*/
 
 /*
- * $Id: jpc_enc.c,v 1.1 2005/05/22 18:33:04 malaterre Exp $
+ * $Id: jpc_enc.c,v 1.2 2005/06/07 19:22:42 malaterre Exp $
  */
 
 /******************************************************************************\
 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);
 * Code.
 \******************************************************************************/
 
+#if 0
 static int jpc_calcssmant(jpc_fix_t stepsize)
 {
   int n;
 {
   return jpc_firstone(stepsize) - JPC_FIX_FRACBITS;
 }
+#endif
 
 static int jpc_enc_encodemainhdr(jpc_enc_t *enc)
 {
   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;
 
       /* 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) {
   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;
 
 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 <
   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;
 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;
   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. */
     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);
 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;
   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;
 {
   jpc_enc_prc_t *prc;
   jpc_enc_rlvl_t *rlvl;
-  uint_fast32_t prcno;
+  int_fast32_t prcno;
 
   if (band->prcs) {
     rlvl = band->rlvl;
   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;
 
     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) {
 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;
   uint_fast32_t cblkno;
   uint_fast32_t tlcblktlx;
   uint_fast32_t tlcblktly;
+  // unused:
+  (void)cp;
 
   cblkno = cblk - prc->cblks;
   cblkxind = cblkno % prc->numhcblks;
 
 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;
 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)
   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;