diff --git a/THANKS.md b/THANKS.md index 460eab10..3334e6ad 100644 --- a/THANKS.md +++ b/THANKS.md @@ -37,3 +37,4 @@ it complete and exempt of errors. * Vincent Torri * Yannick Verschueren * Peter Wimmer +* Marcel Petavy diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c index 084f70bb..ee2a8d7d 100644 --- a/src/bin/jp2/convertbmp.c +++ b/src/bin/jp2/convertbmp.c @@ -955,6 +955,10 @@ int imagetobmp(opj_image_t * image, const char *outfile) adjustB = 0; } + int max = 1024*1024; + OPJ_UINT8 *pBuffer = (OPJ_UINT8 *) calloc(1, max); + int c = 0; + for (i = 0; i < w * h; i++) { OPJ_UINT8 rc, gc, bc; int r, g, b; @@ -995,15 +999,35 @@ int imagetobmp(opj_image_t * image, const char *outfile) } bc = (OPJ_UINT8)b; - fprintf(fdest, "%c%c%c", bc, gc, rc); + if(c >= (max - 3)) { + fwrite(pBuffer,1,c,fdest); + c = 0; + } + + *(pBuffer + c++) = bc; + *(pBuffer + c++) = gc; + *(pBuffer + c++) = rc; if ((i + 1) % w == 0) { for (pad = ((3 * w) % 4) ? (4 - (3 * w) % 4) : 0; pad > 0; pad--) { /* ADD */ - fprintf(fdest, "%c", 0); + + if(c >= (max - 1)) { + fwrite(pBuffer,1,c,fdest); + c = 0; + } + + *(pBuffer + c++) = 0; } } } + + if(c > 0) { + fwrite(pBuffer,1,c,fdest); + } + fclose(fdest); + + free(pBuffer); } else { /* Gray-scale */ /* -->> -->> -->> -->>