]> Creatis software - gdcm.git/blobdiff - src/gdcmjasper/src/libjasper/jpc/jpc_enc.c
COMP: VS6 was not happy to cast an int into ushort
[gdcm.git] / src / gdcmjasper / src / libjasper / jpc / jpc_enc.c
index 2898c2588a8309ace3a5e34a665b4910409edbe6..ec13ad23b274fdf7ff75ed5efd51e3aaac2f83dc 100644 (file)
@@ -62,7 +62,7 @@
  */
 
 /*
- * $Id: jpc_enc.c,v 1.1 2005/05/22 18:33:04 malaterre Exp $
+ * $Id: jpc_enc.c,v 1.5 2005/06/11 02:05:20 malaterre Exp $
  */
 
 /******************************************************************************\
@@ -147,8 +147,8 @@ void jpc_enc_dump(jpc_enc_t *enc);
 int dump_passes(jpc_enc_pass_t *passes, int numpasses, jpc_enc_cblk_t *cblk);
 void calcrdslopes(jpc_enc_cblk_t *cblk);
 void dump_layeringinfo(jpc_enc_t *enc);
-static int jpc_calcssexp(jpc_fix_t stepsize);
-static int jpc_calcssmant(jpc_fix_t stepsize);
+/*static int jpc_calcssexp(jpc_fix_t stepsize);*/
+/*static int jpc_calcssmant(jpc_fix_t stepsize);*/
 void quantize(jas_matrix_t *data, jpc_fix_t stepsize);
 static int jpc_enc_encodemainhdr(jpc_enc_t *enc);
 static int jpc_enc_encodemainbody(jpc_enc_t *enc);
@@ -768,6 +768,7 @@ error:
   if (cp) {
     jpc_enc_cp_destroy(cp);
   }
+  (void)ret; /* ret' is assigned a value that is never used in function cp_create */
   return 0;
 }
 
@@ -797,9 +798,10 @@ int ratestrtosize(char *s, uint_fast32_t rawsize, uint_fast32_t *size)
     } else if (f > 1.0) {
       *size = rawsize + 1;
     } else {
-      *size = f * rawsize;
+      *size = (uint_fast32_t)(f * rawsize);
     }
   }
+  (void)cp; /* 'cp' is assigned a value that is never used in function ratestrtosize */
   return 0;
 }
 
@@ -867,6 +869,7 @@ void jpc_enc_destroy(jpc_enc_t *enc)
 * Code.
 \******************************************************************************/
 
+#if 0
 static int jpc_calcssmant(jpc_fix_t stepsize)
 {
   int n;
@@ -887,6 +890,7 @@ static int jpc_calcssexp(jpc_fix_t stepsize)
 {
   return jpc_firstone(stepsize) - JPC_FIX_FRACBITS;
 }
+#endif
 
 static int jpc_enc_encodemainhdr(jpc_enc_t *enc)
 {
@@ -1033,8 +1037,8 @@ startoff = jas_stream_getrwcount(enc->out);
   cod->mctrans = (cp->tcp.mctid != JPC_MCT_NONE);
   if (tccp->csty & JPC_COX_PRT) {
     for (rlvlno = 0; rlvlno < tccp->maxrlvls; ++rlvlno) {
-      cod->compparms.rlvls[rlvlno].parwidthval = tccp->prcwidthexpns[rlvlno];
-      cod->compparms.rlvls[rlvlno].parheightval = tccp->prcheightexpns[rlvlno];
+      cod->compparms.rlvls[rlvlno].parwidthval = (uint_fast8_t)tccp->prcwidthexpns[rlvlno];
+      cod->compparms.rlvls[rlvlno].parheightval = (uint_fast8_t)tccp->prcheightexpns[rlvlno];
     }
   }
   if (jpc_putms(enc->out, enc->cstate, enc->mrk)) {
@@ -1094,14 +1098,13 @@ startoff = jas_stream_getrwcount(enc->out);
     enc->mainbodysize = UINT_FAST32_MAX;
   }
 
+  (void)mctsynweight; /* 'mctsynweight' is assigned a value that is never used in function jpc_enc_encodemainhdr */
   return 0;
 }
 
 static int jpc_enc_encodemainbody(jpc_enc_t *enc)
 {
   int tileno;
-  int tilex;
-  int tiley;
   int i;
   jpc_sot_t *sot;
   jpc_enc_tcmpt_t *comp;
@@ -1115,7 +1118,6 @@ static int jpc_enc_encodemainbody(jpc_enc_t *enc)
   int adjust;
   int j;
   int absbandno;
-  long numbytes;
   long tilehdrlen;
   long tilelen;
   jpc_enc_tile_t *tile;
@@ -1137,12 +1139,7 @@ int numgbits;
 
   cp = enc->cp;
 
-  /* Avoid compile warnings. */
-  numbytes = 0;
-
   for (tileno = 0; tileno < JAS_CAST(int, cp->numtiles); ++tileno) {
-    tilex = tileno % cp->numhtiles;
-    tiley = tileno / cp->numhtiles;
 
     if (!(enc->curtile = jpc_enc_tile_create(enc->cp, enc->image, tileno))) {
       abort();
@@ -1392,14 +1389,14 @@ if (jpc_enc_enccblks(enc)) {
     rho = (double) (tile->brx - tile->tlx) * (tile->bry - tile->tly) /
       ((cp->refgrdwidth - cp->imgareatlx) * (cp->refgrdheight -
       cp->imgareatly));
-    tile->rawsize = cp->rawsize * rho;
+    tile->rawsize = (uint_fast32_t)(cp->rawsize * rho);
 
     for (lyrno = 0; lyrno < tile->numlyrs - 1; ++lyrno) {
-      tile->lyrsizes[lyrno] = tile->rawsize * jpc_fixtodbl(
-        cp->tcp.ilyrrates[lyrno]);
+      tile->lyrsizes[lyrno] = (uint_fast32_t)(tile->rawsize * jpc_fixtodbl(
+        cp->tcp.ilyrrates[lyrno]));
     }
-    tile->lyrsizes[tile->numlyrs - 1] = (cp->totalsize != UINT_FAST32_MAX) ?
-      (rho * enc->mainbodysize) : UINT_FAST32_MAX;
+    tile->lyrsizes[tile->numlyrs - 1] = (uint_fast32_t)((cp->totalsize != UINT_FAST32_MAX) ?
+      (rho * enc->mainbodysize) : UINT_FAST32_MAX);
     for (lyrno = 0; lyrno < tile->numlyrs; ++lyrno) {
       if (tile->lyrsizes[lyrno] != UINT_FAST32_MAX) {
         if (tilehdrlen <= JAS_CAST(long, tile->lyrsizes[lyrno])) {
@@ -1634,7 +1631,7 @@ int rateallocate(jpc_enc_t *enc, int numlyrs, uint_fast32_t *cumlens)
   jpc_flt_t lo;
   jpc_flt_t hi;
   jas_stream_t *out;
-  long cumlen;
+  unsigned long cumlen;
   int lyrno;
   jpc_flt_t thresh;
   jpc_flt_t goodthresh;
@@ -1806,10 +1803,10 @@ if (jas_getdbglevel()) {
 
       /* Check the rate constraint. */
       assert(pos >= 0);
-      if (pos > cumlen) {
+      if (pos > (long)cumlen) {
         /* The rate is too high. */
         lo = thresh;
-      } else if (pos <= cumlen) {
+      } else if (pos <= (long)cumlen) {
         /* The rate is low enough, so try higher. */
         hi = thresh;
         if (!success || thresh < goodthresh) {
@@ -1922,7 +1919,7 @@ jpc_enc_tile_t *jpc_enc_tile_create(jpc_enc_cp_t *cp, jas_image_t *image, int ti
   jpc_enc_tile_t *tile;
   uint_fast32_t htileno;
   uint_fast32_t vtileno;
-  uint_fast16_t lyrno;
+  int_fast16_t lyrno;
   uint_fast16_t cmptno;
   jpc_enc_tcmpt_t *tcmpt;
 
@@ -2023,7 +2020,7 @@ error:
 void jpc_enc_tile_destroy(jpc_enc_tile_t *tile)
 {
   jpc_enc_tcmpt_t *tcmpt;
-  uint_fast16_t cmptno;
+  int_fast16_t cmptno;
 
   if (tile->tcmpts) {
     for (cmptno = 0, tcmpt = tile->tcmpts; cmptno <
@@ -2045,7 +2042,7 @@ static jpc_enc_tcmpt_t *tcmpt_create(jpc_enc_tcmpt_t *tcmpt, jpc_enc_cp_t *cp,
   jas_image_t *image, jpc_enc_tile_t *tile)
 {
   uint_fast16_t cmptno;
-  uint_fast16_t rlvlno;
+  int_fast16_t rlvlno;
   jpc_enc_rlvl_t *rlvl;
   uint_fast32_t tlx;
   uint_fast32_t tly;
@@ -2140,7 +2137,7 @@ error:
 static void tcmpt_destroy(jpc_enc_tcmpt_t *tcmpt)
 {
   jpc_enc_rlvl_t *rlvl;
-  uint_fast16_t rlvlno;
+  int_fast16_t rlvlno;
 
   if (tcmpt->rlvls) {
     for (rlvlno = 0, rlvl = tcmpt->rlvls; rlvlno < tcmpt->numrlvls;
@@ -2166,7 +2163,7 @@ static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp,
   uint_fast32_t tlprctly;
   uint_fast32_t brprcbrx;
   uint_fast32_t brprcbry;
-  uint_fast16_t bandno;
+  int_fast16_t bandno;
   jpc_enc_band_t *band;
 
   /* Deduce the resolution level. */
@@ -2204,8 +2201,8 @@ static jpc_enc_rlvl_t *rlvl_create(jpc_enc_rlvl_t *rlvl, jpc_enc_cp_t *cp,
     rlvl->cbgwidthexpn = rlvl->prcwidthexpn - 1;
     rlvl->cbgheightexpn = rlvl->prcheightexpn - 1;
   }
-  rlvl->cblkwidthexpn = JAS_MIN(cp->tccp.cblkwidthexpn, rlvl->cbgwidthexpn);
-  rlvl->cblkheightexpn = JAS_MIN(cp->tccp.cblkheightexpn, rlvl->cbgheightexpn);
+  rlvl->cblkwidthexpn = JAS_MIN((int)cp->tccp.cblkwidthexpn, rlvl->cbgwidthexpn);
+  rlvl->cblkheightexpn = JAS_MIN((int)cp->tccp.cblkheightexpn, rlvl->cbgheightexpn);
 
   /* Compute the number of precincts. */
   tlprctlx = JPC_FLOORTOMULTPOW2(rlvl->tlx, rlvl->prcwidthexpn);
@@ -2242,7 +2239,7 @@ error:
 static void rlvl_destroy(jpc_enc_rlvl_t *rlvl)
 {
   jpc_enc_band_t *band;
-  uint_fast16_t bandno;
+  int_fast16_t bandno;
 
   if (rlvl->bands) {
     for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
@@ -2261,7 +2258,7 @@ static jpc_enc_band_t *band_create(jpc_enc_band_t *band, jpc_enc_cp_t *cp,
   uint_fast16_t rlvlno;
   jpc_tsfb_band_t *bandinfo;
   jpc_enc_tcmpt_t *tcmpt;
-  uint_fast32_t prcno;
+  int_fast32_t prcno;
   jpc_enc_prc_t *prc;
 
   tcmpt = rlvl->tcmpt;
@@ -2324,7 +2321,7 @@ static void band_destroy(jpc_enc_band_t *band)
 {
   jpc_enc_prc_t *prc;
   jpc_enc_rlvl_t *rlvl;
-  uint_fast32_t prcno;
+  int_fast32_t prcno;
 
   if (band->prcs) {
     rlvl = band->rlvl;
@@ -2356,7 +2353,7 @@ static jpc_enc_prc_t *prc_create(jpc_enc_prc_t *prc, jpc_enc_cp_t *cp, jpc_enc_b
   uint_fast32_t tlcblktly;
   uint_fast32_t brcblkbrx;
   uint_fast32_t brcblkbry;
-  uint_fast32_t cblkno;
+  int_fast32_t cblkno;
   jpc_enc_cblk_t *cblk;
   jpc_enc_tcmpt_t *tcmpt;
 
@@ -2388,11 +2385,11 @@ if (!rlvlno) {
     corners of the precinct. */
   cbgtlx = tlcbgtlx + (prcxind << rlvl->cbgwidthexpn);
   cbgtly = tlcbgtly + (prcyind << rlvl->cbgheightexpn);
-  prc->tlx = JAS_MAX(jas_seq2d_xstart(band->data), cbgtlx);
-  prc->tly = JAS_MAX(jas_seq2d_ystart(band->data), cbgtly);
-  prc->brx = JAS_MIN(jas_seq2d_xend(band->data), cbgtlx +
+  prc->tlx = JAS_MAX((uint_fast32_t)jas_seq2d_xstart(band->data), cbgtlx);
+  prc->tly = JAS_MAX((uint_fast32_t)jas_seq2d_ystart(band->data), cbgtly);
+  prc->brx = JAS_MIN((uint_fast32_t)jas_seq2d_xend(band->data), cbgtlx +
     (1 << rlvl->cbgwidthexpn));
-  prc->bry = JAS_MIN(jas_seq2d_yend(band->data), cbgtly +
+  prc->bry = JAS_MIN((uint_fast32_t)jas_seq2d_yend(band->data), cbgtly +
     (1 << rlvl->cbgheightexpn));
 
   if (prc->tlx < prc->brx && prc->tly < prc->bry) {
@@ -2467,7 +2464,7 @@ error:
 static void prc_destroy(jpc_enc_prc_t *prc)
 {
   jpc_enc_cblk_t *cblk;
-  uint_fast32_t cblkno;
+  int_fast32_t cblkno;
 
   if (prc->cblks) {
     for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
@@ -2503,6 +2500,8 @@ static jpc_enc_cblk_t *cblk_create(jpc_enc_cblk_t *cblk, jpc_enc_cp_t *cp, jpc_e
   uint_fast32_t cblkno;
   uint_fast32_t tlcblktlx;
   uint_fast32_t tlcblktly;
+  /* unused:*/
+  (void)cp;
 
   cblkno = cblk - prc->cblks;
   cblkxind = cblkno % prc->numhcblks;
@@ -2550,7 +2549,7 @@ error:
 
 static void cblk_destroy(jpc_enc_cblk_t *cblk)
 {
-  uint_fast16_t passno;
+  int_fast16_t passno;
   jpc_enc_pass_t *pass;
   if (cblk->passes) {
     for (passno = 0, pass = cblk->passes; passno < cblk->numpasses;
@@ -2576,6 +2575,7 @@ static void cblk_destroy(jpc_enc_cblk_t *cblk)
 static void pass_destroy(jpc_enc_pass_t *pass)
 {
   /* XXX - need to free resources here */
+  (void)pass;
 }
 
 void jpc_enc_dump(jpc_enc_t *enc)
@@ -2586,11 +2586,11 @@ void jpc_enc_dump(jpc_enc_t *enc)
   jpc_enc_band_t *band;
   jpc_enc_prc_t *prc;
   jpc_enc_cblk_t *cblk;
-  uint_fast16_t cmptno;
-  uint_fast16_t rlvlno;
-  uint_fast16_t bandno;
-  uint_fast32_t prcno;
-  uint_fast32_t cblkno;
+  int_fast16_t cmptno;
+  int_fast16_t rlvlno;
+  int_fast16_t bandno;
+  int_fast32_t prcno;
+  int_fast32_t cblkno;
 
   tile = enc->curtile;