Update of /cvsroot/vba/VisualBoyAdvance/win32/dependencies/libjasper/jpc In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv20508/win32/dependencies/libjasper/jpc Added Files: jpc_bs.c jpc_bs.h jpc_cod.h jpc_cs.c jpc_cs.h jpc_dec.c jpc_dec.h jpc_enc.c jpc_enc.h jpc_fix.h jpc_flt.h jpc_math.c jpc_math.h jpc_mct.c jpc_mct.h jpc_mqcod.c jpc_mqcod.h jpc_mqdec.c jpc_mqdec.h jpc_mqenc.c jpc_mqenc.h jpc_qmfb.c jpc_qmfb.h jpc_t1cod.c jpc_t1cod.h jpc_t1dec.c jpc_t1dec.h jpc_t1enc.c jpc_t1enc.h jpc_t2cod.c jpc_t2cod.h jpc_t2dec.c jpc_t2dec.h jpc_t2enc.c jpc_t2enc.h jpc_tagtree.c jpc_tagtree.h jpc_tsfb.c jpc_tsfb.h jpc_util.c jpc_util.h Log Message: --- NEW FILE: jpc_qmfb.h --- /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. * Copyright (c) 2001-2002 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * Copyright (c) 2001-2003 Michael David Adams * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the * following conditions: * * 1. The above copyright notices and this permission notice (which * includes the disclaimer below) shall be included in all copies or * substantial portions of the Software. * * 2. The name of a copyright holder shall not be used to endorse or * promote products derived from the Software without specific prior * written permission. * * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. * * __END_OF_JASPER_LICENSE__ */ /* * Quadrature Mirror-Image Filter Bank (QMFB) Routines * * $Id: jpc_qmfb.h,v 1.1 2006/05/12 21:26:38 spacy51 Exp $ */ #ifndef JPC_QMFB_H #define JPC_QMFB_H /******************************************************************************\ * Includes. \******************************************************************************/ #include "jasper/jas_seq.h" /******************************************************************************\ * Constants. \******************************************************************************/ /* The maximum number of channels for a QMF bank. */ #define JPC_QMFB1D_MAXCHANS 2 /* Select reversible integer-to-integer mode. */ #define JPC_QMFB1D_RITIMODE 1 /* Vertical filtering. */ #define JPC_QMFB1D_VERT 0x10000 /* QMFB IDs. */ #define JPC_QMFB1D_FT 1 /* 5/3 */ #define JPC_QMFB1D_NS 2 /* 9/7 */ /******************************************************************************\ * Types. \******************************************************************************/ /* Forward declaration. */ struct jpc_qmfb1dops_s; /* Band information. */ typedef struct { /* The starting index for the band in the downsampled domain. */ int start; /* The ending index for the band in the downsampled domain. */ int end; /* The location of the start of the band. */ int locstart; /* The location of the end of the band. */ int locend; } jpc_qmfb1dband_t; /* QMF bank */ typedef struct { /* The operations for this QMFB. */ struct jpc_qmfb1dops_s *ops; } jpc_qmfb1d_t; /* QMFB operations. */ typedef struct jpc_qmfb1dops_s { /* The number of channels in the QMFB. */ int (*getnumchans)(jpc_qmfb1d_t *qmfb); /* Get the analysis filters for this QMFB. */ int (*getanalfilters)(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); /* Get the synthesis filters for this QMFB. */ int (*getsynfilters)(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); /* Do analysis. */ void (*analyze)(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); /* Do synthesis. */ void (*synthesize)(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); } jpc_qmfb1dops_t; /******************************************************************************\ * Functions. \******************************************************************************/ /* Create a QMFB from a QMFB ID. */ jpc_qmfb1d_t *jpc_qmfb1d_make(int qmfbid); /* Create a copy of a QMFB. */ jpc_qmfb1d_t *jpc_qmfb1d_copy(jpc_qmfb1d_t *qmfb); /* Destroy a QMFB. */ void jpc_qmfb1d_destroy(jpc_qmfb1d_t *qmfb); /* Get the number of channels for a QMFB. */ int jpc_qmfb1d_getnumchans(jpc_qmfb1d_t *qmfb); /* Get the analysis filters for a QMFB. */ int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); /* Get the synthesis filters for a QMFB. */ int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters); /* Get the bands for a QMFB. */ void jpc_qmfb1d_getbands(jpc_qmfb1d_t *qmfb, int flags, uint_fast32_t xstart, uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, int maxbands, int *numbandsptr, jpc_qmfb1dband_t *bands); /* Perform analysis. */ void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); /* Perform synthesis. */ void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x); #endif --- NEW FILE: jpc_enc.c --- /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. * Copyright (c) 2001-2003 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * Copyright (c) 2001-2003 Michael David Adams * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") obtaining a copy of this software and associated documentation [...2584 lines suppressed...] ++bandno, ++band) { if (!band->data) { continue; } fprintf(stderr, " band %5d %5d %5d %5d\n", jas_seq2d_xstart(band->data), jas_seq2d_ystart(band->data), jas_seq2d_xend(band->data), jas_seq2d_yend(band->data)); for (prcno = 0, prc = band->prcs; prcno < rlvl->numprcs; ++prcno, ++prc) { fprintf(stderr, " prc %5d %5d %5d %5d (%5d %5d)\n", prc->tlx, prc->tly, prc->brx, prc->bry, prc->brx - prc->tlx, prc->bry - prc->tly); if (!prc->cblks) { continue; } for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks; ++cblkno, ++cblk) { fprintf(stderr, " cblk %5d %5d %5d %5d\n", jas_seq2d_xstart(cblk->data), jas_seq2d_ystart(cblk->data), jas_seq2d_xend(cblk->data), jas_seq2d_yend(cblk->data)); } } } } } } --- NEW FILE: jpc_qmfb.c --- /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. * Copyright (c) 2001-2003 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * Copyright (c) 2001-2003 Michael David Adams * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") obtaining a copy of this software and associated documentation [...1083 lines suppressed...] int jpc_qmfb1d_getanalfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters) { return (*qmfb->ops->getanalfilters)(qmfb, len, filters); } int jpc_qmfb1d_getsynfilters(jpc_qmfb1d_t *qmfb, int len, jas_seq2d_t **filters) { return (*qmfb->ops->getsynfilters)(qmfb, len, filters); } void jpc_qmfb1d_analyze(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x) { (*qmfb->ops->analyze)(qmfb, flags, x); } void jpc_qmfb1d_synthesize(jpc_qmfb1d_t *qmfb, int flags, jas_seq2d_t *x) { (*qmfb->ops->synthesize)(qmfb, flags, x); } --- NEW FILE: jpc_cs.c --- /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. * Copyright (c) 2001-2002 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * Copyright (c) 2001-2003 Michael David Adams * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") obtaining a copy of this software and associated documentation [...1606 lines suppressed...] } } if (n < 2) { return -1; } if (buf[0] == (JPC_MS_SOC >> 8) && buf[1] == (JPC_MS_SOC & 0xff)) { return 0; } return -1; } int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long len) { return jas_stream_copy(out, in, len); } int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long len) { return jas_stream_copy(out, in, len); } --- NEW FILE: jpc_enc.h --- /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. * Copyright (c) 2001-2002 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * Copyright (c) 2001-2003 Michael David Adams * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the * following conditions: * * 1. The above copyright notices and this permission notice (which * includes the disclaimer below) shall be included in all copies or * substantial portions of the Software. * * 2. The name of a copyright holder shall not be used to endorse or * promote products derived from the Software without specific prior * written permission. * * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. * * __END_OF_JASPER_LICENSE__ */ /* * $Id: jpc_enc.h,v 1.1 2006/05/12 21:26:38 spacy51 Exp $ */ #ifndef JPC_ENC_H #define JPC_ENC_H /******************************************************************************\ * Includes. \******************************************************************************/ #include "jasper/jas_seq.h" #include "jpc_t2cod.h" #include "jpc_mqenc.h" #include "jpc_cod.h" #include "jpc_tagtree.h" #include "jpc_cs.h" #include "jpc_flt.h" #include "jpc_tsfb.h" /******************************************************************************\ * Constants. \******************************************************************************/ /* The number of bits used in various lookup tables. */ #define JPC_NUMEXTRABITS JPC_NMSEDEC_FRACBITS /* An invalid R-D slope value. */ #define JPC_BADRDSLOPE (-1) /******************************************************************************\ * Coding parameters types. \******************************************************************************/ /* Per-component coding paramters. */ typedef struct { /* The horizontal sampling period. */ uint_fast8_t sampgrdstepx; /* The vertical sampling period. */ uint_fast8_t sampgrdstepy; /* The sample alignment horizontal offset. */ uint_fast8_t sampgrdsubstepx; /* The sample alignment vertical offset. */ uint_fast8_t sampgrdsubstepy; /* The precision of the samples. */ uint_fast8_t prec; /* The signedness of the samples. */ bool sgnd; /* The number of step sizes. */ uint_fast16_t numstepsizes; /* The quantizer step sizes. */ uint_fast16_t stepsizes[JPC_MAXBANDS]; } jpc_enc_ccp_t; /* Per-tile coding parameters. */ typedef struct { /* The coding mode. */ bool intmode; /* The coding style (i.e., SOP, EPH). */ uint_fast8_t csty; /* The progression order. */ uint_fast8_t prg; /* The multicomponent transform. */ uint_fast8_t mctid; /* The number of layers. */ uint_fast16_t numlyrs; /* The normalized bit rates associated with the various intermediate layers. */ jpc_fix_t *ilyrrates; } jpc_enc_tcp_t; /* Per tile-component coding parameters. */ typedef struct { /* The coding style (i.e., explicit precinct sizes). */ uint_fast8_t csty; /* The maximum number of resolution levels allowed. */ uint_fast8_t maxrlvls; /* The exponent for the nominal code block width. */ uint_fast16_t cblkwidthexpn; /* The exponent for the nominal code block height. */ uint_fast16_t cblkheightexpn; /* The code block style parameters (e.g., lazy, terminate all, segmentation symbols, causal, reset probability models). */ uint_fast8_t cblksty; /* The QMFB. */ uint_fast8_t qmfbid; /* The precinct width values. */ uint_fast16_t prcwidthexpns[JPC_MAXRLVLS]; /* The precinct height values. */ uint_fast16_t prcheightexpns[JPC_MAXRLVLS]; /* The number of guard bits. */ uint_fast8_t numgbits; } jpc_enc_tccp_t; /* Coding parameters. */ typedef struct { /* The debug level. */ int debug; /* The horizontal offset from the origin of the reference grid to the left edge of the image area. */ uint_fast32_t imgareatlx; /* The vertical offset from the origin of the reference grid to the top edge of the image area. */ uint_fast32_t imgareatly; /* The horizontal offset from the origin of the reference grid to the right edge of the image area (plus one). */ uint_fast32_t refgrdwidth; /* The vertical offset from the origin of the reference grid to the bottom edge of the image area (plus one). */ uint_fast32_t refgrdheight; /* The horizontal offset from the origin of the tile grid to the origin of the reference grid. */ uint_fast32_t tilegrdoffx; /* The vertical offset from the origin of the tile grid to the origin of the reference grid. */ uint_fast32_t tilegrdoffy; /* The nominal tile width in units of the image reference grid. */ uint_fast32_t tilewidth; /* The nominal tile height in units of the image reference grid. */ uint_fast32_t tileheight; /* The number of tiles spanning the image area in the horizontal direction. */ uint_fast32_t numhtiles; /* The number of tiles spanning the image area in the vertical direction. */ uint_fast32_t numvtiles; /* The number of tiles. */ uint_fast32_t numtiles; /* The number of components. */ uint_fast16_t numcmpts; /* The per-component coding parameters. */ jpc_enc_ccp_t *ccps; /* The per-tile coding parameters. */ jpc_enc_tcp_t tcp; /* The per-tile-component coding parameters. */ jpc_enc_tccp_t tccp; /* The target code stream length in bytes. */ uint_fast32_t totalsize; /* The raw (i.e., uncompressed) size of the image in bytes. */ uint_fast32_t rawsize; } jpc_enc_cp_t; /******************************************************************************\ * Encoder class. \******************************************************************************/ /* Encoder per-coding-pass state information. */ typedef struct { /* The starting offset for this pass. */ int start; /* The ending offset for this pass. */ int end; /* The type of data in this pass (i.e., MQ or raw). */ int type; /* Flag indicating that this pass is terminated. */ int term; /* The entropy coder state after coding this pass. */ jpc_mqencstate_t mqencstate; /* The layer to which this pass has been assigned. */ int lyrno; /* The R-D slope for this pass. */ jpc_flt_t rdslope; /* The weighted MSE reduction associated with this pass. */ jpc_flt_t wmsedec; /* The cumulative weighted MSE reduction. */ jpc_flt_t cumwmsedec; /* The normalized MSE reduction. */ long nmsedec; } jpc_enc_pass_t; /* Encoder per-code-block state information. */ typedef struct { /* The number of passes. */ int numpasses; /* The per-pass information. */ jpc_enc_pass_t *passes; /* The number of passes encoded so far. */ int numencpasses; /* The number of insignificant MSBs. */ int numimsbs; /* The number of bits used to encode pass data lengths. */ int numlenbits; /* The byte stream for this code block. */ jas_stream_t *stream; /* The entropy encoder. */ jpc_mqenc_t *mqenc; /* The data for this code block. */ jas_matrix_t *data; /* The state for this code block. */ jas_matrix_t *flags; /* The number of bit planes required for this code block. */ int numbps; /* The next pass to be encoded. */ jpc_enc_pass_t *curpass; /* The per-code-block-group state information. */ struct jpc_enc_prc_s *prc; /* The saved current pass. */ /* This is used by the rate control code. */ jpc_enc_pass_t *savedcurpass; /* The saved length indicator size. */ /* This is used by the rate control code. */ int savednumlenbits; /* The saved number of encoded passes. */ /* This is used by the rate control code. */ int savednumencpasses; } jpc_enc_cblk_t; /* Encoder per-code-block-group state information. */ typedef struct jpc_enc_prc_s { /* The x-coordinate of the top-left corner of the precinct. */ uint_fast32_t tlx; /* The y-coordinate of the top-left corner of the precinct. */ uint_fast32_t tly; /* The x-coordinate of the bottom-right corner of the precinct (plus one). */ uint_fast32_t brx; /* The y-coordinate of the bottom-right corner of the precinct (plus one). */ uint_fast32_t bry; /* The number of code blocks spanning the precinct in the horizontal direction. */ int numhcblks; /* The number of code blocks spanning the precinct in the vertical direction. */ int numvcblks; /* The total number of code blocks. */ int numcblks; /* The per-code-block information. */ jpc_enc_cblk_t *cblks; /* The inclusion tag tree. */ jpc_tagtree_t *incltree; /* The insignifcant MSBs tag tree. */ jpc_tagtree_t *nlibtree; /* The per-band information. */ struct jpc_enc_band_s *band; /* The saved inclusion tag tree. */ /* This is used by rate control. */ jpc_tagtree_t *savincltree; /* The saved leading-insignificant-bit-planes tag tree. */ /* This is used by rate control. */ jpc_tagtree_t *savnlibtree; } jpc_enc_prc_t; /* Encoder per-band state information. */ typedef struct jpc_enc_band_s { /* The per precinct information. */ jpc_enc_prc_t *prcs; /* The coefficient data for this band. */ jas_matrix_t *data; /* The orientation of this band (i.e., LL, LH, HL, or HH). */ int orient; /* The number of bit planes associated with this band. */ int numbps; /* The quantizer step size. */ jpc_fix_t absstepsize; /* The encoded quantizer step size. */ int stepsize; /* The L2 norm of the synthesis basis functions associated with this band. (The MCT is not considered in this value.) */ jpc_fix_t synweight; /* The analysis gain for this band. */ int analgain; /* The per-resolution-level information. */ struct jpc_enc_rlvl_s *rlvl; } jpc_enc_band_t; /* Encoder per-resolution-level state information. */ typedef struct jpc_enc_rlvl_s { /* The x-coordinate of the top-left corner of the tile-component at this resolution. */ uint_fast32_t tlx; /* The y-coordinate of the top-left corner of the tile-component at this resolution. */ uint_fast32_t tly; /* The x-coordinate of the bottom-right corner of the tile-component at this resolution (plus one). */ uint_fast32_t brx; /* The y-coordinate of the bottom-right corner of the tile-component at this resolution (plus one). */ uint_fast32_t bry; /* The exponent value for the nominal precinct width measured relative to the associated LL band. */ int prcwidthexpn; /* The exponent value for the nominal precinct height measured relative to the associated LL band. */ int prcheightexpn; /* The number of precincts spanning the resolution level in the horizontal direction. */ int numhprcs; /* The number of precincts spanning the resolution level in the vertical direction. */ int numvprcs; /* The total number of precincts. */ int numprcs; /* The exponent value for the nominal code block group width. This quantity is associated with the next lower resolution level (assuming that there is one). */ int cbgwidthexpn; /* The exponent value for the nominal code block group height. This quantity is associated with the next lower resolution level (assuming that there is one). */ int cbgheightexpn; /* The exponent value for the code block width. */ uint_fast16_t cblkwidthexpn; /* The exponent value for the code block height. */ uint_fast16_t cblkheightexpn; /* The number of bands associated with this resolution level. */ int numbands; /* The per-band information. */ jpc_enc_band_t *bands; /* The parent tile-component. */ struct jpc_enc_tcmpt_s *tcmpt; } jpc_enc_rlvl_t; /* Encoder per-tile-component state information. */ typedef struct jpc_enc_tcmpt_s { /* The number of resolution levels. */ int numrlvls; /* The per-resolution-level information. */ jpc_enc_rlvl_t *rlvls; /* The tile-component data. */ jas_matrix_t *data; /* The QMFB. */ int qmfbid; /* The number of bands. */ int numbands; /* The TSFB. */ jpc_tsfb_t *tsfb; /* The synthesis energy weight (for the MCT). */ jpc_fix_t synweight; /* The precinct width exponents. */ int prcwidthexpns[JPC_MAXRLVLS]; /* The precinct height exponents. */ int prcheightexpns[JPC_MAXRLVLS]; /* The code block width exponent. */ int cblkwidthexpn; /* The code block height exponent. */ int cblkheightexpn; /* Coding style (i.e., explicit precinct sizes). */ int csty; /* Code block style. */ int cblksty; /* The number of quantizer step sizes. */ int numstepsizes; /* The encoded quantizer step sizes. */ uint_fast16_t stepsizes[JPC_MAXBANDS]; /* The parent tile. */ struct jpc_enc_tile_s *tile; } jpc_enc_tcmpt_t; /* Encoder per-tile state information. */ typedef struct jpc_enc_tile_s { /* The tile number. */ uint_fast32_t tileno; /* The x-coordinate of the top-left corner of the tile measured with respect to the reference grid. */ uint_fast32_t tlx; /* The y-coordinate of the top-left corner of the tile measured with respect to the reference grid. */ uint_fast32_t tly; /* The x-coordinate of the bottom-right corner of the tile measured with respect to the reference grid (plus one). */ uint_fast32_t brx; /* The y-coordinate of the bottom-right corner of the tile measured with respect to the reference grid (plus one). */ uint_fast32_t bry; /* The coding style. */ uint_fast8_t csty; /* The progression order. */ uint_fast8_t prg; /* The number of layers. */ int numlyrs; /* The MCT to employ (if any). */ uint_fast8_t mctid; /* The packet iterator (used to determine the order of packet generation). */ jpc_pi_t *pi; /* The coding mode (i.e., integer or real). */ bool intmode; /* The number of bytes to allocate to the various layers. */ uint_fast32_t *lyrsizes; /* The number of tile-components. */ int numtcmpts; /* The per tile-component information. */ jpc_enc_tcmpt_t *tcmpts; /* The raw (i.e., uncompressed) size of this tile. */ uint_fast32_t rawsize; } jpc_enc_tile_t; /* Encoder class. */ typedef struct jpc_enc_s { /* The image being encoded. */ jas_image_t *image; /* The output stream. */ jas_stream_t *out; /* The coding parameters. */ jpc_enc_cp_t *cp; /* The tile currently being processed. */ jpc_enc_tile_t *curtile; /* The code stream state. */ jpc_cstate_t *cstate; /* The number of bytes output so far. */ uint_fast32_t len; /* The number of bytes available for the main body of the code stream. */ /* This is used for rate allocation purposes. */ uint_fast32_t mainbodysize; /* The marker segment currently being processed. */ /* This member is a convenience for making cleanup easier. */ jpc_ms_t *mrk; /* The stream used to temporarily hold tile-part data. */ jas_stream_t *tmpstream; } jpc_enc_t; #endif --- NEW FILE: jpc_util.h --- /* * Copyright (c) 2001-2002 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * Copyright (c) 2001-2003 Michael David Adams * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the * following conditions: * * 1. The above copyright notices and this permission notice (which * includes the disclaimer below) shall be included in all copies or * substantial portions of the Software. * * 2. The name of a copyright holder shall not be used to endorse or * promote products derived from the Software without specific prior * written permission. * * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. * * __END_OF_JASPER_LICENSE__ */ #ifndef JPC_UTIL_H #define JPC_UTIL_H /* Parse a comma separated list of real numbers into an array of doubles. */ int jpc_atoaf(char *s, int *numvalues, double **values); /* Upsample a sequence. */ jas_seq_t *jpc_seq_upsample(jas_seq_t *seq, int n); /* Convolve two sequences. */ jas_seq_t *jpc_seq_conv(jas_seq_t *seq0, jas_seq_t *seq1); /* Compute the norm of a sequence. */ jpc_fix_t jpc_seq_norm(jas_seq_t *x); #endif --- NEW FILE: jpc_tsfb.h --- /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. * Copyright (c) 2001-2002 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * Copyright (c) 2001-2003 Michael David Adams * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the * following conditions: * * 1. The above copyright notices and this permission notice (which * includes the disclaimer below) shall be included in all copies or * substantial portions of the Software. * * 2. The name of a copyright holder shall not be used to endorse or * promote products derived from the Software without specific prior * written permission. * * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. * * __END_OF_JASPER_LICENSE__ */ /* * Tree-Structured Filter Bank (TSFB) Library * * $Id: jpc_tsfb.h,v 1.1 2006/05/12 21:26:38 spacy51 Exp $ */ #ifndef JPC_TSFB_H #define JPC_TSFB_H /******************************************************************************\ * Includes. \******************************************************************************/ #include "jasper/jas_seq.h" #include "jpc_fix.h" #include "jpc_qmfb.h" /******************************************************************************\ * Constants. \******************************************************************************/ #define JPC_TSFB_MAXBANDS (JPC_TSFB_MAXDEPTH * 3 + 1) #define JPC_TSFB_MAXDEPTH 32 #define JPC_TSFB_RITIMODE JPC_QMFB1D_RITIMODE #define JPC_TSFB_MAXBANDSPERNODE (JPC_QMFB1D_MAXCHANS * JPC_QMFB1D_MAXCHANS) #define JPC_TSFB_PRUNEVERT 0x01 #define JPC_TSFB_PRUNEHORZ 0x02 #define JPC_TSFB_LL 0 #define JPC_TSFB_LH 1 #define JPC_TSFB_HL 2 #define JPC_TSFB_HH 3 /******************************************************************************\ * Types. \******************************************************************************/ typedef struct { int xstart; int ystart; int xend; int yend; int locxstart; int locystart; int locxend; int locyend; } jpc_tsfbnodeband_t; typedef struct jpc_tsfbnode_s { int numhchans; int numvchans; jpc_qmfb1d_t *hqmfb; jpc_qmfb1d_t *vqmfb; int maxchildren; int numchildren; struct jpc_tsfbnode_s *children[JPC_TSFB_MAXBANDSPERNODE]; struct jpc_tsfbnode_s *parent; } jpc_tsfbnode_t; typedef struct { jpc_tsfbnode_t *root; } jpc_tsfb_t; typedef struct { int xstart; int ystart; int xend; int yend; int orient; int locxstart; int locystart; int locxend; int locyend; jpc_fix_t synenergywt; } jpc_tsfb_band_t; /******************************************************************************\ * Functions. \******************************************************************************/ /* Create a TSFB. */ jpc_tsfb_t *jpc_cod_gettsfb(int qmfbid, int numlevels); /* Create a wavelet-type TSFB with the specified horizontal and vertical QMFBs. */ jpc_tsfb_t *jpc_tsfb_wavelet(jpc_qmfb1d_t *hqmfb, jpc_qmfb1d_t *vqmfb, int numdlvls); /* Destroy a TSFB. */ void jpc_tsfb_destroy(jpc_tsfb_t *tsfb); /* Perform analysis. */ void jpc_tsfb_analyze(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x); /* Perform synthesis. */ void jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, int flags, jas_seq2d_t *x); /* Get band information for a TSFB. */ int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart, uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend, jpc_tsfb_band_t *bands); #endif --- NEW FILE: jpc_t1dec.c --- /* * Copyright (c) 1999-2000 Image Power, Inc. and the University of * British Columbia. * Copyright (c) 2001-2003 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * Copyright (c) 2001-2003 Michael David Adams * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the * following conditions: * * 1. The above copyright notices and this permission notice (which * includes the disclaimer below) shall be included in all copies or * substantial portions of the Software. * * 2. The name of a copyright holder shall not be used to endorse or * promote products derived from the Software without specific prior * written permission. * * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. * * __END_OF_JASPER_LICENSE__ */ /* * Tier 1 Decoder * * $Id: jpc_t1dec.c,v 1.1 2006/05/12 21:26:38 spacy51 Exp $ */ /******************************************************************************\ * Includes. \******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <assert.h> #include "jasper/jas_fix.h" #include "jasper/jas_stream.h" #include "jasper/jas_math.h" #include "jpc_bs.h" #include "jpc_mqdec.h" #include "jpc_t1dec.h" #include "jpc_t1cod.h" #include "jpc_dec.h" /******************************************************************************\ * \******************************************************************************/ static int jpc_dec_decodecblk(jpc_dec_t *dec, jpc_dec_tile_t *tile, jpc_dec_tcomp_t *tcomp, jpc_dec_band_t *band, jpc_dec_cblk_t *cblk, int dopartial, int maxlyrs); static int dec_sigpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int orient, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data); static int dec_rawsigpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data); static int dec_refpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data); static int dec_rawrefpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data); static int dec_clnpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int orient, int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data); #if defined(DEBUG) static long t1dec_cnt = 0; #endif #if !defined(DEBUG) #define JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) \ ((v) = jpc_mqdec_getbit(mqdec)) #else #define JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) \ { \ (v) = jpc_mqdec_getbit(mqdec); \ if (jas_getdbglevel() >= 100) { \ fprintf(stderr, "index = %ld; passtype = %s; symtype = %s; sym = %d\n", t1dec_cnt, passtypename, symtypename, v); \ ++t1dec_cnt; \ } \ } #endif #define JPC_T1D_GETBITNOSKEW(mqdec, v, passtypename, symtypename) \ JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) #if !defined(DEBUG) #define JPC_T1D_RAWGETBIT(bitstream, v, passtypename, symtypename) \ ((v) = jpc_bitstream_getbit(bitstream)) #else #define JPC_T1D_RAWGETBIT(bitstream, v, passtypename, symtypename) \ { \ (v) = jpc_bitstream_getbit(bitstream); \ if (jas_getdbglevel() >= 100) { \ fprintf(stderr, "index = %ld; passtype = %s; symtype = %s; sym = %d\n", t1dec_cnt, passtypename, symtypename, v); \ ++t1dec_cnt; \ } \ } #endif /******************************************************************************\ * Code. \******************************************************************************/ int jpc_dec_decodecblks(jpc_dec_t *dec, jpc_dec_tile_t *tile) { jpc_dec_tcomp_t *tcomp; int compcnt; jpc_dec_rlvl_t *rlvl; int rlvlcnt; jpc_dec_band_t *band; int bandcnt; jpc_dec_prc_t *prc; int prccnt; jpc_dec_cblk_t *cblk; int cblkcnt; for (compcnt = dec->numcomps, tcomp = tile->tcomps; compcnt > 0; --compcnt, ++tcomp) { for (rlvlcnt = tcomp->numrlvls, rlvl = tcomp->rlvls; rlvlcnt > 0; --rlvlcnt, ++rlvl) { if (!rlvl->bands) { continue; } for (bandcnt = rlvl->numbands, band = rlvl->bands; bandcnt > 0; --bandcnt, ++band) { if (!band->data) { continue; } for (prccnt = rlvl->numprcs, prc = band->prcs; prccnt > 0; --prccnt, ++prc) { if (!prc->cblks) { continue; } for (cblkcnt = prc->numcblks, cblk = prc->cblks; cblkcnt > 0; --cblkcnt, ++cblk) { if (jpc_dec_decodecblk(dec, tile, tcomp, band, cblk, 1, JPC_MAXLYRS)) { return -1; } } } } } } return 0; } static int jpc_dec_decodecblk(jpc_dec_t *dec, jpc_dec_tile_t *tile, jpc_dec_tcomp_t *tcomp, jpc_dec_band_t *band, jpc_dec_cblk_t *cblk, int dopartial, int maxlyrs) { jpc_dec_seg_t *seg; int i; int bpno; int passtype; int ret; int compno; int filldata; int fillmask; jpc_dec_ccp_t *ccp; compno = tcomp - tile->tcomps; if (!cblk->flags) { /* Note: matrix is assumed to be zeroed */ if (!(cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) + 2, jas_matrix_numcols(cblk->data) + 2))) { return -1; } } seg = cblk->segs.head; while (seg && (seg != cblk->curseg || dopartial) && (maxlyrs < 0 || seg->lyrno < maxlyrs)) { assert(seg->numpasses >= seg->maxpasses || dopartial); assert(seg->stream); jas_stream_rewind(seg->stream); jas_stream_setrwcount(seg->stream, 0); if (seg->type == JPC_SEG_MQ) { if (!cblk->mqdec) { if (!(cblk->mqdec = jpc_mqdec_create(JPC_NUMCTXS, 0))) { return -1; } jpc_mqdec_setctxs(cblk->mqdec, JPC_NUMCTXS, jpc_mqctxs); } jpc_mqdec_setinput(cblk->mqdec, seg->stream); jpc_mqdec_init(cblk->mqdec); } else { assert(seg->type == JPC_SEG_RAW); if (!cblk->nulldec) { if (!(cblk->nulldec = jpc_bitstream_sopen(seg->stream, "r"))) { assert(0); } } } for (i = 0; i < seg->numpasses; ++i) { if (cblk->numimsbs > band->numbps) { ccp = &tile->cp->ccps[compno]; if (ccp->roishift <= 0) { fprintf(stderr, "warning: corrupt code stream\n"); } else { if (cblk->numimsbs < ccp->roishift - band->numbps) { fprintf(stderr, "warning: corrupt code stream\n"); } } } bpno = band->roishift + band->numbps - 1 - (cblk->numimsbs + (seg->passno + i - cblk->firstpassno + 2) / 3); if (bpno < 0) { goto premature_exit; } #if 1 passtype = (seg->passno + i + 2) % 3; #else passtype = JPC_PASSTYPE(seg->passno + i + 2); #endif assert(bpno >= 0 && bpno < 31); switch (passtype) { case JPC_SIGPASS: ret = (seg->type == JPC_SEG_MQ) ? dec_sigpass(dec, cblk->mqdec, bpno, band->orient, (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, cblk->flags, cblk->data) : dec_rawsigpass(dec, cblk->nulldec, bpno, (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, cblk->flags, cblk->data); break; case JPC_REFPASS: ret = (seg->type == JPC_SEG_MQ) ? dec_refpass(dec, cblk->mqdec, bpno, (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, cblk->flags, cblk->data) : dec_rawrefpass(dec, cblk->nulldec, bpno, (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, cblk->flags, cblk->data); break; case JPC_CLNPASS: assert(seg->type == JPC_SEG_MQ); ret = dec_clnpass(dec, cblk->mqdec, bpno, band->orient, (tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0, (tile->cp->ccps[compno].cblkctx & JPC_COX_SEGSYM) != 0, cblk->flags, cblk->data); break; default: ret = -1; break; } /* Do we need to reset after each coding pass? */ if (tile->cp->ccps[compno].cblkctx & JPC_COX_RESET) { jpc_mqdec_setctxs(cblk->mqdec, JPC_NUMCTXS, jpc_mqctxs); } if (ret) { fprintf(stderr, "coding pass failed passtype=%d segtype=%d\n", passtype, seg->type); return -1; } } if (seg->type == JPC_SEG_MQ) { /* Note: dont destroy mq decoder because context info will be lost */ } else { assert(seg->type == JPC_SEG_RAW); if (tile->cp->ccps[compno].cblkctx & JPC_COX_PTERM) { fillmask = 0x7f; filldata = 0x2a; } else { fillmask = 0; filldata = 0; } if ((ret = jpc_bitstream_inalign(cblk->nulldec, fillmask, filldata)) < 0) { return -1; } else if (ret > 0) { fprintf(stderr, "warning: bad termination pattern detected\n"); } jpc_bitstream_close(cblk->nulldec); cblk->nulldec = 0; } cblk->curseg = seg->next; jpc_seglist_remove(&cblk->segs, seg); jpc_seg_destroy(seg); seg = cblk->curseg; } assert(dopartial ? (!cblk->curseg) : 1); premature_exit: return 0; } /******************************************************************************\ * Code for significance pass. \******************************************************************************/ #define jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, orient, mqdec, vcausalflag) \ { \ int f; \ int v; \ f = *(fp); \ if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ jpc_mqdec_setcurctx((mqdec), JPC_GETZCCTXNO(f, (orient))); \ JPC_T1D_GETBIT((mqdec), v, "SIG", "ZC"); \ if (v) { \ jpc_mqdec_setcurctx((mqdec), JPC_GETSCCTXNO(f)); \ JPC_T1D_GETBIT((mqdec), v, "SIG", "SC"); \ v ^= JPC_GETSPB(f); \ JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \ *(fp) |= JPC_SIG; \ *(dp) = (v) ? (-(oneplushalf)) : (oneplushalf); \ } \ *(fp) |= JPC_VISIT; \ } \ } static int dec_sigpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int orient, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data) { int i; int j; int one; int half; int oneplushalf; int vscanlen; int width; int height; jpc_fix_t *fp; int frowstep; int fstripestep; jpc_fix_t *fstripestart; jpc_fix_t *fvscanstart; jpc_fix_t *dp; int drowstep; int dstripestep; jpc_fix_t *dstripestart; jpc_fix_t *dvscanstart; int k; /* Avoid compiler warning about unused parameters. */ dec = 0; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; one = 1 << bitpos; half = one >> 1; oneplushalf = one | half; fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; dp = dvscanstart; k = vscanlen; /* Process first sample in vertical scan. */ jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, orient, mqdec, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process second sample in vertical scan. */ jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, orient, mqdec, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process third sample in vertical scan. */ jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, orient, mqdec, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process fourth sample in vertical scan. */ jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, orient, mqdec, 0); } } return 0; } #define jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, in, vcausalflag) \ { \ jpc_fix_t f = *(fp); \ jpc_fix_t v; \ if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \ JPC_T1D_RAWGETBIT(in, v, "SIG", "ZC"); \ if (v < 0) { \ return -1; \ } \ if (v) { \ JPC_T1D_RAWGETBIT(in, v, "SIG", "SC"); \ if (v < 0) { \ return -1; \ } \ JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \ *(fp) |= JPC_SIG; \ *(dp) = v ? (-oneplushalf) : (oneplushalf); \ } \ *(fp) |= JPC_VISIT; \ } \ } static int dec_rawsigpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data) { int i; int j; int k; int one; int half; int oneplushalf; int vscanlen; int width; int height; jpc_fix_t *fp; int frowstep; int fstripestep; jpc_fix_t *fstripestart; jpc_fix_t *fvscanstart; jpc_fix_t *dp; int drowstep; int dstripestep; jpc_fix_t *dstripestart; jpc_fix_t *dvscanstart; /* Avoid compiler warning about unused parameters. */ dec = 0; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; one = 1 << bitpos; half = one >> 1; oneplushalf = one | half; fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; dp = dvscanstart; k = vscanlen; /* Process first sample in vertical scan. */ jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, in, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process second sample in vertical scan. */ jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, in, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process third sample in vertical scan. */ jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, in, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process fourth sample in vertical scan. */ jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, in, 0); } } return 0; } /******************************************************************************\ * Code for refinement pass. \******************************************************************************/ #define jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, vcausalflag) \ { \ int v; \ int t; \ if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ jpc_mqdec_setcurctx((mqdec), JPC_GETMAGCTXNO(*(fp))); \ JPC_T1D_GETBITNOSKEW((mqdec), v, "REF", "MR"); \ t = (v ? (poshalf) : (neghalf)); \ *(dp) += (*(dp) < 0) ? (-t) : t; \ *(fp) |= JPC_REFINE; \ } \ } static int dec_refpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data) { int i; int j; int vscanlen; int width; int height; int one; int poshalf; int neghalf; jpc_fix_t *fp; int frowstep; int fstripestep; jpc_fix_t *fstripestart; jpc_fix_t *fvscanstart; jpc_fix_t *dp; int drowstep; int dstripestep; jpc_fix_t *dstripestart; jpc_fix_t *dvscanstart; int k; /* Avoid compiler warning about unused parameters. */ dec = 0; vcausalflag = 0; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; one = 1 << bitpos; poshalf = one >> 1; neghalf = (bitpos > 0) ? (-poshalf) : (-1); fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; dp = dvscanstart; k = vscanlen; /* Process first sample in vertical scan. */ jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process second sample in vertical scan. */ jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process third sample in vertical scan. */ jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process fourth sample in vertical scan. */ jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0); } } return 0; } #define jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, vcausalflag) \ { \ jpc_fix_t v; \ jpc_fix_t t; \ if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \ JPC_T1D_RAWGETBIT(in, v, "REF", "MAGREF"); \ if (v < 0) { \ return -1; \ } \ t = (v ? poshalf : neghalf); \ *(dp) += (*(dp) < 0) ? (-t) : t; \ *(fp) |= JPC_REFINE; \ } \ } static int dec_rawrefpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data) { int i; int j; int k; int vscanlen; int width; int height; int one; int poshalf; int neghalf; jpc_fix_t *fp; int frowstep; int fstripestep; jpc_fix_t *fstripestart; jpc_fix_t *fvscanstart; jpc_fix_t *dp; int drowstep; int dstripestep; jpc_fix_t *dstripestart; jpc_fix_t *dvscanstart; /* Avoid compiler warning about unused parameters. */ dec = 0; vcausalflag = 0; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; one = 1 << bitpos; poshalf = one >> 1; neghalf = (bitpos > 0) ? (-poshalf) : (-1); fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = height; i > 0; i -= 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(i, 4); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; dp = dvscanstart; k = vscanlen; /* Process first sample in vertical scan. */ jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, vcausalflag); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process second sample in vertical scan. */ jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process third sample in vertical scan. */ jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0); if (--k <= 0) { continue; } fp += frowstep; dp += drowstep; /* Process fourth sample in vertical scan. */ jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0); } } return 0; } /******************************************************************************\ * Code for cleanup pass. \******************************************************************************/ #define jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient, mqdec, flabel, plabel, vcausalflag) \ { \ int v; \ flabel \ if (!((f) & (JPC_SIG | JPC_VISIT))) { \ jpc_mqdec_setcurctx((mqdec), JPC_GETZCCTXNO((f), (orient))); \ JPC_T1D_GETBIT((mqdec), v, "CLN", "ZC"); \ if (v) { \ plabel \ /* Coefficient is significant. */ \ jpc_mqdec_setcurctx((mqdec), JPC_GETSCCTXNO(f)); \ JPC_T1D_GETBIT((mqdec), v, "CLN", "SC"); \ v ^= JPC_GETSPB(f); \ *(dp) = (v) ? (-(oneplushalf)) : (oneplushalf); \ JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \ *(fp) |= JPC_SIG; \ } \ } \ /* XXX - Is this correct? Can aggregation cause some VISIT bits not to be reset? Check. */ \ *(fp) &= ~JPC_VISIT; \ } static int dec_clnpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int orient, int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data) { int i; int j; int k; int vscanlen; int v; int half; int runlen; int f; int width; int height; int one; int oneplushalf; jpc_fix_t *fp; int frowstep; int fstripestep; jpc_fix_t *fstripestart; jpc_fix_t *fvscanstart; jpc_fix_t *dp; int drowstep; int dstripestep; jpc_fix_t *dstripestart; jpc_fix_t *dvscanstart; /* Avoid compiler warning about unused parameters. */ dec = 0; one = 1 << bitpos; half = one >> 1; oneplushalf = one | half; width = jas_matrix_numcols(data); height = jas_matrix_numrows(data); frowstep = jas_matrix_rowstep(flags); drowstep = jas_matrix_rowstep(data); fstripestep = frowstep << 2; dstripestep = drowstep << 2; fstripestart = jas_matrix_getref(flags, 1, 1); dstripestart = jas_matrix_getref(data, 0, 0); for (i = 0; i < height; i += 4, fstripestart += fstripestep, dstripestart += dstripestep) { fvscanstart = fstripestart; dvscanstart = dstripestart; vscanlen = JAS_MIN(4, height - i); for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) { fp = fvscanstart; if (vscanlen >= 4 && (!((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) { jpc_mqdec_setcurctx(mqdec, JPC_AGGCTXNO); JPC_T1D_GETBIT(mqdec, v, "CLN", "AGG"); if (!v) { continue; } jpc_mqdec_setcurctx(mqdec, JPC_UCTXNO); JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "RL"); runlen = v; JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "RL"); runlen = (runlen << 1) | v; f = *(fp = fvscanstart + frowstep * runle... [truncated message content] |