Back to index

lightning-sunbird  0.9+nobinonly
jcmarker.c
Go to the documentation of this file.
00001 /*
00002  * jcmarker.c
00003  *
00004  * Copyright (C) 1991-1998, Thomas G. Lane.
00005  * This file is part of the Independent JPEG Group's software.
00006  * For conditions of distribution and use, see the accompanying README file.
00007  *
00008  * This file contains routines to write JPEG datastream markers.
00009  */
00010 
00011 #define JPEG_INTERNALS
00012 #include "jinclude.h"
00013 #include "jpeglib.h"
00014 
00015 
00016 typedef enum {                     /* JPEG marker codes */
00017   M_SOF0  = 0xc0,
00018   M_SOF1  = 0xc1,
00019   M_SOF2  = 0xc2,
00020   M_SOF3  = 0xc3,
00021   
00022   M_SOF5  = 0xc5,
00023   M_SOF6  = 0xc6,
00024   M_SOF7  = 0xc7,
00025   
00026   M_JPG   = 0xc8,
00027   M_SOF9  = 0xc9,
00028   M_SOF10 = 0xca,
00029   M_SOF11 = 0xcb,
00030   
00031   M_SOF13 = 0xcd,
00032   M_SOF14 = 0xce,
00033   M_SOF15 = 0xcf,
00034   
00035   M_DHT   = 0xc4,
00036   
00037   M_DAC   = 0xcc,
00038   
00039   M_RST0  = 0xd0,
00040   M_RST1  = 0xd1,
00041   M_RST2  = 0xd2,
00042   M_RST3  = 0xd3,
00043   M_RST4  = 0xd4,
00044   M_RST5  = 0xd5,
00045   M_RST6  = 0xd6,
00046   M_RST7  = 0xd7,
00047   
00048   M_SOI   = 0xd8,
00049   M_EOI   = 0xd9,
00050   M_SOS   = 0xda,
00051   M_DQT   = 0xdb,
00052   M_DNL   = 0xdc,
00053   M_DRI   = 0xdd,
00054   M_DHP   = 0xde,
00055   M_EXP   = 0xdf,
00056   
00057   M_APP0  = 0xe0,
00058   M_APP1  = 0xe1,
00059   M_APP2  = 0xe2,
00060   M_APP3  = 0xe3,
00061   M_APP4  = 0xe4,
00062   M_APP5  = 0xe5,
00063   M_APP6  = 0xe6,
00064   M_APP7  = 0xe7,
00065   M_APP8  = 0xe8,
00066   M_APP9  = 0xe9,
00067   M_APP10 = 0xea,
00068   M_APP11 = 0xeb,
00069   M_APP12 = 0xec,
00070   M_APP13 = 0xed,
00071   M_APP14 = 0xee,
00072   M_APP15 = 0xef,
00073   
00074   M_JPG0  = 0xf0,
00075   M_JPG13 = 0xfd,
00076   M_COM   = 0xfe,
00077   
00078   M_TEM   = 0x01
00079 } JPEG_MARKER;
00080 
00081 
00082 /* Private state */
00083 
00084 typedef struct {
00085   struct jpeg_marker_writer pub; /* public fields */
00086 
00087   unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
00088 } my_marker_writer;
00089 
00090 typedef my_marker_writer * my_marker_ptr;
00091 
00092 
00093 /*
00094  * Basic output routines.
00095  *
00096  * Note that we do not support suspension while writing a marker.
00097  * Therefore, an application using suspension must ensure that there is
00098  * enough buffer space for the initial markers (typ. 600-700 bytes) before
00099  * calling jpeg_start_compress, and enough space to write the trailing EOI
00100  * (a few bytes) before calling jpeg_finish_compress.  Multipass compression
00101  * modes are not supported at all with suspension, so those two are the only
00102  * points where markers will be written.
00103  */
00104 
00105 LOCAL(void)
00106 emit_byte (j_compress_ptr cinfo, int16 val)
00107 /* Emit a byte */
00108 {
00109   struct jpeg_destination_mgr * dest = cinfo->dest;
00110 
00111   *(dest->next_output_byte)++ = (JOCTET) val;
00112   if (--dest->free_in_buffer == 0) {
00113     if (! (*dest->empty_output_buffer) (cinfo))
00114       ERREXIT(cinfo, JERR_CANT_SUSPEND);
00115   }
00116 }
00117 
00118 
00119 LOCAL(void)
00120 emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
00121 /* Emit a marker code */
00122 {
00123   emit_byte(cinfo, 0xFF);
00124   emit_byte(cinfo, (int16) mark);
00125 }
00126 
00127 
00128 LOCAL(void)
00129 emit_2bytes (j_compress_ptr cinfo, int16 value)
00130 /* Emit a 2-byte integer; these are always MSB first in JPEG files */
00131 {
00132   emit_byte(cinfo, (value >> 8) & 0xFF);
00133   emit_byte(cinfo, value & 0xFF);
00134 }
00135 
00136 
00137 /*
00138  * Routines to write specific marker types.
00139  */
00140 
00141 LOCAL(int16)
00142 emit_dqt (j_compress_ptr cinfo, int16 index)
00143 /* Emit a DQT marker */
00144 /* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
00145 {
00146   JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
00147   int16 prec;
00148   int16 i;
00149 
00150   if (qtbl == NULL)
00151     ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
00152 
00153   prec = 0;
00154   for (i = 0; i < DCTSIZE2; i++) {
00155     if (qtbl->quantval[i] > 255)
00156       prec = 1;
00157   }
00158 
00159   if (! qtbl->sent_table) {
00160     emit_marker(cinfo, M_DQT);
00161 
00162     emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
00163 
00164     emit_byte(cinfo, index + (prec<<4));
00165 
00166     for (i = 0; i < DCTSIZE2; i++) {
00167       /* The table entries must be emitted in zigzag order. */
00168       unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
00169       if (prec)
00170        emit_byte(cinfo, (int16) (qval >> 8));
00171       emit_byte(cinfo, (int16) (qval & 0xFF));
00172     }
00173 
00174     qtbl->sent_table = TRUE;
00175   }
00176 
00177   return prec;
00178 }
00179 
00180 
00181 LOCAL(void)
00182 emit_dht (j_compress_ptr cinfo, int16 index, boolean is_ac)
00183 /* Emit a DHT marker */
00184 {
00185   JHUFF_TBL * htbl;
00186   int16 length, i;
00187   
00188   if (is_ac) {
00189     htbl = cinfo->ac_huff_tbl_ptrs[index];
00190     index += 0x10;          /* output index has AC bit set */
00191   } else {
00192     htbl = cinfo->dc_huff_tbl_ptrs[index];
00193   }
00194 
00195   if (htbl == NULL)
00196     ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
00197   
00198   if (! htbl->sent_table) {
00199     emit_marker(cinfo, M_DHT);
00200     
00201     length = 0;
00202     for (i = 1; i <= 16; i++)
00203       length += htbl->bits[i];
00204     
00205     emit_2bytes(cinfo, length + 2 + 1 + 16);
00206     emit_byte(cinfo, index);
00207     
00208     for (i = 1; i <= 16; i++)
00209       emit_byte(cinfo, htbl->bits[i]);
00210     
00211     for (i = 0; i < length; i++)
00212       emit_byte(cinfo, htbl->huffval[i]);
00213     
00214     htbl->sent_table = TRUE;
00215   }
00216 }
00217 
00218 
00219 LOCAL(void)
00220 emit_dac (j_compress_ptr cinfo)
00221 /* Emit a DAC marker */
00222 /* Since the useful info is so small, we want to emit all the tables in */
00223 /* one DAC marker.  Therefore this routine does its own scan of the table. */
00224 {
00225 #ifdef C_ARITH_CODING_SUPPORTED
00226   char dc_in_use[NUM_ARITH_TBLS];
00227   char ac_in_use[NUM_ARITH_TBLS];
00228   int16 length, i;
00229   jpeg_component_info *compptr;
00230   
00231   for (i = 0; i < NUM_ARITH_TBLS; i++)
00232     dc_in_use[i] = ac_in_use[i] = 0;
00233   
00234   for (i = 0; i < cinfo->comps_in_scan; i++) {
00235     compptr = cinfo->cur_comp_info[i];
00236     dc_in_use[compptr->dc_tbl_no] = 1;
00237     ac_in_use[compptr->ac_tbl_no] = 1;
00238   }
00239   
00240   length = 0;
00241   for (i = 0; i < NUM_ARITH_TBLS; i++)
00242     length += dc_in_use[i] + ac_in_use[i];
00243   
00244   emit_marker(cinfo, M_DAC);
00245   
00246   emit_2bytes(cinfo, length*2 + 2);
00247   
00248   for (i = 0; i < NUM_ARITH_TBLS; i++) {
00249     if (dc_in_use[i]) {
00250       emit_byte(cinfo, i);
00251       emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
00252     }
00253     if (ac_in_use[i]) {
00254       emit_byte(cinfo, i + 0x10);
00255       emit_byte(cinfo, cinfo->arith_ac_K[i]);
00256     }
00257   }
00258 #endif /* C_ARITH_CODING_SUPPORTED */
00259 }
00260 
00261 
00262 LOCAL(void)
00263 emit_dri (j_compress_ptr cinfo)
00264 /* Emit a DRI marker */
00265 {
00266   emit_marker(cinfo, M_DRI);
00267   
00268   emit_2bytes(cinfo, 4);    /* fixed length */
00269 
00270   emit_2bytes(cinfo, (int16) cinfo->restart_interval);
00271 }
00272 
00273 
00274 LOCAL(void)
00275 emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
00276 /* Emit a SOF marker */
00277 {
00278   int16 ci;
00279   jpeg_component_info *compptr;
00280   
00281   emit_marker(cinfo, code);
00282   
00283   emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
00284 
00285   /* Make sure image isn't bigger than SOF field can handle */
00286   if ((long) cinfo->image_height > 65535L ||
00287       (long) cinfo->image_width > 65535L)
00288     ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
00289 
00290   emit_byte(cinfo, cinfo->data_precision);
00291   emit_2bytes(cinfo, (int16) cinfo->image_height);
00292   emit_2bytes(cinfo, (int16) cinfo->image_width);
00293 
00294   emit_byte(cinfo, cinfo->num_components);
00295 
00296   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00297        ci++, compptr++) {
00298     emit_byte(cinfo, compptr->component_id);
00299     emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
00300     emit_byte(cinfo, compptr->quant_tbl_no);
00301   }
00302 }
00303 
00304 
00305 LOCAL(void)
00306 emit_sos (j_compress_ptr cinfo)
00307 /* Emit a SOS marker */
00308 {
00309   int16 i, td, ta;
00310   jpeg_component_info *compptr;
00311   
00312   emit_marker(cinfo, M_SOS);
00313   
00314   emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
00315   
00316   emit_byte(cinfo, cinfo->comps_in_scan);
00317   
00318   for (i = 0; i < cinfo->comps_in_scan; i++) {
00319     compptr = cinfo->cur_comp_info[i];
00320     emit_byte(cinfo, compptr->component_id);
00321     td = compptr->dc_tbl_no;
00322     ta = compptr->ac_tbl_no;
00323     if (cinfo->progressive_mode) {
00324       /* Progressive mode: only DC or only AC tables are used in one scan;
00325        * furthermore, Huffman coding of DC refinement uses no table at all.
00326        * We emit 0 for unused field(s); this is recommended by the P&M text
00327        * but does not seem to be specified in the standard.
00328        */
00329       if (cinfo->Ss == 0) {
00330        ta = 0;                     /* DC scan */
00331        if (cinfo->Ah != 0 && !cinfo->arith_code)
00332          td = 0;            /* no DC table either */
00333       } else {
00334        td = 0;                     /* AC scan */
00335       }
00336     }
00337     emit_byte(cinfo, (td << 4) + ta);
00338   }
00339 
00340   emit_byte(cinfo, cinfo->Ss);
00341   emit_byte(cinfo, cinfo->Se);
00342   emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
00343 }
00344 
00345 
00346 LOCAL(void)
00347 emit_jfif_app0 (j_compress_ptr cinfo)
00348 /* Emit a JFIF-compliant APP0 marker */
00349 {
00350   /*
00351    * Length of APP0 block   (2 bytes)
00352    * Block ID               (4 bytes - ASCII "JFIF")
00353    * Zero byte                     (1 byte to terminate the ID string)
00354    * Version Major, Minor   (2 bytes - major first)
00355    * Units                  (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
00356    * Xdpu                   (2 bytes - dots per unit horizontal)
00357    * Ydpu                   (2 bytes - dots per unit vertical)
00358    * Thumbnail X size              (1 byte)
00359    * Thumbnail Y size              (1 byte)
00360    */
00361   
00362   emit_marker(cinfo, M_APP0);
00363   
00364   emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
00365 
00366   emit_byte(cinfo, 0x4A);   /* Identifier: ASCII "JFIF" */
00367   emit_byte(cinfo, 0x46);
00368   emit_byte(cinfo, 0x49);
00369   emit_byte(cinfo, 0x46);
00370   emit_byte(cinfo, 0);
00371   emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
00372   emit_byte(cinfo, cinfo->JFIF_minor_version);
00373   emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
00374   emit_2bytes(cinfo, (int16) cinfo->X_density);
00375   emit_2bytes(cinfo, (int16) cinfo->Y_density);
00376   emit_byte(cinfo, 0);             /* No thumbnail image */
00377   emit_byte(cinfo, 0);
00378 }
00379 
00380 
00381 LOCAL(void)
00382 emit_adobe_app14 (j_compress_ptr cinfo)
00383 /* Emit an Adobe APP14 marker */
00384 {
00385   /*
00386    * Length of APP14 block  (2 bytes)
00387    * Block ID               (5 bytes - ASCII "Adobe")
00388    * Version Number         (2 bytes - currently 100)
00389    * Flags0                 (2 bytes - currently 0)
00390    * Flags1                 (2 bytes - currently 0)
00391    * Color transform        (1 byte)
00392    *
00393    * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
00394    * now in circulation seem to use Version = 100, so that's what we write.
00395    *
00396    * We write the color transform byte as 1 if the JPEG color space is
00397    * YCbCr, 2 if it's YCCK, 0 otherwise.  Adobe's definition has to do with
00398    * whether the encoder performed a transformation, which is pretty useless.
00399    */
00400   
00401   emit_marker(cinfo, M_APP14);
00402   
00403   emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
00404 
00405   emit_byte(cinfo, 0x41);   /* Identifier: ASCII "Adobe" */
00406   emit_byte(cinfo, 0x64);
00407   emit_byte(cinfo, 0x6F);
00408   emit_byte(cinfo, 0x62);
00409   emit_byte(cinfo, 0x65);
00410   emit_2bytes(cinfo, 100);  /* Version */
00411   emit_2bytes(cinfo, 0);    /* Flags0 */
00412   emit_2bytes(cinfo, 0);    /* Flags1 */
00413   switch (cinfo->jpeg_color_space) {
00414   case JCS_YCbCr:
00415     emit_byte(cinfo, 1);    /* Color transform = 1 */
00416     break;
00417   case JCS_YCCK:
00418     emit_byte(cinfo, 2);    /* Color transform = 2 */
00419     break;
00420   default:
00421     emit_byte(cinfo, 0);    /* Color transform = 0 */
00422     break;
00423   }
00424 }
00425 
00426 
00427 /*
00428  * These routines allow writing an arbitrary marker with parameters.
00429  * The only intended use is to emit COM or APPn markers after calling
00430  * write_file_header and before calling write_frame_header.
00431  * Other uses are not guaranteed to produce desirable results.
00432  * Counting the parameter bytes properly is the caller's responsibility.
00433  */
00434 
00435 METHODDEF(void)
00436 write_marker_header (j_compress_ptr cinfo, int16 marker, unsigned int datalen)
00437 /* Emit an arbitrary marker header */
00438 {
00439   if (datalen > (unsigned int) 65533)            /* safety check */
00440     ERREXIT(cinfo, JERR_BAD_LENGTH);
00441 
00442   emit_marker(cinfo, (JPEG_MARKER) marker);
00443 
00444   emit_2bytes(cinfo, (int16) (datalen + 2));     /* total length */
00445 }
00446 
00447 METHODDEF(void)
00448 write_marker_byte (j_compress_ptr cinfo, int16 val)
00449 /* Emit one byte of marker parameters following write_marker_header */
00450 {
00451   emit_byte(cinfo, val);
00452 }
00453 
00454 
00455 /*
00456  * Write datastream header.
00457  * This consists of an SOI and optional APPn markers.
00458  * We recommend use of the JFIF marker, but not the Adobe marker,
00459  * when using YCbCr or grayscale data.  The JFIF marker should NOT
00460  * be used for any other JPEG colorspace.  The Adobe marker is helpful
00461  * to distinguish RGB, CMYK, and YCCK colorspaces.
00462  * Note that an application can write additional header markers after
00463  * jpeg_start_compress returns.
00464  */
00465 
00466 METHODDEF(void)
00467 write_file_header (j_compress_ptr cinfo)
00468 {
00469   my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
00470 
00471   emit_marker(cinfo, M_SOI);       /* first the SOI */
00472 
00473   /* SOI is defined to reset restart interval to 0 */
00474   marker->last_restart_interval = 0;
00475 
00476   if (cinfo->write_JFIF_header)    /* next an optional JFIF APP0 */
00477     emit_jfif_app0(cinfo);
00478   if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
00479     emit_adobe_app14(cinfo);
00480 }
00481 
00482 
00483 /*
00484  * Write frame header.
00485  * This consists of DQT and SOFn markers.
00486  * Note that we do not emit the SOF until we have emitted the DQT(s).
00487  * This avoids compatibility problems with incorrect implementations that
00488  * try to error-check the quant table numbers as soon as they see the SOF.
00489  */
00490 
00491 METHODDEF(void)
00492 write_frame_header (j_compress_ptr cinfo)
00493 {
00494   int16 ci, prec;
00495   boolean is_baseline;
00496   jpeg_component_info *compptr;
00497   
00498   /* Emit DQT for each quantization table.
00499    * Note that emit_dqt() suppresses any duplicate tables.
00500    */
00501   prec = 0;
00502   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00503        ci++, compptr++) {
00504     prec += emit_dqt(cinfo, compptr->quant_tbl_no);
00505   }
00506   /* now prec is nonzero iff there are any 16-bit quant tables. */
00507 
00508   /* Check for a non-baseline specification.
00509    * Note we assume that Huffman table numbers won't be changed later.
00510    */
00511   if (cinfo->arith_code || cinfo->progressive_mode ||
00512       cinfo->data_precision != 8) {
00513     is_baseline = FALSE;
00514   } else {
00515     is_baseline = TRUE;
00516     for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00517         ci++, compptr++) {
00518       if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
00519        is_baseline = FALSE;
00520     }
00521     if (prec && is_baseline) {
00522       is_baseline = FALSE;
00523       /* If it's baseline except for quantizer size, warn the user */
00524       TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
00525     }
00526   }
00527 
00528   /* Emit the proper SOF marker */
00529   if (cinfo->arith_code) {
00530     emit_sof(cinfo, M_SOF9);       /* SOF code for arithmetic coding */
00531   } else {
00532     if (cinfo->progressive_mode)
00533       emit_sof(cinfo, M_SOF2);     /* SOF code for progressive Huffman */
00534     else if (is_baseline)
00535       emit_sof(cinfo, M_SOF0);     /* SOF code for baseline implementation */
00536     else
00537       emit_sof(cinfo, M_SOF1);     /* SOF code for non-baseline Huffman file */
00538   }
00539 }
00540 
00541 
00542 /*
00543  * Write scan header.
00544  * This consists of DHT or DAC markers, optional DRI, and SOS.
00545  * Compressed data will be written following the SOS.
00546  */
00547 
00548 METHODDEF(void)
00549 write_scan_header (j_compress_ptr cinfo)
00550 {
00551   my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
00552   int16 i;
00553   jpeg_component_info *compptr;
00554 
00555   if (cinfo->arith_code) {
00556     /* Emit arith conditioning info.  We may have some duplication
00557      * if the file has multiple scans, but it's so small it's hardly
00558      * worth worrying about.
00559      */
00560     emit_dac(cinfo);
00561   } else {
00562     /* Emit Huffman tables.
00563      * Note that emit_dht() suppresses any duplicate tables.
00564      */
00565     for (i = 0; i < cinfo->comps_in_scan; i++) {
00566       compptr = cinfo->cur_comp_info[i];
00567       if (cinfo->progressive_mode) {
00568        /* Progressive mode: only DC or only AC tables are used in one scan */
00569        if (cinfo->Ss == 0) {
00570          if (cinfo->Ah == 0)       /* DC needs no table for refinement scan */
00571            emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
00572        } else {
00573          emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
00574        }
00575       } else {
00576        /* Sequential mode: need both DC and AC tables */
00577        emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
00578        emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
00579       }
00580     }
00581   }
00582 
00583   /* Emit DRI if required --- note that DRI value could change for each scan.
00584    * We avoid wasting space with unnecessary DRIs, however.
00585    */
00586   if (cinfo->restart_interval != marker->last_restart_interval) {
00587     emit_dri(cinfo);
00588     marker->last_restart_interval = cinfo->restart_interval;
00589   }
00590 
00591   emit_sos(cinfo);
00592 }
00593 
00594 
00595 /*
00596  * Write datastream trailer.
00597  */
00598 
00599 METHODDEF(void)
00600 write_file_trailer (j_compress_ptr cinfo)
00601 {
00602   emit_marker(cinfo, M_EOI);
00603 }
00604 
00605 
00606 /*
00607  * Write an abbreviated table-specification datastream.
00608  * This consists of SOI, DQT and DHT tables, and EOI.
00609  * Any table that is defined and not marked sent_table = TRUE will be
00610  * emitted.  Note that all tables will be marked sent_table = TRUE at exit.
00611  */
00612 
00613 METHODDEF(void)
00614 write_tables_only (j_compress_ptr cinfo)
00615 {
00616   int16 i;
00617 
00618   emit_marker(cinfo, M_SOI);
00619 
00620   for (i = 0; i < NUM_QUANT_TBLS; i++) {
00621     if (cinfo->quant_tbl_ptrs[i] != NULL)
00622       (void) emit_dqt(cinfo, i);
00623   }
00624 
00625   if (! cinfo->arith_code) {
00626     for (i = 0; i < NUM_HUFF_TBLS; i++) {
00627       if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
00628        emit_dht(cinfo, i, FALSE);
00629       if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
00630        emit_dht(cinfo, i, TRUE);
00631     }
00632   }
00633 
00634   emit_marker(cinfo, M_EOI);
00635 }
00636 
00637 
00638 /*
00639  * Initialize the marker writer module.
00640  */
00641 
00642 GLOBAL(void)
00643 jinit_marker_writer (j_compress_ptr cinfo)
00644 {
00645   my_marker_ptr marker;
00646 
00647   /* Create the subobject */
00648   marker = (my_marker_ptr)
00649     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00650                             SIZEOF(my_marker_writer));
00651   cinfo->marker = (struct jpeg_marker_writer *) marker;
00652   /* Initialize method pointers */
00653   marker->pub.write_file_header = write_file_header;
00654   marker->pub.write_frame_header = write_frame_header;
00655   marker->pub.write_scan_header = write_scan_header;
00656   marker->pub.write_file_trailer = write_file_trailer;
00657   marker->pub.write_tables_only = write_tables_only;
00658   marker->pub.write_marker_header = write_marker_header;
00659   marker->pub.write_marker_byte = write_marker_byte;
00660   /* Initialize private state */
00661   marker->last_restart_interval = 0;
00662 }