diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2012-10-21 20:57:29 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2012-10-21 20:57:29 +0000 |
commit | 29a09fe56dacb89e94041fae9cca620cc718b7bf (patch) | |
tree | 9e787499a248ebf8113e47e1264d7139486fd45b /converter/other/jpeg2000/pamtojpeg2k.c | |
parent | 4f9fe4469128aba7143155947210a380baf09fed (diff) | |
download | netpbm-mirror-29a09fe56dacb89e94041fae9cca620cc718b7bf.tar.gz netpbm-mirror-29a09fe56dacb89e94041fae9cca620cc718b7bf.tar.xz netpbm-mirror-29a09fe56dacb89e94041fae9cca620cc718b7bf.zip |
Default to no output size constraint, allow compression ratio < 1. Note that compression >=1 is not always possible, because of uncompressed metadata
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1754 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/jpeg2000/pamtojpeg2k.c')
-rw-r--r-- | converter/other/jpeg2000/pamtojpeg2k.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/converter/other/jpeg2000/pamtojpeg2k.c b/converter/other/jpeg2000/pamtojpeg2k.c index 731ee38c..15ea0f31 100644 --- a/converter/other/jpeg2000/pamtojpeg2k.c +++ b/converter/other/jpeg2000/pamtojpeg2k.c @@ -43,7 +43,8 @@ struct cmdlineInfo { unsigned int cblkwidth; unsigned int cblkheight; enum compmode compmode; - float compressionRatio; + unsigned int compressionSpec; + float compression; char * ilyrrates; enum progression progression; unsigned int numrlvls; @@ -81,7 +82,7 @@ parseCommandLine(int argc, char ** argv, unsigned int tilewidthSpec, tileheightSpec; unsigned int prcwidthSpec, prcheightSpec; unsigned int cblkwidthSpec, cblkheightSpec; - unsigned int modeSpec, compressionSpec, ilyrratesSpec; + unsigned int modeSpec, ilyrratesSpec; unsigned int progressionSpec, numrlvlsSpec, numgbitsSpec; unsigned int debuglevelSpec; @@ -115,8 +116,8 @@ parseCommandLine(int argc, char ** argv, &cblkheightSpec, 0); OPTENT3(0, "mode", OPT_STRING, &modeOpt, &modeSpec, 0); - OPTENT3(0, "compression", OPT_FLOAT, &cmdlineP->compressionRatio, - &compressionSpec, 0); + OPTENT3(0, "compression", OPT_FLOAT, &cmdlineP->compression, + &cmdlineP->compressionSpec, 0); OPTENT3(0, "ilyrrates", OPT_STRING, &cmdlineP->ilyrrates, &ilyrratesSpec, 0); OPTENT3(0, "progression", OPT_STRING, &progressionOpt, @@ -184,11 +185,6 @@ parseCommandLine(int argc, char ** argv, "valid values are 'INTEGER' and 'REAL'", modeOpt); } else cmdlineP->compmode = COMPMODE_INTEGER; - if (compressionSpec) { - if (cmdlineP->compressionRatio < 1.0) - pm_error("Compression ratio less than 1 does not make sense."); - } else - cmdlineP->compressionRatio = 1.0; if (!ilyrratesSpec) cmdlineP->ilyrrates = (char*) ""; if (progressionSpec) { @@ -230,7 +226,10 @@ parseCommandLine(int argc, char ** argv, static void createJasperRaster(struct pam * const inpamP, jas_image_t * const jasperP) { - +/*---------------------------------------------------------------------------- + Create the raster in the *jasperP object, reading the raster from the + input file described by *inpamP, which is positioned to the raster. +-----------------------------------------------------------------------------*/ jas_matrix_t ** matrix; /* malloc'ed */ /* matrix[X] is the data for Plane X of the current row */ unsigned int plane; @@ -394,8 +393,15 @@ writeJpc(jas_image_t * const jasperP, /* Note that asprintfN() doesn't understand %f, but sprintf() does */ - sprintf(rateOpt, "%1.9f", 1.0/cmdline.compressionRatio); - + if (cmdline.compressionSpec) + sprintf(rateOpt, "rate=%1.9f", 1.0/cmdline.compression); + else { + /* No 'rate' option. This means there is no constraint on the image + size, so the encoder will compress losslessly. Note that the + image may get larger, because of metadata. + */ + rateOpt[0] = '\0'; + } pm_asprintf(&options, "imgareatlx=%u " "imgareatly=%u " @@ -408,8 +414,8 @@ writeJpc(jas_image_t * const jasperP, "cblkwidth=%u " "cblkheight=%u " "mode=%s " - "rate=%s " - "%s " + "%s " /* rate */ + "%s " /* ilyrrates */ "prg=%s " "numrlvls=%u " "numgbits=%u " @@ -441,8 +447,8 @@ writeJpc(jas_image_t * const jasperP, cmdline.pterm ? "pterm" : "", cmdline.resetprob ? "resetprob" : "" ); - pm_strfree(ilyrratesOpt); + pm_strfree(ilyrratesOpt); /* Open the output image file (Standard Output) */ outStreamP = jas_stream_fdopen(fileno(ofP), "w+b"); @@ -459,7 +465,7 @@ writeJpc(jas_image_t * const jasperP, rc = jas_image_encode(jasperP, outStreamP, jas_image_strtofmt((char*)"jpc"), - (char*)options); + (char *)options); if (rc != 0) pm_error("jas_image_encode() failed to encode the JPEG 2000 " "image. Rc=%d", rc); @@ -487,7 +493,7 @@ int main(int argc, char **argv) { struct cmdlineInfo cmdline; - FILE *ifP; + FILE * ifP; struct pam inpam; jas_image_t * jasperP; |