From 64429225702c1ca65ea3b6882be0e19c94509843 Mon Sep 17 00:00:00 2001 From: frog Date: Fri, 2 Jul 2004 09:19:00 +0000 Subject: [PATCH] * src/jpeg/libijg12/jdhuff12.c: - printf polluting ctest removed. - TAB removal for comminting * Test: - TestAllReadCompareDicom.cxx: added a test that compares all the images in gdcmDataImages.h with corresponding images in gdcmData/BaselineDicom/. When baseline images are not present this test creates them. Note: we need to validate each reference image, but before that I'd like to rename them with a more explicit name... - CMakeLists.txt: changed accordingly. * Example/*.cxx: examples now only include gdcm.h (as opposed to including each header needed). --- ChangeLog | 15 ++ Example/FindTags.cxx | 1 - Example/PrintDocument.cxx | 18 +-- Example/PrintFile.cxx | 18 +-- Example/TestWrite.cxx | 5 +- Example/Write.cxx | 5 +- Example/WriteDicom.cxx | 3 +- Example/WriteRead.cxx | 5 +- Testing/CMakeLists.txt | 1 + Testing/TestAllReadCompareDicom.cxx | 167 ++++++++++++++++++++ src/jpeg/libijg12/jdhuff12.c | 229 ++++++++++++++-------------- 11 files changed, 303 insertions(+), 164 deletions(-) create mode 100644 Testing/TestAllReadCompareDicom.cxx diff --git a/ChangeLog b/ChangeLog index b22b77c6..680d67ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-07-02 Eric Boix + * src/jpeg/libijg12/jdhuff12.c: + - printf polluting ctest removed. + - TAB removal for comminting + * Test: + - TestAllReadCompareDicom.cxx: added a test that compares all the + images in gdcmDataImages.h with corresponding images in + gdcmData/BaselineDicom/. When baseline images are not present + this test creates them. + Note: we need to validate each reference image, but before that + I'd like to rename them with a more explicit name... + - CMakeLists.txt: changed accordingly. + * Example/*.cxx: examples now only include gdcm.h (as opposed to + including each header needed). + 2004-07-01 Eric Boix * Test/*.cxx and Example/*.cxx: moved some examples away from the test suite to the Example directory. Are concerned: diff --git a/Example/FindTags.cxx b/Example/FindTags.cxx index 46aea14b..8439e9f9 100644 --- a/Example/FindTags.cxx +++ b/Example/FindTags.cxx @@ -1,5 +1,4 @@ #include -//#include #include "gdcm.h" #include "math.h" diff --git a/Example/PrintDocument.cxx b/Example/PrintDocument.cxx index 940b8166..d3ceeb25 100644 --- a/Example/PrintDocument.cxx +++ b/Example/PrintDocument.cxx @@ -1,21 +1,5 @@ #include - -#include "gdcmException.h" -#include "gdcmCommon.h" - -#include "gdcmDictEntry.h" -#include "gdcmDict.h" -#include "gdcmDictSet.h" -#include "gdcmHeader.h" -#include "gdcmUtil.h" -#include "gdcmBinEntry.h" -#include "gdcmDocEntry.h" -#include "gdcmDocEntrySet.h" -#include "gdcmDocument.h" -#include "gdcmElementSet.h" -#include "gdcmSeqEntry.h" -#include "gdcmSQItem.h" -#include "gdcmValEntry.h" +#include "gdcm.h" int main(int argc, char* argv[]) { diff --git a/Example/PrintFile.cxx b/Example/PrintFile.cxx index 810712a4..c2b98006 100644 --- a/Example/PrintFile.cxx +++ b/Example/PrintFile.cxx @@ -1,22 +1,6 @@ #include +#include "gdcm.h" -#include "gdcmException.h" -#include "gdcmCommon.h" - -#include "gdcmDictEntry.h" -#include "gdcmDict.h" -#include "gdcmDictSet.h" -#include "gdcmHeader.h" -#include "gdcmUtil.h" -#include "gdcmBinEntry.h" -#include "gdcmDocEntry.h" -#include "gdcmDocEntrySet.h" -#include "gdcmDocument.h" -#include "gdcmElementSet.h" -#include "gdcmSeqEntry.h" -#include "gdcmSQItem.h" -#include "gdcmValEntry.h" -#include "gdcmFile.h" int main(int argc, char* argv[]) { diff --git a/Example/TestWrite.cxx b/Example/TestWrite.cxx index 9673abf0..cb9b9e69 100644 --- a/Example/TestWrite.cxx +++ b/Example/TestWrite.cxx @@ -1,9 +1,6 @@ #include -#include "gdcm.h" -#include "gdcmHeader.h" -#include "gdcmDocument.h" - #include +#include "gdcm.h" int main(int argc, char* argv[]) { diff --git a/Example/Write.cxx b/Example/Write.cxx index 120f73cb..dbc53038 100644 --- a/Example/Write.cxx +++ b/Example/Write.cxx @@ -1,9 +1,6 @@ #include -#include "gdcm.h" -#include "gdcmHeader.h" -#include "gdcmDocument.h" - #include +#include "gdcm.h" int main(int argc, char* argv[]) { diff --git a/Example/WriteDicom.cxx b/Example/WriteDicom.cxx index a10d1f78..10554b39 100644 --- a/Example/WriteDicom.cxx +++ b/Example/WriteDicom.cxx @@ -1,5 +1,4 @@ -#include "gdcmDocument.h" -#include "gdcmFile.h" +#include "gdcm.h" // Writting of a DICOM file based on a correct dicom header // and data pixel of another image diff --git a/Example/WriteRead.cxx b/Example/WriteRead.cxx index b45de305..d4d2c4f1 100644 --- a/Example/WriteRead.cxx +++ b/Example/WriteRead.cxx @@ -1,9 +1,6 @@ #include -#include "gdcm.h" -#include "gdcmHeader.h" -#include "gdcmDocument.h" - #include +#include "gdcm.h" int main(int argc, char* argv[]) { diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 2ba2bca1..43b987ad 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -17,6 +17,7 @@ IF (GDCM_DATA_ROOT) SET(TEST_SOURCES ${TEST_SOURCES} TestReadWriteReadCompare.cxx # includes generated gdcmDataImages.h PrintAllDocument.cxx # includes generated gdcmDataImages.h + TestAllReadCompareDicom.cxx # includes generated gdcmDataImages.h PrintDicomDir.cxx TestChangeHeader.cxx TestDicomDir.cxx #require DICOMDIR diff --git a/Testing/TestAllReadCompareDicom.cxx b/Testing/TestAllReadCompareDicom.cxx new file mode 100644 index 00000000..46d51a6c --- /dev/null +++ b/Testing/TestAllReadCompareDicom.cxx @@ -0,0 +1,167 @@ +#include "gdcmHeader.h" +#include "gdcmFile.h" + +//Generated file: +#include "gdcmDataImages.h" + +int TestAllReadCompareDicom(int argc, char* argv[]) +{ + if ( argc > 1 ) + { + std::cerr << " Usage: " << argv[0] + << " (no arguments needed)." << std::endl; + return 1; + } + + std::cout << " Description (Test::TestAllReadCompareDicom): " + << std::endl; + std::cout << " For all images in gdcmData (and not blacklisted in " + "Test/CMakeLists.txt)" + << std::endl; + std::cout << " apply the following to each filename.xxx: " + << std::endl; + std::cout << " step 1: parse the image (as gdcmHeader) and call" + << " IsReadable(). " + << std::endl; + std::cout << " step 2: find in GDCM_DATA_ROOT/BaselineDicom/filename.dcm" + << std::endl + << " (with format DICOM V3, explicit Value" + << "Representation)" + << std::endl; + std::cout << " step 3a: when image NOT found on step 2, write " + << std::endl + << " GDCM_DATA_ROOT/BaselineDicom/filename.dcm" + << std::endl + << " (with format DICOM V3, explicit Value" + << "Representation)" + << std::endl; + std::cout << " step 3b: when image found on step 2, and when IsReadable()" + << std::endl + << " compare it (in memory with memcmp) with the" + << std::endl + << " image we are testing (the one of step 1). " + << std::endl << std::endl; + + int i = 0; + while( gdcmDataImages[i] != 0 ) + { + ////// Check for existence of reference baseline directory + + std::string baseLineDir = GDCM_DATA_ROOT; + baseLineDir += "/BaselineDicom/"; + + FILE* testFILE = fopen( baseLineDir.c_str(), "r" ); + if (! testFILE ) + { + std::cerr << " The reference baseline directory " << std::endl + << " " + << baseLineDir << std::endl + << " couldn't be opened." + << std::endl; + return 1; + } + else + fclose( testFILE ); + + ////// Step 1 (see above description): + + std::string filename = GDCM_DATA_ROOT; + filename += "/"; //doh! + filename += gdcmDataImages[i]; + + std::cout << " Testing: " << filename << std::endl; + + gdcmFile* tested = new gdcmFile( filename.c_str(), false, true ); + if( !tested->GetHeader()->IsReadable() ) + { + std::cout << " Image not gdcm compatible:" + << filename << std::endl; + delete tested; + return 1; + } + + ////// Step 2: + + ////// Check for existence of reference baseline dicom file: + + std::string referenceFileName = baseLineDir + gdcmDataImages[i++]; + std::string::size_type slash_pos = referenceFileName.rfind( "." ); + if ( slash_pos != std::string::npos ) + { + referenceFileName.replace( slash_pos + 1, 3, "dcm" ); + } + + testFILE = fopen( referenceFileName.c_str(), "r" ); + if (! testFILE ) + { + ////// Step 3a: + + int testedDataSize = tested->GetImageDataSize(); + void* testedImageData = tested->GetImageData(); // Kludge + tested->WriteDcmExplVR( referenceFileName ); + std::cerr << " Creating reference baseline file :" << std::endl + << " " << referenceFileName + << std::endl; + delete tested; + delete (char*)testedImageData; + continue; + } + else + fclose( testFILE ); + + ////// When reference file is not gdcm readable test is failed: + + gdcmFile* reference = new gdcmFile( referenceFileName.c_str(), + false, true ); + if( !reference->GetHeader()->IsReadable() ) + { + std::cout << " Reference image " << std::endl + << " " << referenceFileName <GetImageDataSize(); + void* testedImageData = tested->GetImageData(); + + int referenceDataSize = reference->GetImageDataSize(); + void* referenceImageData = reference->GetImageData(); + + if (testedDataSize != referenceDataSize) + { + std::cout << " Pixel areas lengths differ: " + << testedDataSize << " # " << referenceDataSize + << std::endl; + delete tested; + delete reference; + delete (char*)testedImageData; + delete (char*)referenceImageData; + return 1; + } + + if (int res = memcmp(testedImageData, referenceImageData, + testedDataSize) != 0 ) + { + std::cout << " Pixel differ (as expanded in memory)." + << std::endl; + delete tested; + delete reference; + delete (char*)testedImageData; + delete (char*)referenceImageData; + return 1; + } + std::cout << " Passed." << std::endl ; + + //////////////// Clean up: + delete tested; + delete reference; + delete (char*)testedImageData; + delete (char*)referenceImageData; + } + + return 0; +} diff --git a/src/jpeg/libijg12/jdhuff12.c b/src/jpeg/libijg12/jdhuff12.c index b3734b89..c01a7165 100644 --- a/src/jpeg/libijg12/jdhuff12.c +++ b/src/jpeg/libijg12/jdhuff12.c @@ -17,7 +17,7 @@ #define JPEG_INTERNALS #include "jinclude12.h" #include "jpeglib12.h" -#include "jdhuff12.h" /* Declarations shared with jdphuff.c */ +#include "jdhuff12.h" /* Declarations shared with jdphuff.c */ /* @@ -41,10 +41,10 @@ typedef struct { #else #if MAX_COMPS_IN_SCAN == 4 #define ASSIGN_STATE(dest,src) \ - ((dest).last_dc_val[0] = (src).last_dc_val[0], \ - (dest).last_dc_val[1] = (src).last_dc_val[1], \ - (dest).last_dc_val[2] = (src).last_dc_val[2], \ - (dest).last_dc_val[3] = (src).last_dc_val[3]) + ((dest).last_dc_val[0] = (src).last_dc_val[0], \ + (dest).last_dc_val[1] = (src).last_dc_val[1], \ + (dest).last_dc_val[2] = (src).last_dc_val[2], \ + (dest).last_dc_val[3] = (src).last_dc_val[3]) #endif #endif @@ -55,11 +55,11 @@ typedef struct { /* These fields are loaded into local variables at start of each MCU. * In case of suspension, we exit WITHOUT updating them. */ - bitread_perm_state bitstate; /* Bit buffer at start of MCU */ - savable_state saved; /* Other state at start of MCU */ + bitread_perm_state bitstate; /* Bit buffer at start of MCU */ + savable_state saved; /* Other state at start of MCU */ /* These fields are NOT loaded into local working state. */ - unsigned int restarts_to_go; /* MCUs left in this restart interval */ + unsigned int restarts_to_go; /* MCUs left in this restart interval */ /* Pointers to derived tables (these workspaces have image lifespan) */ d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS]; @@ -104,9 +104,9 @@ start_pass_huff_decoder (j_decompress_ptr cinfo) /* Compute derived values for Huffman tables */ /* We may do this more than once for a table, but it's not expensive */ jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl, - & entropy->dc_derived_tbls[dctbl]); + & entropy->dc_derived_tbls[dctbl]); jpeg_make_d_derived_tbl(cinfo, FALSE, actbl, - & entropy->ac_derived_tbls[actbl]); + & entropy->ac_derived_tbls[actbl]); /* Initialize DC predictions to 0 */ entropy->saved.last_dc_val[ci] = 0; } @@ -147,7 +147,7 @@ start_pass_huff_decoder (j_decompress_ptr cinfo) GLOBAL(void) jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, - d_derived_tbl ** pdtbl) + d_derived_tbl ** pdtbl) { JHUFF_TBL *htbl; d_derived_tbl *dtbl; @@ -173,9 +173,9 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, if (*pdtbl == NULL) *pdtbl = (d_derived_tbl *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(d_derived_tbl)); + SIZEOF(d_derived_tbl)); dtbl = *pdtbl; - dtbl->pub = htbl; /* fill in back link */ + dtbl->pub = htbl; /* fill in back link */ /* Figure C.1: make table of Huffman code length for each symbol */ @@ -226,7 +226,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, p += htbl->bits[l]; dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */ } else { - dtbl->maxcode[l] = -1; /* -1 if no codes of this length */ + dtbl->maxcode[l] = -1; /* -1 if no codes of this length */ } } dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */ @@ -247,9 +247,9 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, /* Generate left-justified code followed by all possible bit sequences */ lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l); for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) { - dtbl->look_nbits[lookbits] = l; - dtbl->look_sym[lookbits] = htbl->huffval[p]; - lookbits++; + dtbl->look_nbits[lookbits] = l; + dtbl->look_sym[lookbits] = htbl->huffval[p]; + lookbits++; } } } @@ -265,8 +265,8 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, int sym = htbl->huffval[i]; //printf ("htbl->huffval[%d]=%d\n",i,htbl->huffval[i]); if (sym < 0 || sym > 15) { - printf("JERR_BAD_HUFF_TABLE sym %d (>15)\n",sym); - //ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); + //printf("JERR_BAD_HUFF_TABLE sym %d (>15)\n",sym); + //ERREXIT(cinfo, JERR_BAD_HUFF_TABLE); // Sorry for the patch : // Now, we can read Philips MRI Images htbl->huffval[i]=15; @@ -292,7 +292,7 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, */ #ifdef SLOW_SHIFT_32 -#define MIN_GET_BITS 15 /* minimum allowable value */ +#define MIN_GET_BITS 15 /* minimum allowable value */ #else #define MIN_GET_BITS (BIT_BUF_SIZE-7) #endif @@ -300,8 +300,9 @@ jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, GLOBAL(boolean) jpeg_fill_bit_buffer (bitread_working_state * state, - register bit_buf_type get_buffer, register int bits_left, - int nbits) + register bit_buf_type get_buffer, + register int bits_left, + int nbits) /* Load up the bit buffer to a depth of at least nbits */ { /* Copy heavily used state fields into locals (hopefully registers) */ @@ -313,54 +314,54 @@ jpeg_fill_bit_buffer (bitread_working_state * state, /* (It is assumed that no request will be for more than that many bits.) */ /* We fail to do so only if we hit a marker or are forced to suspend. */ - if (cinfo->unread_marker == 0) { /* cannot advance past a marker */ + if (cinfo->unread_marker == 0) { /* cannot advance past a marker */ while (bits_left < MIN_GET_BITS) { register int c; /* Attempt to read a byte */ if (bytes_in_buffer == 0) { - if (! (*cinfo->src->fill_input_buffer) (cinfo)) - return FALSE; - next_input_byte = cinfo->src->next_input_byte; - bytes_in_buffer = cinfo->src->bytes_in_buffer; + if (! (*cinfo->src->fill_input_buffer) (cinfo)) + return FALSE; + next_input_byte = cinfo->src->next_input_byte; + bytes_in_buffer = cinfo->src->bytes_in_buffer; } bytes_in_buffer--; c = GETJOCTET(*next_input_byte++); /* If it's 0xFF, check and discard stuffed zero byte */ if (c == 0xFF) { - /* Loop here to discard any padding FF's on terminating marker, - * so that we can save a valid unread_marker value. NOTE: we will - * accept multiple FF's followed by a 0 as meaning a single FF data - * byte. This data pattern is not valid according to the standard. - */ - do { - if (bytes_in_buffer == 0) { - if (! (*cinfo->src->fill_input_buffer) (cinfo)) - return FALSE; - next_input_byte = cinfo->src->next_input_byte; - bytes_in_buffer = cinfo->src->bytes_in_buffer; - } - bytes_in_buffer--; - c = GETJOCTET(*next_input_byte++); - } while (c == 0xFF); - - if (c == 0) { - /* Found FF/00, which represents an FF data byte */ - c = 0xFF; - } else { - /* Oops, it's actually a marker indicating end of compressed data. - * Save the marker code for later use. - * Fine point: it might appear that we should save the marker into - * bitread working state, not straight into permanent state. But - * once we have hit a marker, we cannot need to suspend within the - * current MCU, because we will read no more bytes from the data - * source. So it is OK to update permanent state right away. - */ - cinfo->unread_marker = c; - /* See if we need to insert some fake zero bits. */ - goto no_more_bytes; - } + /* Loop here to discard any padding FF's on terminating marker, + * so that we can save a valid unread_marker value. NOTE: we will + * accept multiple FF's followed by a 0 as meaning a single FF data + * byte. This data pattern is not valid according to the standard. + */ + do { + if (bytes_in_buffer == 0) { + if (! (*cinfo->src->fill_input_buffer) (cinfo)) + return FALSE; + next_input_byte = cinfo->src->next_input_byte; + bytes_in_buffer = cinfo->src->bytes_in_buffer; + } + bytes_in_buffer--; + c = GETJOCTET(*next_input_byte++); + } while (c == 0xFF); + + if (c == 0) { + /* Found FF/00, which represents an FF data byte */ + c = 0xFF; + } else { + /* Oops, it's actually a marker indicating end of compressed data. + * Save the marker code for later use. + * Fine point: it might appear that we should save the marker into + * bitread working state, not straight into permanent state. But + * once we have hit a marker, we cannot need to suspend within the + * current MCU, because we will read no more bytes from the data + * source. So it is OK to update permanent state right away. + */ + cinfo->unread_marker = c; + /* See if we need to insert some fake zero bits. */ + goto no_more_bytes; + } } /* OK, load c into get_buffer */ @@ -380,8 +381,8 @@ jpeg_fill_bit_buffer (bitread_working_state * state, * appears per data segment. */ if (! cinfo->entropy->insufficient_data) { - WARNMS(cinfo, JWRN_HIT_MARKER); - cinfo->entropy->insufficient_data = TRUE; + WARNMS(cinfo, JWRN_HIT_MARKER); + cinfo->entropy->insufficient_data = TRUE; } /* Fill the buffer with zero bits */ get_buffer <<= MIN_GET_BITS - bits_left; @@ -406,8 +407,8 @@ jpeg_fill_bit_buffer (bitread_working_state * state, GLOBAL(int) jpeg_huff_decode (bitread_working_state * state, - register bit_buf_type get_buffer, register int bits_left, - d_derived_tbl * htbl, int min_bits) + register bit_buf_type get_buffer, register int bits_left, + d_derived_tbl * htbl, int min_bits) { register int l = min_bits; register INT32 code; @@ -436,7 +437,7 @@ jpeg_huff_decode (bitread_working_state * state, if (l > 16) { WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE); - return 0; /* fake a zero as the safest result */ + return 0; /* fake a zero as the safest result */ } return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ]; @@ -535,7 +536,7 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) - return FALSE; + return FALSE; } /* If we've run out of data, just leave the MCU set to zeroes. @@ -560,68 +561,66 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) /* Section F.2.2.1: decode the DC coefficient difference */ HUFF_DECODE(s, br_state, dctbl, return FALSE, label1); if (s) { - CHECK_BIT_BUFFER(br_state, s, return FALSE); - r = GET_BITS(s); - s = HUFF_EXTEND(r, s); + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); } if (entropy->dc_needed[blkn]) { - /* Convert DC difference to actual value, update last_dc_val */ - int ci = cinfo->MCU_membership[blkn]; - s += state.last_dc_val[ci]; - state.last_dc_val[ci] = s; - /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ - (*block)[0] = (JCOEF) s; + /* Convert DC difference to actual value, update last_dc_val */ + int ci = cinfo->MCU_membership[blkn]; + s += state.last_dc_val[ci]; + state.last_dc_val[ci] = s; + /* Output the DC coefficient (assumes jpeg_natural_order[0] = 0) */ + (*block)[0] = (JCOEF) s; } if (entropy->ac_needed[blkn]) { - /* Section F.2.2.2: decode the AC coefficients */ - /* Since zeroes are skipped, output area must be cleared beforehand */ - for (k = 1; k < DCTSIZE2; k++) { - HUFF_DECODE(s, br_state, actbl, return FALSE, label2); + /* Section F.2.2.2: decode the AC coefficients */ + /* Since zeroes are skipped, output area must be cleared beforehand */ + for (k = 1; k < DCTSIZE2; k++) { + HUFF_DECODE(s, br_state, actbl, return FALSE, label2); - r = s >> 4; - s &= 15; + r = s >> 4; + s &= 15; - if (s) { - k += r; - CHECK_BIT_BUFFER(br_state, s, return FALSE); - r = GET_BITS(s); - s = HUFF_EXTEND(r, s); - /* Output coefficient in natural (dezigzagged) order. - * Note: the extra entries in jpeg_natural_order[] will save us - * if k >= DCTSIZE2, which could happen if the data is corrupted. - */ - (*block)[jpeg_natural_order[k]] = (JCOEF) s; - } else { - if (r != 15) - break; - k += 15; - } - } - + if (s) { + k += r; + CHECK_BIT_BUFFER(br_state, s, return FALSE); + r = GET_BITS(s); + s = HUFF_EXTEND(r, s); + /* Output coefficient in natural (dezigzagged) order. + * Note: the extra entries in jpeg_natural_order[] will save us + * if k >= DCTSIZE2, which could happen if the data is corrupted. + */ + (*block)[jpeg_natural_order[k]] = (JCOEF) s; + } else { + if (r != 15) + break; + k += 15; + } + } } else { - /* Section F.2.2.2: decode the AC coefficients */ - /* In this path we just discard the values */ - for (k = 1; k < DCTSIZE2; k++) { - HUFF_DECODE(s, br_state, actbl, return FALSE, label3); + /* Section F.2.2.2: decode the AC coefficients */ + /* In this path we just discard the values */ + for (k = 1; k < DCTSIZE2; k++) { + HUFF_DECODE(s, br_state, actbl, return FALSE, label3); - r = s >> 4; - s &= 15; + r = s >> 4; + s &= 15; - if (s) { - k += r; - CHECK_BIT_BUFFER(br_state, s, return FALSE); - DROP_BITS(s); - } else { - if (r != 15) - break; - k += 15; - } - } - + if (s) { + k += r; + CHECK_BIT_BUFFER(br_state, s, return FALSE); + DROP_BITS(s); + } else { + if (r != 15) + break; + k += 15; + } + } } } @@ -649,7 +648,7 @@ jinit_huff_decoder (j_decompress_ptr cinfo) entropy = (huff_entropy_ptr) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(huff_entropy_decoder)); + SIZEOF(huff_entropy_decoder)); cinfo->entropy = (struct jpeg_entropy_decoder *) entropy; entropy->pub.start_pass = start_pass_huff_decoder; entropy->pub.decode_mcu = decode_mcu; -- 2.45.1