Merge pull request #1383 from rouault/deprecate_bpp

API: deprecate 'bpp' member in favor of 'prec'
This commit is contained in:
Even Rouault 2021-10-21 17:21:36 +02:00 committed by GitHub
commit 9f70bf0ad1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 216 additions and 246 deletions

View File

@ -117,7 +117,6 @@ static void scale_component_up(opj_image_comp_t* component,
} }
} }
component->prec = precision; component->prec = precision;
component->bpp = precision;
} }
void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision) void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision)
{ {
@ -144,7 +143,6 @@ void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision)
l_data[i] >>= shift; l_data[i] >>= shift;
} }
} }
component->bpp = precision;
component->prec = precision; component->prec = precision;
} }
@ -838,7 +836,6 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters)
for (i = 0; i < numcomps; i++) { for (i = 0; i < numcomps; i++) {
cmptparm[i].prec = 8; cmptparm[i].prec = 8;
cmptparm[i].bpp = 8;
cmptparm[i].sgnd = 0; cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; cmptparm[i].dx = (OPJ_UINT32)subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; cmptparm[i].dy = (OPJ_UINT32)subsampling_dy;
@ -1269,7 +1266,6 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters)
} }
cmptparm.prec = (OPJ_UINT32)prec; cmptparm.prec = (OPJ_UINT32)prec;
cmptparm.bpp = (OPJ_UINT32)prec;
cmptparm.dx = (OPJ_UINT32)parameters->subsampling_dx; cmptparm.dx = (OPJ_UINT32)parameters->subsampling_dx;
cmptparm.dy = (OPJ_UINT32)parameters->subsampling_dy; cmptparm.dy = (OPJ_UINT32)parameters->subsampling_dy;
@ -1327,7 +1323,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters)
comp->data[i] = v; comp->data[i] = v;
} }
fclose(f); fclose(f);
comp->bpp = (OPJ_UINT32)int_floorlog2(max) + 1; comp->prec = (OPJ_UINT32)int_floorlog2(max) + 1;
return image; return image;
} }
@ -1875,7 +1871,6 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters)
for (i = 0; i < numcomps; i++) { for (i = 0; i < numcomps; i++) {
cmptparm[i].prec = (OPJ_UINT32)prec; cmptparm[i].prec = (OPJ_UINT32)prec;
cmptparm[i].bpp = (OPJ_UINT32)prec;
cmptparm[i].sgnd = 0; cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; cmptparm[i].dx = (OPJ_UINT32)subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; cmptparm[i].dy = (OPJ_UINT32)subsampling_dy;
@ -2366,7 +2361,6 @@ static opj_image_t* rawtoimage_common(const char *filename,
/* initialize image components */ /* initialize image components */
for (i = 0; i < numcomps; i++) { for (i = 0; i < numcomps; i++) {
cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth; cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth;
cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth;
cmptparm[i].sgnd = (OPJ_UINT32)raw_cp->rawSigned; cmptparm[i].sgnd = (OPJ_UINT32)raw_cp->rawSigned;
cmptparm[i].dx = (OPJ_UINT32)(subsampling_dx * raw_cp->rawComps[i].dx); cmptparm[i].dx = (OPJ_UINT32)(subsampling_dx * raw_cp->rawComps[i].dx);
cmptparm[i].dy = (OPJ_UINT32)(subsampling_dy * raw_cp->rawComps[i].dy); cmptparm[i].dy = (OPJ_UINT32)(subsampling_dy * raw_cp->rawComps[i].dy);

View File

@ -198,14 +198,10 @@ static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride,
bmp_mask_get_shift_and_prec(blueMask, &blueShift, &bluePrec); bmp_mask_get_shift_and_prec(blueMask, &blueShift, &bluePrec);
bmp_mask_get_shift_and_prec(alphaMask, &alphaShift, &alphaPrec); bmp_mask_get_shift_and_prec(alphaMask, &alphaShift, &alphaPrec);
image->comps[0].bpp = redPrec;
image->comps[0].prec = redPrec; image->comps[0].prec = redPrec;
image->comps[1].bpp = greenPrec;
image->comps[1].prec = greenPrec; image->comps[1].prec = greenPrec;
image->comps[2].bpp = bluePrec;
image->comps[2].prec = bluePrec; image->comps[2].prec = bluePrec;
if (hasAlpha) { if (hasAlpha) {
image->comps[3].bpp = alphaPrec;
image->comps[3].prec = alphaPrec; image->comps[3].prec = alphaPrec;
} }
@ -260,14 +256,10 @@ static void bmpmask16toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride,
bmp_mask_get_shift_and_prec(blueMask, &blueShift, &bluePrec); bmp_mask_get_shift_and_prec(blueMask, &blueShift, &bluePrec);
bmp_mask_get_shift_and_prec(alphaMask, &alphaShift, &alphaPrec); bmp_mask_get_shift_and_prec(alphaMask, &alphaShift, &alphaPrec);
image->comps[0].bpp = redPrec;
image->comps[0].prec = redPrec; image->comps[0].prec = redPrec;
image->comps[1].bpp = greenPrec;
image->comps[1].prec = greenPrec; image->comps[1].prec = greenPrec;
image->comps[2].bpp = bluePrec;
image->comps[2].prec = bluePrec; image->comps[2].prec = bluePrec;
if (hasAlpha) { if (hasAlpha) {
image->comps[3].bpp = alphaPrec;
image->comps[3].prec = alphaPrec; image->comps[3].prec = alphaPrec;
} }
@ -838,7 +830,6 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
memset(&cmptparm[0], 0, sizeof(cmptparm)); memset(&cmptparm[0], 0, sizeof(cmptparm));
for (i = 0; i < 4U; i++) { for (i = 0; i < 4U; i++) {
cmptparm[i].prec = 8; cmptparm[i].prec = 8;
cmptparm[i].bpp = 8;
cmptparm[i].sgnd = 0; cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)parameters->subsampling_dx; cmptparm[i].dx = (OPJ_UINT32)parameters->subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)parameters->subsampling_dy; cmptparm[i].dy = (OPJ_UINT32)parameters->subsampling_dy;

View File

@ -193,9 +193,8 @@ static opj_image_t * pngtoimage_internal(opj_cparameters_t * params,
/* Create image */ /* Create image */
memset(cmptparm, 0, sizeof(cmptparm)); memset(cmptparm, 0, sizeof(cmptparm));
for (i = 0; i < nr_comp; ++i) { for (i = 0; i < nr_comp; ++i) {
cmptparm[i].prec = (OPJ_UINT32)bit_depth;
/* bits_per_pixel: 8 or 16 */ /* bits_per_pixel: 8 or 16 */
cmptparm[i].bpp = (OPJ_UINT32)bit_depth; cmptparm[i].prec = (OPJ_UINT32)bit_depth;
cmptparm[i].sgnd = 0; cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx; cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy; cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy;

View File

@ -1389,7 +1389,6 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
for (j = 0; j < numcomps; j++) { for (j = 0; j < numcomps; j++) {
cmptparm[j].prec = tiBps; cmptparm[j].prec = tiBps;
cmptparm[j].bpp = tiBps;
cmptparm[j].dx = (OPJ_UINT32)subsampling_dx; cmptparm[j].dx = (OPJ_UINT32)subsampling_dx;
cmptparm[j].dy = (OPJ_UINT32)subsampling_dy; cmptparm[j].dy = (OPJ_UINT32)subsampling_dy;
cmptparm[j].w = (OPJ_UINT32)w; cmptparm[j].w = (OPJ_UINT32)w;

View File

@ -1086,8 +1086,6 @@ static opj_image_t* convert_gray_to_rgb(opj_image_t* original)
return NULL; return NULL;
} }
l_new_components[0].bpp = l_new_components[1].bpp = l_new_components[2].bpp =
original->comps[0].bpp;
l_new_components[0].dx = l_new_components[1].dx = l_new_components[2].dx = l_new_components[0].dx = l_new_components[1].dx = l_new_components[2].dx =
original->comps[0].dx; original->comps[0].dx;
l_new_components[0].dy = l_new_components[1].dy = l_new_components[2].dy = l_new_components[0].dy = l_new_components[1].dy = l_new_components[2].dy =
@ -1106,7 +1104,6 @@ static opj_image_t* convert_gray_to_rgb(opj_image_t* original)
original->comps[0].y0; original->comps[0].y0;
for (compno = 1U; compno < original->numcomps; ++compno) { for (compno = 1U; compno < original->numcomps; ++compno) {
l_new_components[compno + 2U].bpp = original->comps[compno].bpp;
l_new_components[compno + 2U].dx = original->comps[compno].dx; l_new_components[compno + 2U].dx = original->comps[compno].dx;
l_new_components[compno + 2U].dy = original->comps[compno].dy; l_new_components[compno + 2U].dy = original->comps[compno].dy;
l_new_components[compno + 2U].h = original->comps[compno].h; l_new_components[compno + 2U].h = original->comps[compno].h;
@ -1196,7 +1193,6 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
opj_image_cmptparm_t* l_new_cmp = &(l_new_components[compno]); opj_image_cmptparm_t* l_new_cmp = &(l_new_components[compno]);
opj_image_comp_t* l_org_cmp = &(original->comps[compno]); opj_image_comp_t* l_org_cmp = &(original->comps[compno]);
l_new_cmp->bpp = l_org_cmp->bpp;
l_new_cmp->prec = l_org_cmp->prec; l_new_cmp->prec = l_org_cmp->prec;
l_new_cmp->sgnd = l_org_cmp->sgnd; l_new_cmp->sgnd = l_org_cmp->sgnd;
l_new_cmp->x0 = original->x0; l_new_cmp->x0 = original->x0;

View File

@ -66,7 +66,6 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts,
comp->x0 = cmptparms[compno].x0; comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0; comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec; comp->prec = cmptparms[compno].prec;
comp->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd; comp->sgnd = cmptparms[compno].sgnd;
if (comp->h != 0 && if (comp->h != 0 &&
(OPJ_SIZE_T)comp->w > SIZE_MAX / comp->h / sizeof(OPJ_INT32)) { (OPJ_SIZE_T)comp->w > SIZE_MAX / comp->h / sizeof(OPJ_INT32)) {

View File

@ -6975,7 +6975,7 @@ static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz,
/* Bitdepth */ /* Bitdepth */
for (i = 0; i < image->numcomps; i++) { for (i = 0; i < image->numcomps; i++) {
if ((image->comps[i].bpp != 12) | (image->comps[i].sgnd)) { if ((image->comps[i].prec != 12) | (image->comps[i].sgnd)) {
char signed_str[] = "signed"; char signed_str[] = "signed";
char unsigned_str[] = "unsigned"; char unsigned_str[] = "unsigned";
char *tmp_str = image->comps[i].sgnd ? signed_str : unsigned_str; char *tmp_str = image->comps[i].sgnd ? signed_str : unsigned_str;
@ -6984,7 +6984,7 @@ static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz,
"Precision of each component shall be 12 bits unsigned" "Precision of each component shall be 12 bits unsigned"
"-> At least component %d of input image (%d bits, %s) is not compliant\n" "-> At least component %d of input image (%d bits, %s) is not compliant\n"
"-> Non-profile-3 codestream will be generated\n", "-> Non-profile-3 codestream will be generated\n",
i, image->comps[i].bpp, tmp_str); i, image->comps[i].prec, tmp_str);
return OPJ_FALSE; return OPJ_FALSE;
} }
} }
@ -7275,7 +7275,7 @@ static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters,
/* Bitdepth */ /* Bitdepth */
for (i = 0; i < image->numcomps; i++) { for (i = 0; i < image->numcomps; i++) {
if (!(image->comps[i].bpp >= 8 && image->comps[i].bpp <= 16) || if (!(image->comps[i].prec >= 8 && image->comps[i].prec <= 16) ||
(image->comps[i].sgnd)) { (image->comps[i].sgnd)) {
char signed_str[] = "signed"; char signed_str[] = "signed";
char unsigned_str[] = "unsigned"; char unsigned_str[] = "unsigned";
@ -7284,7 +7284,7 @@ static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters,
"IMF profiles require precision of each component to b in [8-16] bits unsigned" "IMF profiles require precision of each component to b in [8-16] bits unsigned"
"-> At least component %d of input image (%d bits, %s) is not compliant\n" "-> At least component %d of input image (%d bits, %s) is not compliant\n"
"-> Non-IMF codestream will be generated\n", "-> Non-IMF codestream will be generated\n",
i, image->comps[i].bpp, tmp_str); i, image->comps[i].prec, tmp_str);
ret = OPJ_FALSE; ret = OPJ_FALSE;
} }
} }

View File

@ -76,6 +76,12 @@ Most compilers implement their own version of this keyword ...
#define OPJ_DEPRECATED(func) func #define OPJ_DEPRECATED(func) func
#endif #endif
#if defined(__GNUC__) && __GNUC__ >= 6
#define OPJ_DEPRECATED_STRUCT_MEMBER(memb, msg) __attribute__ ((deprecated(msg))) memb
#else
#define OPJ_DEPRECATED_STRUCT_MEMBER(memb, msg) memb
#endif
#if defined(OPJ_STATIC) || !defined(_WIN32) #if defined(OPJ_STATIC) || !defined(_WIN32)
/* http://gcc.gnu.org/wiki/Visibility */ /* http://gcc.gnu.org/wiki/Visibility */
# if !defined(_WIN32) && __GNUC__ >= 4 # if !defined(_WIN32) && __GNUC__ >= 4
@ -681,10 +687,10 @@ typedef struct opj_image_comp {
OPJ_UINT32 x0; OPJ_UINT32 x0;
/** y component offset compared to the whole image */ /** y component offset compared to the whole image */
OPJ_UINT32 y0; OPJ_UINT32 y0;
/** precision */ /** precision: number of bits per component per pixel */
OPJ_UINT32 prec; OPJ_UINT32 prec;
/** image depth in bits */ /** obsolete: use prec instead */
OPJ_UINT32 bpp; OPJ_DEPRECATED_STRUCT_MEMBER(OPJ_UINT32 bpp, "Use prec instead");
/** signed (1) / unsigned (0) */ /** signed (1) / unsigned (0) */
OPJ_UINT32 sgnd; OPJ_UINT32 sgnd;
/** number of decoded resolution */ /** number of decoded resolution */
@ -738,10 +744,10 @@ typedef struct opj_image_comptparm {
OPJ_UINT32 x0; OPJ_UINT32 x0;
/** y component offset compared to the whole image */ /** y component offset compared to the whole image */
OPJ_UINT32 y0; OPJ_UINT32 y0;
/** precision */ /** precision: number of bits per component per pixel */
OPJ_UINT32 prec; OPJ_UINT32 prec;
/** image depth in bits */ /** obsolete: use prec instead */
OPJ_UINT32 bpp; OPJ_DEPRECATED_STRUCT_MEMBER(OPJ_UINT32 bpp, "Use prec instead");
/** signed (1) / unsigned (0) */ /** signed (1) / unsigned (0) */
OPJ_UINT32 sgnd; OPJ_UINT32 sgnd;
} opj_image_cmptparm_t; } opj_image_cmptparm_t;

View File

@ -225,7 +225,6 @@ static opj_image_t* readImageFromFilePPM(const char* filename,
param_image_read[it_file].dy = 0; param_image_read[it_file].dy = 0;
param_image_read[it_file].h = image_read->comps->h; param_image_read[it_file].h = image_read->comps->h;
param_image_read[it_file].w = image_read->comps->w; param_image_read[it_file].w = image_read->comps->w;
param_image_read[it_file].bpp = image_read->comps->bpp;
param_image_read[it_file].prec = image_read->comps->prec; param_image_read[it_file].prec = image_read->comps->prec;
param_image_read[it_file].sgnd = image_read->comps->sgnd; param_image_read[it_file].sgnd = image_read->comps->sgnd;
@ -356,7 +355,6 @@ static opj_image_t* readImageFromFilePGX(const char* filename,
param_image_read[it_file].dy = 0; param_image_read[it_file].dy = 0;
param_image_read[it_file].h = image_read->comps->h; param_image_read[it_file].h = image_read->comps->h;
param_image_read[it_file].w = image_read->comps->w; param_image_read[it_file].w = image_read->comps->w;
param_image_read[it_file].bpp = image_read->comps->bpp;
param_image_read[it_file].prec = image_read->comps->prec; param_image_read[it_file].prec = image_read->comps->prec;
param_image_read[it_file].sgnd = image_read->comps->sgnd; param_image_read[it_file].sgnd = image_read->comps->sgnd;
@ -403,7 +401,6 @@ static int imageToPNG(const opj_image_t* image, const char* filename,
param_image_write.dy = 0; param_image_write.dy = 0;
param_image_write.h = image->comps[num_comp_select].h; param_image_write.h = image->comps[num_comp_select].h;
param_image_write.w = image->comps[num_comp_select].w; param_image_write.w = image->comps[num_comp_select].w;
param_image_write.bpp = image->comps[num_comp_select].bpp;
param_image_write.prec = image->comps[num_comp_select].prec; param_image_write.prec = image->comps[num_comp_select].prec;
param_image_write.sgnd = image->comps[num_comp_select].sgnd; param_image_write.sgnd = image->comps[num_comp_select].sgnd;
@ -797,7 +794,6 @@ int main(int argc, char **argv)
param_image_diff[it_comp].dy = 0; param_image_diff[it_comp].dy = 0;
param_image_diff[it_comp].sgnd = 0; param_image_diff[it_comp].sgnd = 0;
param_image_diff[it_comp].prec = 8; param_image_diff[it_comp].prec = 8;
param_image_diff[it_comp].bpp = 1;
param_image_diff[it_comp].h = imageBase->comps[it_comp].h; param_image_diff[it_comp].h = imageBase->comps[it_comp].h;
param_image_diff[it_comp].w = imageBase->comps[it_comp].w; param_image_diff[it_comp].w = imageBase->comps[it_comp].w;
@ -814,13 +810,6 @@ int main(int argc, char **argv)
goto cleanup; goto cleanup;
} }
if (((imageBase->comps)[it_comp]).bpp != ((imageTest->comps)[it_comp]).bpp &&
!inParam.ignore_prec) {
printf("ERROR: bit per pixel mismatch [comp %d] (%d><%d)\n", it_comp,
((imageBase->comps)[it_comp]).bpp, ((imageTest->comps)[it_comp]).bpp);
goto cleanup;
}
if (((imageBase->comps)[it_comp]).h != ((imageTest->comps)[it_comp]).h) { if (((imageBase->comps)[it_comp]).h != ((imageTest->comps)[it_comp]).h) {
printf("ERROR: height mismatch [comp %d] (%d><%d)\n", it_comp, printf("ERROR: height mismatch [comp %d] (%d><%d)\n", it_comp,
((imageBase->comps)[it_comp]).h, ((imageTest->comps)[it_comp]).h); ((imageBase->comps)[it_comp]).h, ((imageTest->comps)[it_comp]).h);
@ -856,12 +845,12 @@ int main(int argc, char **argv)
double MSE = 0; double MSE = 0;
unsigned right_shift_input = 0; unsigned right_shift_input = 0;
unsigned right_shift_output = 0; unsigned right_shift_output = 0;
if (((imageBase->comps)[it_comp]).bpp > ((imageTest->comps)[it_comp]).bpp) { if (((imageBase->comps)[it_comp]).prec > ((imageTest->comps)[it_comp]).prec) {
right_shift_input = ((imageBase->comps)[it_comp]).bpp - (( right_shift_input = ((imageBase->comps)[it_comp]).prec - ((
imageTest->comps)[it_comp]).bpp; imageTest->comps)[it_comp]).prec;
} else { } else {
right_shift_output = ((imageTest->comps)[it_comp]).bpp - (( right_shift_output = ((imageTest->comps)[it_comp]).prec - ((
imageBase->comps)[it_comp]).bpp; imageBase->comps)[it_comp]).prec;
} }
for (itpxl = 0; for (itpxl = 0;
itpxl < ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h; itpxl < ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h;

View File

@ -36,102 +36,101 @@ void error_callback(const char *msg, void *v);
void warning_callback(const char *msg, void *v); void warning_callback(const char *msg, void *v);
void info_callback(const char *msg, void *v); void info_callback(const char *msg, void *v);
void error_callback(const char *msg, void *v) { void error_callback(const char *msg, void *v)
(void)msg; {
(void)v; (void)msg;
puts(msg); (void)v;
puts(msg);
} }
void warning_callback(const char *msg, void *v) { void warning_callback(const char *msg, void *v)
(void)msg; {
(void)v; (void)msg;
puts(msg); (void)v;
puts(msg);
} }
void info_callback(const char *msg, void *v) { void info_callback(const char *msg, void *v)
(void)msg; {
(void)v; (void)msg;
puts(msg); (void)v;
puts(msg);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char * v = opj_version(); const char * v = opj_version();
const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY;
unsigned int numcomps = 1; unsigned int numcomps = 1;
unsigned int i; unsigned int i;
unsigned int image_width = 256; unsigned int image_width = 256;
unsigned int image_height = 256; unsigned int image_height = 256;
opj_cparameters_t parameters; opj_cparameters_t parameters;
unsigned int subsampling_dx = 0; unsigned int subsampling_dx = 0;
unsigned int subsampling_dy = 0; unsigned int subsampling_dy = 0;
opj_image_cmptparm_t cmptparm; opj_image_cmptparm_t cmptparm;
opj_image_t *image; opj_image_t *image;
opj_codec_t* l_codec = 00; opj_codec_t* l_codec = 00;
OPJ_BOOL bSuccess; OPJ_BOOL bSuccess;
opj_stream_t *l_stream = 00; opj_stream_t *l_stream = 00;
(void)argc; (void)argc;
(void)argv; (void)argv;
opj_set_default_encoder_parameters(&parameters); opj_set_default_encoder_parameters(&parameters);
parameters.cod_format = J2K_CFMT; parameters.cod_format = J2K_CFMT;
puts(v); puts(v);
cmptparm.prec = 8; cmptparm.prec = 8;
cmptparm.bpp = 8; cmptparm.sgnd = 0;
cmptparm.sgnd = 0; cmptparm.dx = subsampling_dx;
cmptparm.dx = subsampling_dx; cmptparm.dy = subsampling_dy;
cmptparm.dy = subsampling_dy; cmptparm.w = image_width;
cmptparm.w = image_width; cmptparm.h = image_height;
cmptparm.h = image_height;
image = opj_image_create(numcomps, &cmptparm, color_space); image = opj_image_create(numcomps, &cmptparm, color_space);
assert( image ); assert(image);
for (i = 0; i < image_width * image_height; i++) for (i = 0; i < image_width * image_height; i++) {
{ unsigned int compno;
unsigned int compno; for (compno = 0; compno < numcomps; compno++) {
for(compno = 0; compno < numcomps; compno++) image->comps[compno].data[i] = 0;
{ }
image->comps[compno].data[i] = 0;
}
} }
/* catch events using our callbacks and give a local context */ /* catch events using our callbacks and give a local context */
opj_set_info_handler(l_codec, info_callback,00); opj_set_info_handler(l_codec, info_callback, 00);
opj_set_warning_handler(l_codec, warning_callback,00); opj_set_warning_handler(l_codec, warning_callback, 00);
opj_set_error_handler(l_codec, error_callback,00); opj_set_error_handler(l_codec, error_callback, 00);
l_codec = opj_create_compress(OPJ_CODEC_J2K); l_codec = opj_create_compress(OPJ_CODEC_J2K);
opj_set_info_handler(l_codec, info_callback,00); opj_set_info_handler(l_codec, info_callback, 00);
opj_set_warning_handler(l_codec, warning_callback,00); opj_set_warning_handler(l_codec, warning_callback, 00);
opj_set_error_handler(l_codec, error_callback,00); opj_set_error_handler(l_codec, error_callback, 00);
opj_setup_encoder(l_codec, &parameters, image); opj_setup_encoder(l_codec, &parameters, image);
l_stream = opj_stream_create_default_file_stream("testempty1.j2k", OPJ_FALSE);
assert(l_stream);
bSuccess = opj_start_compress(l_codec, image, l_stream);
if (!bSuccess) {
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return 0;
}
assert(bSuccess);
bSuccess = opj_encode(l_codec, l_stream);
assert(bSuccess);
bSuccess = opj_end_compress(l_codec, l_stream);
assert(bSuccess);
l_stream = opj_stream_create_default_file_stream("testempty1.j2k",OPJ_FALSE);
assert(l_stream);
bSuccess = opj_start_compress(l_codec,image,l_stream);
if( !bSuccess )
{
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
opj_image_destroy(image); opj_image_destroy(image);
puts("end");
return 0; return 0;
}
assert( bSuccess );
bSuccess = opj_encode(l_codec, l_stream);
assert( bSuccess );
bSuccess = opj_end_compress(l_codec, l_stream);
assert( bSuccess );
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
puts( "end" );
return 0;
} }

View File

@ -37,147 +37,145 @@ void error_callback(const char *msg, void *v);
void warning_callback(const char *msg, void *v); void warning_callback(const char *msg, void *v);
void info_callback(const char *msg, void *v); void info_callback(const char *msg, void *v);
void error_callback(const char *msg, void *v) { void error_callback(const char *msg, void *v)
(void)msg; {
(void)v; (void)msg;
puts(msg); (void)v;
puts(msg);
} }
void warning_callback(const char *msg, void *v) { void warning_callback(const char *msg, void *v)
(void)msg; {
(void)v; (void)msg;
puts(msg); (void)v;
puts(msg);
} }
void info_callback(const char *msg, void *v) { void info_callback(const char *msg, void *v)
(void)msg; {
(void)v; (void)msg;
puts(msg); (void)v;
puts(msg);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char * v = opj_version(); const char * v = opj_version();
const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY;
unsigned int numcomps = 1; unsigned int numcomps = 1;
unsigned int i; unsigned int i;
unsigned int image_width = 256; unsigned int image_width = 256;
unsigned int image_height = 256; unsigned int image_height = 256;
opj_cparameters_t parameters; opj_cparameters_t parameters;
unsigned int subsampling_dx; unsigned int subsampling_dx;
unsigned int subsampling_dy; unsigned int subsampling_dy;
const char outputfile[] = "testempty2.j2k"; const char outputfile[] = "testempty2.j2k";
opj_image_cmptparm_t cmptparm; opj_image_cmptparm_t cmptparm;
opj_image_t *image; opj_image_t *image;
opj_codec_t* l_codec = 00; opj_codec_t* l_codec = 00;
OPJ_BOOL bSuccess; OPJ_BOOL bSuccess;
opj_stream_t *l_stream = 00; opj_stream_t *l_stream = 00;
(void)argc; (void)argc;
(void)argv; (void)argv;
opj_set_default_encoder_parameters(&parameters); opj_set_default_encoder_parameters(&parameters);
parameters.cod_format = J2K_CFMT; parameters.cod_format = J2K_CFMT;
puts(v); puts(v);
subsampling_dx = (unsigned int)parameters.subsampling_dx; subsampling_dx = (unsigned int)parameters.subsampling_dx;
subsampling_dy = (unsigned int)parameters.subsampling_dy; subsampling_dy = (unsigned int)parameters.subsampling_dy;
cmptparm.prec = 8; cmptparm.prec = 8;
cmptparm.bpp = 8; cmptparm.sgnd = 0;
cmptparm.sgnd = 0; cmptparm.dx = subsampling_dx;
cmptparm.dx = subsampling_dx; cmptparm.dy = subsampling_dy;
cmptparm.dy = subsampling_dy; cmptparm.w = image_width;
cmptparm.w = image_width; cmptparm.h = image_height;
cmptparm.h = image_height; strncpy(parameters.outfile, outputfile, sizeof(parameters.outfile) - 1);
strncpy(parameters.outfile, outputfile, sizeof(parameters.outfile)-1);
image = opj_image_create(numcomps, &cmptparm, color_space); image = opj_image_create(numcomps, &cmptparm, color_space);
assert( image ); assert(image);
for (i = 0; i < image_width * image_height; i++) for (i = 0; i < image_width * image_height; i++) {
{ unsigned int compno;
unsigned int compno; for (compno = 0; compno < numcomps; compno++) {
for(compno = 0; compno < numcomps; compno++) image->comps[compno].data[i] = 0;
{ }
image->comps[compno].data[i] = 0;
}
} }
/* catch events using our callbacks and give a local context */ /* catch events using our callbacks and give a local context */
opj_set_info_handler(l_codec, info_callback,00); opj_set_info_handler(l_codec, info_callback, 00);
opj_set_warning_handler(l_codec, warning_callback,00); opj_set_warning_handler(l_codec, warning_callback, 00);
opj_set_error_handler(l_codec, error_callback,00); opj_set_error_handler(l_codec, error_callback, 00);
l_codec = opj_create_compress(OPJ_CODEC_J2K); l_codec = opj_create_compress(OPJ_CODEC_J2K);
opj_set_info_handler(l_codec, info_callback,00); opj_set_info_handler(l_codec, info_callback, 00);
opj_set_warning_handler(l_codec, warning_callback,00); opj_set_warning_handler(l_codec, warning_callback, 00);
opj_set_error_handler(l_codec, error_callback,00); opj_set_error_handler(l_codec, error_callback, 00);
opj_setup_encoder(l_codec, &parameters, image); opj_setup_encoder(l_codec, &parameters, image);
l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE); l_stream = opj_stream_create_default_file_stream(parameters.outfile, OPJ_FALSE);
if( !l_stream ) if (!l_stream) {
{ fprintf(stderr, "Something went wrong during creation of stream\n");
fprintf( stderr, "Something went wrong during creation of stream\n" ); opj_destroy_codec(l_codec);
opj_destroy_codec(l_codec); opj_image_destroy(image);
opj_image_destroy(image); opj_stream_destroy(l_stream);
opj_stream_destroy(l_stream); return 1;
return 1;
} }
assert(l_stream); assert(l_stream);
bSuccess = opj_start_compress(l_codec,image,l_stream); bSuccess = opj_start_compress(l_codec, image, l_stream);
if( !bSuccess ) if (!bSuccess) {
{ opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return 0;
}
assert(bSuccess);
bSuccess = opj_encode(l_codec, l_stream);
assert(bSuccess);
bSuccess = opj_end_compress(l_codec, l_stream);
assert(bSuccess);
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
opj_image_destroy(image); opj_image_destroy(image);
/* read back the generated file */
{
opj_codec_t* d_codec = 00;
opj_dparameters_t dparameters;
d_codec = opj_create_decompress(OPJ_CODEC_J2K);
opj_set_info_handler(d_codec, info_callback, 00);
opj_set_warning_handler(d_codec, warning_callback, 00);
opj_set_error_handler(d_codec, error_callback, 00);
bSuccess = opj_setup_decoder(d_codec, &dparameters);
assert(bSuccess);
l_stream = opj_stream_create_default_file_stream(outputfile, 1);
assert(l_stream);
bSuccess = opj_read_header(l_stream, d_codec, &image);
assert(bSuccess);
bSuccess = opj_decode(l_codec, l_stream, image);
assert(bSuccess);
bSuccess = opj_end_decompress(l_codec, l_stream);
assert(bSuccess);
opj_stream_destroy(l_stream);
opj_destroy_codec(d_codec);
opj_image_destroy(image);
}
puts("end");
return 0; return 0;
}
assert( bSuccess );
bSuccess = opj_encode(l_codec, l_stream);
assert( bSuccess );
bSuccess = opj_end_compress(l_codec, l_stream);
assert( bSuccess );
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
/* read back the generated file */
{
opj_codec_t* d_codec = 00;
opj_dparameters_t dparameters;
d_codec = opj_create_decompress(OPJ_CODEC_J2K);
opj_set_info_handler(d_codec, info_callback,00);
opj_set_warning_handler(d_codec, warning_callback,00);
opj_set_error_handler(d_codec, error_callback,00);
bSuccess = opj_setup_decoder(d_codec, &dparameters);
assert( bSuccess );
l_stream = opj_stream_create_default_file_stream(outputfile,1);
assert( l_stream );
bSuccess = opj_read_header(l_stream, d_codec, &image);
assert( bSuccess );
bSuccess = opj_decode(l_codec, l_stream, image);
assert( bSuccess );
bSuccess = opj_end_decompress(l_codec, l_stream);
assert( bSuccess );
opj_stream_destroy(l_stream);
opj_destroy_codec(d_codec);
opj_image_destroy(image);
}
puts( "end" );
return 0;
} }