now allows 16-bit precision for mj2 encoding and decoding (solves Issue 49 and Issue 63). Credit to Winfried.

This commit is contained in:
Antonin Descampe 2011-02-17 20:01:14 +00:00
parent af71acb043
commit e023107e97
3 changed files with 70 additions and 32 deletions

View File

@ -5,6 +5,9 @@ What's New for OpenJPEG
! : changed ! : changed
+ : added + : added
February 17, 2011
* [antonin] now allows 16-bit precision for mj2 encoding and decoding (solves Issue 49 and Issue 63). Credit to Winfried.
February 9, 2011 February 9, 2011
! [antonin] renamed "java sources" to "java-sources" to avoid blank space ! [antonin] renamed "java sources" to "java-sources" to avoid blank space
- [antonin] removed opj_config.h.in from svn, as it is automaticaly generated by autoheader when calling ./bootstrap.sh - [antonin] removed opj_config.h.in from svn, as it is automaticaly generated by autoheader when calling ./bootstrap.sh
@ -17,7 +20,7 @@ January 30, 2011
- [antonin] removed depcomp file from trunk (automatically copied by automake in main folder) - [antonin] removed depcomp file from trunk (automatically copied by automake in main folder)
January 29, 2011 January 29, 2011
* [antonin] removed 'é' in license header to prevent warning C4819 (see http://code.google.com/p/openjpeg/issues/detail?id=57). * [antonin] removed 'é' in license header to prevent warning C4819 (see Issue 57).
January 24, 2011 January 24, 2011
- [antonin] remove more obsolete VS files. Left only mj2_to_metadata VS files, as this is the only executable not yet handled by CMake. - [antonin] remove more obsolete VS files. Left only mj2_to_metadata VS files, as this is the only executable not yet handled by CMake.
@ -34,7 +37,7 @@ January 18, 2011
! [rdieter] cmake: SOVERSION change to 1 (from 1.4) to match auto-tools ! [rdieter] cmake: SOVERSION change to 1 (from 1.4) to match auto-tools
January 17, 2011 January 17, 2011
- [rdieter] remove generated files (ticket 52) - [rdieter] remove generated files (Issue 52)
January 16, 2011 January 16, 2011
* [antonin] convert.c: inclusion of endian.h has to be different on APPLE platforms * [antonin] convert.c: inclusion of endian.h has to be different on APPLE platforms

View File

@ -251,7 +251,7 @@ int main(int argc, char **argv)
opj_cinfo_t* cinfo; opj_cinfo_t* cinfo;
bool bSuccess; bool bSuccess;
int numframes; int numframes;
int prec = 0; int prec = 8;/* DEFAULT */
double total_time = 0; double total_time = 0;
memset(&mj2_parameters, 0, sizeof(mj2_cparameters_t)); memset(&mj2_parameters, 0, sizeof(mj2_cparameters_t));
@ -623,7 +623,11 @@ int main(int argc, char **argv)
"Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]); "Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]);
return 1; return 1;
} }
if(prec < 1 || prec > 16)
{
fprintf(stderr, "Error: Depth %d must be in the range 8 .. 16\n",prec);
return 1;
}
if ((j2k_parameters->cp_disto_alloc || j2k_parameters->cp_fixed_alloc || j2k_parameters->cp_fixed_quality) if ((j2k_parameters->cp_disto_alloc || j2k_parameters->cp_fixed_alloc || j2k_parameters->cp_fixed_quality)
&& (!(j2k_parameters->cp_disto_alloc ^ j2k_parameters->cp_fixed_alloc ^ j2k_parameters->cp_fixed_quality))) { && (!(j2k_parameters->cp_disto_alloc ^ j2k_parameters->cp_fixed_alloc ^ j2k_parameters->cp_fixed_quality))) {
fprintf(stderr, "Error: options -r -q and -f cannot be used together !!\n"); fprintf(stderr, "Error: options -r -q and -f cannot be used together !!\n");
@ -668,9 +672,6 @@ int main(int argc, char **argv)
+ 1 : mj2_parameters.Dim[1] + (mj2_parameters.h - 1) * j2k_parameters->subsampling_dy + 1; + 1 : mj2_parameters.Dim[1] + (mj2_parameters.h - 1) * j2k_parameters->subsampling_dy + 1;
mj2_parameters.numcomps = 3; /* YUV files only have 3 components */ mj2_parameters.numcomps = 3; /* YUV files only have 3 components */
if(prec < 1 || prec > 32) prec = 8; /* DEFAULT */
mj2_parameters.prec = prec; mj2_parameters.prec = prec;
j2k_parameters->tcp_mct = 0; j2k_parameters->tcp_mct = 0;

View File

@ -104,23 +104,26 @@ opj_image_t *mj2_image_create(mj2_tk_t * tk, opj_cparameters_t *parameters)
char yuvtoimage(mj2_tk_t * tk, opj_image_t * img, int frame_num, opj_cparameters_t *parameters, char* infile) char yuvtoimage(mj2_tk_t * tk, opj_image_t * img, int frame_num, opj_cparameters_t *parameters, char* infile)
{ {
int i, compno; int i, compno;
int offset, size, max, prec_size; int offset, size, max, prec_bytes, is_16, v;
long end_of_f, position; long end_of_f, position;
int numcomps = 3; int numcomps = 3;
int subsampling_dx = parameters->subsampling_dx; int subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy; int subsampling_dy = parameters->subsampling_dy;
FILE *yuvfile; FILE *yuvfile;
int *data;
unsigned char uc;
yuvfile = fopen(infile,"rb"); yuvfile = fopen(infile,"rb");
if (!yuvfile) { if (!yuvfile) {
fprintf(stderr, "failed to open %s for readings\n",parameters->infile); fprintf(stderr, "failed to open %s for readings\n",parameters->infile);
return 1; return 1;
} }
prec_size = (tk->depth + 7)/8;/* bytes of precision */ is_16 = (tk->depth > 8);
prec_bytes = (is_16?2:1);
offset = (int) ((double) (frame_num * tk->w * tk->h) * (1.0 + offset = (int) ((double) (frame_num * tk->w * tk->h) * (1.0 +
1.0 * (double) 2 / (double) (tk->CbCr_subsampling_dx * tk->CbCr_subsampling_dy))); 1.0 * (double) 2 / (double) (tk->CbCr_subsampling_dx * tk->CbCr_subsampling_dy)));
offset *= prec_size; offset *= prec_bytes;
fseek(yuvfile, 0, SEEK_END); fseek(yuvfile, 0, SEEK_END);
end_of_f = ftell(yuvfile); end_of_f = ftell(yuvfile);
@ -140,19 +143,25 @@ char yuvtoimage(mj2_tk_t * tk, opj_image_t * img, int frame_num, opj_cparameters
img->y1 = !tk->Dim[1] ? (tk->h - 1) * subsampling_dy + 1 : tk->Dim[1] + img->y1 = !tk->Dim[1] ? (tk->h - 1) * subsampling_dy + 1 : tk->Dim[1] +
(tk->h - 1) * subsampling_dy + 1; (tk->h - 1) * subsampling_dy + 1;
size = tk->w * tk->h * prec_size; size = tk->w * tk->h * prec_bytes;
for(compno = 0; compno < numcomps; compno++) for(compno = 0; compno < numcomps; compno++)
{ {
max = size/(img->comps[compno].dx * img->comps[compno].dy); max = size/(img->comps[compno].dx * img->comps[compno].dy);
data = img->comps[compno].data;
for (i = 0; i < max && !feof(yuvfile); i++) for (i = 0; i < max && !feof(yuvfile); i++)
{ {
if (!fread(&img->comps[compno].data[i], 1, 1, yuvfile)) v = 0;
fread(&uc, 1, 1, yuvfile);
v = uc;
if(is_16)
{ {
fprintf(stderr, "Error reading %s file !!\n", infile); fread(&uc, 1, 1, yuvfile);
return 1; v |= (uc<<8);
} }
*data++ = v;
} }
} }
fclose(yuvfile); fclose(yuvfile);
@ -173,7 +182,9 @@ char yuvtoimage(mj2_tk_t * tk, opj_image_t * img, int frame_num, opj_cparameters
bool imagetoyuv(opj_image_t * img, char *outfile) bool imagetoyuv(opj_image_t * img, char *outfile)
{ {
FILE *f; FILE *f;
int i; int *data;
int i, v, is_16, prec_bytes;
unsigned char buf[2];
if (img->numcomps == 3) { if (img->numcomps == 3) {
if (img->comps[0].dx != img->comps[1].dx / 2 if (img->comps[0].dx != img->comps[1].dx / 2
@ -193,38 +204,61 @@ bool imagetoyuv(opj_image_t * img, char *outfile)
fprintf(stderr, "failed to open %s for writing\n", outfile); fprintf(stderr, "failed to open %s for writing\n", outfile);
return false; return false;
} }
is_16 = (img->comps[0].prec > 8);
prec_bytes = (is_16?2:1);
data = img->comps[0].data;
for (i = 0; i < (img->comps[0].w * img->comps[0].h); i++) { for (i = 0; i < (img->comps[0].w * img->comps[0].h); i++) {
unsigned char y; v = *data++;
y = img->comps[0].data[i]; buf[0] = (unsigned char)v;
fwrite(&y, 1, 1, f);
if(is_16) buf[1] = (unsigned char)(v>>8);
fwrite(buf, 1, prec_bytes, f);
} }
if (img->numcomps == 3) { if (img->numcomps == 3) {
for (i = 0; i < (img->comps[1].w * img->comps[1].h); i++) { data = img->comps[1].data;
unsigned char cb;
cb = img->comps[1].data[i];
fwrite(&cb, 1, 1, f);
}
for (i = 0; i < (img->comps[1].w * img->comps[1].h); i++) {
v = *data++;
buf[0] = (unsigned char)v;
if(is_16) buf[1] = (unsigned char)(v>>8);
fwrite(buf, 1, prec_bytes, f);
}
data = img->comps[2].data;
for (i = 0; i < (img->comps[2].w * img->comps[2].h); i++) { for (i = 0; i < (img->comps[2].w * img->comps[2].h); i++) {
unsigned char cr; v = *data++;
cr = img->comps[2].data[i]; buf[0] = (unsigned char)v;
fwrite(&cr, 1, 1, f);
if(is_16) buf[1] = (unsigned char)(v>>8);
fwrite(buf, 1, prec_bytes, f);
} }
} else if (img->numcomps == 1) { } else if (img->numcomps == 1) {
/* fake CbCr values */
if(is_16)
{
buf[0] = 255;
if(img->comps[0].prec == 10) buf[1] = 1;
else
if(img->comps[0].prec == 12) buf[1] = 3;
else
buf[1] = 125;
}
else buf[0] = 125;
for (i = 0; i < (img->comps[0].w * img->comps[0].h * 0.25); i++) { for (i = 0; i < (img->comps[0].w * img->comps[0].h * 0.25); i++) {
unsigned char cb = 125; fwrite(buf, 1, prec_bytes, f);
fwrite(&cb, 1, 1, f);
} }
for (i = 0; i < (img->comps[0].w * img->comps[0].h * 0.25); i++) { for (i = 0; i < (img->comps[0].w * img->comps[0].h * 0.25); i++) {
unsigned char cr = 125; fwrite(buf, 1, prec_bytes, f);
fwrite(&cr, 1, 1, f);
} }
} }
fclose(f); fclose(f);