This commit is contained in:
mpetavy 2022-02-27 02:58:25 +09:00 committed by GitHub
commit 6357f52feb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -37,3 +37,4 @@ it complete and exempt of errors.
* Vincent Torri
* Yannick Verschueren
* Peter Wimmer
* Marcel Petavy

View File

@ -41,6 +41,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#include "openjpeg.h"
#include "convert.h"
@ -701,7 +702,8 @@ static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData,
opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
{
opj_image_cmptparm_t cmptparm[4]; /* maximum of 4 components */
opj_image_cmptparm_t cmptparm[4]; /*
imum of 4 components */
OPJ_UINT8 lut_R[256], lut_G[256], lut_B[256];
OPJ_UINT8 const* pLUT[3];
opj_image_t * image = NULL;
@ -908,6 +910,8 @@ int imagetobmp(opj_image_t * image, const char *outfile)
int i, pad;
FILE *fdest = NULL;
int adjustR, adjustG, adjustB;
OPJ_UINT8 *pBuffer = (OPJ_UINT8 *) calloc(1, 1024*1024);
OPJ_SIZE_T c = 0;
if (image->comps[0].prec < 8) {
fprintf(stderr, "imagetobmp: Unsupported precision: %d\n",
@ -1041,15 +1045,35 @@ int imagetobmp(opj_image_t * image, const char *outfile)
}
bc = (OPJ_UINT8)b;
fprintf(fdest, "%c%c%c", bc, gc, rc);
if(c >= (malloc_usable_size(pBuffer) - 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 >= (malloc_usable_size(pBuffer) - 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 */
/* -->> -->> -->> -->>