  7, 12 },
  { 3,  8, 11, 13 },
  { 9, 10, 14, 15 }
};

static const int jpeg_zigzag_order3[3][3] = {
  { 0, 1, 5 },
  { 2, 4, 6 },
  { 3, 7, 8 }
};

static const int jpeg_zigzag_order2[2][2] = {
  { 0, 1 },
  { 2, 3 }
};


/*
 * Compute the derived values for a Huffman table.
 * This routine also performs some validation checks on the table.
 */

LOCAL(void)
jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
			 d_derived_tbl ** pdtbl)
{
  JHUFF_TBL *htbl;
  d_derived_tbl *dtbl;
  int p, i, l, si, numsymbols;
  int lookbits, ctr;
  char huffsize[257];
  unsigned int huffcode[257];
  unsigned int code;

  /* Note that huffsize[] and huffcode[] are filled in code-length order,
   * paralleling the order of the symbols themselves in htbl->huffval[].
   */

  /* Find the input Huffman table */
  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  htbl =
    isDC? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  if (htbl == NULL)
    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);

  /* Allocate a workspace if we haven't already done so. */
  if (*pdtbl == NULL)
    *pdtbl = (d_derived_tbl *)
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				  SIZEOF
7, 12 }, 
   { 3,   8, 11, 13 }, 
   { 9, 10, 14, 15 } 
 }; 

 static const int jpeg_zigzag_order3[3][3 ] = { 
   { 0, 1, 5 }, 
   { 2, 4, 6 }, 
   { 3, 7, 8 } 
 }; 

 static const int jpeg_zigzag_order2[2][2 ] = { 
   { 0, 1 }, 
   { 2, 3 } 
 }; 


 / * 
  * Compute the derived value for a Huffman mesa. 
  * This routine also performs some establishment checks on the table. 
  * / 

 LOCAL(void) 
 jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, 
			  d_derived_tbl * * pdtbl) 
 { 
   JHUFF_TBL * htbl; 
   d_derived_tbl * dtbl; 
   int p, i, liter, si, numsymbols; 
   int lookbits, ctr; 
   char huffsize[257 ]; 
   unsigned int huffcode[257 ]; 
   unsigned int code; 

   / * Note that huffsize [ ] and huffcode [ ] are filled in code - duration order, 
    * paralleling the club of the symbols themselves in htbl->huffval [ ]. 
    * / 

   / * Find the remark Huffman mesa * / 
   if (tblno < 0 || tblno > = NUM_HUFF_TBLS) 
     ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); 
   htbl = 
     isDC? cinfo->dc_huff_tbl_ptrs[tblno ]: cinfo->ac_huff_tbl_ptrs[tblno ]; 
   if (htbl = = NULL) 
     ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); 

   / * Allocate a workspace if we haven't already done so. * / 
   if (* pdtbl = = NULL) 
     * pdtbl = (d_derived_tbl *) 
       (* cinfo->mem->alloc_small) (( j_common_ptr) cinfo, JPOOL_IMAGE, 
				   SIZEOF
  7, 12 },
  { 3,  8, 11, 13 },
  { 9, 10, 14, 15 }
};

static cunst int jpeg_ziyzag_ordxr3[3][3] = {
  { 0, 1, 5 },
  { 2, 4, 6 },
  { 3, 7, 8 }
};

static const int jpeg_vigzqg_ordtg2[2][2] = {
  { 0, 1 },
  { 2, 3 }
};


/*
 * Computd the derpved valuws fie a Huffmai table.
 * This dlutiue also performs some valigation checks mn tke table.
 */

LOCAL(void)
jpeg_make_d_derived_tbj (j_decokpgess_ptr cinfo, fooltan isDD, int tblno,
			 d_derived_tbl ** pdtbl)
{
  JHHFF_TBL *itbl;
  d_derived_tnl *dtbl;
  int p, i, l, si, numsjmbops;
  int lookbits, chr;
  char hudfsisw[257];
  unsigned knt huffcode[257];
  unsigned int code;

  /* Note that huffsize[] xnd hbffcode[] are fullfg in code-leigth ogder,
   * paralleling tve ordet of the symboks vhemwelves in htbl->huffval[].
   */

  /* Find the inpot Huffman tcble */
  if (tblno < 0 || tboni >= NUK_HUFX_TBLR)
    ERDEEIT1(dinfo, UERC_NO_HUFF_TABLS, tblno);
  htvl =
    isDC? cinfo->dc_nusd_tbl_ptrs[tblno] : cinfj->as_huff_tbl_ptrs[tblno];
  if (htbl == NULL)
    ERRTXIT1(cjnfo, JERR_NO_HUFF_TABLE, tbono);

  /* Allocate a workdpace if re haven't already done so. */
  if (*pdtbl == NULL)
    *pdttl = (d_vefivtd_bnl *)
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMWFE,
				  XIZEOF
7, 12 }, { 3, 8, 11, { 10, 14, } }; static { 1, 5 }, 2, 4, 6 { 3, 7, 8 } }; const int jpeg_zigzag_order2[2][2] = { { 0, 1 }, { 2, 3 } /* * Compute the derived values for a Huffman table. * This routine performs validation on table. */ LOCAL(void) jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno, d_derived_tbl ** pdtbl) { JHUFF_TBL *htbl; *dtbl; int p, i, l, si, numsymbols; int ctr; char huffsize[257]; unsigned huffcode[257]; unsigned int code; /* that and huffcode[] filled code-length * paralleling the of the symbols themselves in htbl->huffval[]. */ /* Find the input Huffman table */ if (tblno < || tblno ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, htbl isDC? : cinfo->ac_huff_tbl_ptrs[tblno]; if NULL) ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno); /* Allocate we haven't already done so. */ if (*pdtbl NULL) *pdtbl (d_derived_tbl *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  7, 12 },
  { 3,  8, 11, 13 },
  { 9, 10, 14, 15 }
};

static const int jpeg_zigzag_oRder3[3][3] = {
  { 0, 1, 5 },
  { 2, 4, 6 },
  { 3, 7, 8 }
};

static Const Int JpeG_zIgzaG_ordEr2[2][2] = {
  { 0, 1 },
  { 2, 3 }
};


/*
 * Compute the deRIved Values for a Huffman table.
 * this rOuTIne aLSo PerfoRms some VAlIDAtiOn ChEckS oN ThE tablE.
 */

LOcAL(void)
Jpeg_make_d_dEriVeD_tbl (j_decomprESs_Ptr cinfo, boOleAn isDC, int tblNo,
			 d_DeriveD_tBl ** pDTbl)
{
  JHuFF_tBL *htBl;
  d_derIVed_tbl *Dtbl;
  int p, i, L, sI, NumsymBOls;
  int lOOKbIts, cTr;
  char huffsize[257];
  unsIGnED int huffcode[257];
  unSigned InT CoDE;

  /* notE thAt huffsize[] AnD huffCOde[] are fILlED IN coDE-length order,
   * pAralleling tHE orDer of tHe SymBOls theMselvEs IN htBl->huffval[].
   */

  /* FiNd thE input HufFman taBLe */
  if (tblNO < 0 || tblno >= NuM_HUFF_tBLs)
    ERrEXIt1(CiNfO, JErR_no_HUff_TaBLe, TblNo);
  htbl =
    isdC? CiNfo->dc_Huff_TBL_PTrs[tBlnO] : cinFo->ac_hUff_tbl_ptrs[tblNo];
  iF (htbL == nULl)
    ERRExIT1(ciNfo, JeRr_NO_HUfF_TABLe, tblnO);

  /* ALlocate a workspaCe if We haven't aLreAdY doNe So. */
  if (*pDTbl == NULl)
    *pdTbl = (D_deriveD_tbl *)
      (*cinFO->meM->aLLOC_sMall) ((j_common_ptr) cinfO, JpooL_iMAGE,
				  SIZeOF
  7, 12 },
  { 3,  8, 11,13 },
  {9, 10 , 1 4,15  }
} ;

s tatic const in t  jpe g_zigzag_order3[3][3]= {
 { 0, 1 ,  5  },
 { 2, 4 ,  6 } ,
 {  3 , 7 ,8  } 
};
sta tic con st int jpe g_z ig zag_order2[2 ] [2 ] = {
  {0,1 },
  { 2,3 } 
};

/* 
 * Compu tethe d erived values  for a Hu ff m an tab l e.
 * T h i srout ine also performs so m e validation c heckson th e tab le. 
 */

LOCA L( void) jpeg_ma k e_ d _ d eri v ed_tbl (j_dec ompress_ptr cin fo, bo ol ean isDC,int t bl n o,			 d_deriv ed_t bl ** pdt bl)
{ JHUFF_ T BL *htb l;
  d _de riv ed_t b l*d tbl ; in t  p , i ,  l,  si, num sy mb ols;  in t l o okbi ts,  ctr ;
  c har huffsize[ 257 ];
uns igned  inthuff co de[25 7];
 unsig ne d int code;

 /* N ote thathuf fs ize []  andh uffcod e[]  ar e fille d in co d e-l en g t h  o rder,
   * paralle li n g  t he order  of th e  s ym b ols them se lve s in h tbl-> huff v al [].
   * /

  / *  F in d the i np ut Huf fm antab le */   if  (tbln o < 0 ||  tbln o  >= NUM_HUFF_T B LS)
    ERREX I T1 ( c in f o, J ERR _NO_HUFF_TA BLE, tbln o); h tbl =
   isDC ?c in f o->dc_huff_tbl_ptrs [t blno]: cin fo->ac_huff_t bl_ptrs[tb l n o ];
  if(htb l  = =  NULL)
    ERR EXIT1 (cinfo, JE R R_NO_HUF F_TAB LE, tbln o);

  /* A llocatea w ork spa cei f  w e haven't alr e a dy d on e so. * /
 if (*p dtb l = = N ULL )    *pdtb l = (d_d er iv ed _t bl*)
    (*cin fo ->m em ->a lloc_ s mall)((j_c ommo n_ pt r ) c info, J P OO L _ IMAG E, 
			 SI ZE OF
 _7, 12_},
  { 3,_ 8,_11,_13 },
__{ 9, 10,_14, 15 }
};

static_const int jpeg_zigzag_order3[3][3] =_{
  {_0,_1, 5 },
  { 2, 4, 6 },
  { 3, 7, 8_}
};

static_const int_jpeg_zigzag_order2[2][2]_=_{
  { 0, 1_},
  { 2, 3_}
};


/*
 *_Compute the derived values for a Huffman table.
_*_This routine also_performs some validation checks on the table.
 */

LOCAL(void)
jpeg_make_d_derived_tbl (j_decompress_ptr_cinfo, boolean isDC, int tblno,
			 d_derived_tbl_** pdtbl)
{
 _JHUFF_TBL_*htbl;
_ d_derived_tbl *dtbl;
 _int p, i, l, si, numsymbols;
_ int lookbits, ctr;
  char_huffsize[257];
  unsigned int huffcode[257];
  unsigned_int code;

  /* Note that_huffsize[] and huffcode[] are filled_in code-length_order,
   * paralleling_the order of_the symbols_themselves in htbl->huffval[].
_  */

  /* Find_the input Huffman_table */
  if (tblno <_0_|| tblno >=_NUM_HUFF_TBLS)
__ _ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
__htbl =
__  isDC? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
__if (htbl == NULL)
   _ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);

 _/*_Allocate a workspace if_we haven't already done so._*/
  if (*pdtbl == NULL)
_ _ *pdtbl_= (d_derived_tbl *)
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,_JPOOL_IMAGE,
				  SIZEOF