diff options
| author | Antonin Descampe <antonin@gmail.com> | 2009-09-10 13:34:19 +0000 |
|---|---|---|
| committer | Antonin Descampe <antonin@gmail.com> | 2009-09-10 13:34:19 +0000 |
| commit | ec400c4fa5ed89b85b3694f6424dda2541d25c0b (patch) | |
| tree | 870eabad965d3d3d17b4c9ff239edf8bca590e51 /codec | |
| parent | b1d8788a464e0de986eabab0fb22c8d857b89c78 (diff) | |
V2 branch :
- found a bug in tcd.c that was preventing to find the correct threshold in tcd_rateallocate.c for high-precision images. Applied a temporary patch but a better solution should be found.
- Modified the way raw images with more that 8bpp are read and written
Diffstat (limited to 'codec')
| -rw-r--r-- | codec/convert.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/codec/convert.c b/codec/convert.c index ada2af08..cd5c1c5f 100644 --- a/codec/convert.c +++ b/codec/convert.c @@ -2012,19 +2012,30 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw } } } - else + else if(raw_cp->rawBitDepth <= 16) { - unsigned short value = 0; + unsigned short value; for(compno = 0; compno < numcomps; compno++) { for (i = 0; i < w * h; i++) { - if (!fread(&value, 2, 1, f)) { + unsigned char temp; + if (!fread(&temp, 1, 1, f)) { fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); return NULL; } + value = temp << 8; + if (!fread(&temp, 1, 1, f)) { + fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); + return NULL; + } + value += temp; image->comps[compno].data[i] = raw_cp->rawSigned?(short)value:value; } } } + else { + fprintf(stderr,"OpenJPEG cannot encode raw components with bit depth higher than 16 bits.\n"); + return NULL; + } if (fread(&ch, 1, 1, f)) { fprintf(stderr,"Warning. End of raw file not reached... processing anyway\n"); @@ -2102,8 +2113,12 @@ int imagetoraw(opj_image_t * image, const char *outfile) ptr = image->comps[compno].data; for (line = 0; line < h; line++) { for(row = 0; row < w; row++) { + unsigned char temp; curr = (signed short int) (*ptr & mask); - fwrite(&curr, sizeof(signed short int), 1, rawFile); + temp = curr >> 8; + fwrite(&temp, 1, 1, rawFile); + temp = curr; + fwrite(&temp, 1, 1, rawFile); ptr++; } } @@ -2115,8 +2130,12 @@ int imagetoraw(opj_image_t * image, const char *outfile) ptr = image->comps[compno].data; for (line = 0; line < h; line++) { for(row = 0; row < w; row++) { + unsigned char temp; curr = (unsigned short int) (*ptr & mask); - fwrite(&curr, sizeof(unsigned short int), 1, rawFile); + temp = curr >> 8; + fwrite(&temp, 1, 1, rawFile); + temp = curr; + fwrite(&temp, 1, 1, rawFile); ptr++; } } |
