jcmarker.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * jcmarker.c
  3. *
  4. * Copyright (C) 1991-1995, Thomas G. Lane.
  5. * This file is part of the Independent JPEG Group's software.
  6. * For conditions of distribution and use, see the accompanying README file.
  7. *
  8. * This file contains routines to write JPEG datastream markers.
  9. */
  10. // leave this as first line for PCH reasons...
  11. //
  12. #include "../server/exe_headers.h"
  13. #define JPEG_INTERNALS
  14. #include "jinclude.h"
  15. #include "jpeglib.h"
  16. typedef enum { /* JPEG marker codes */
  17. M_SOF0 = 0xc0,
  18. M_SOF1 = 0xc1,
  19. M_SOF2 = 0xc2,
  20. M_SOF3 = 0xc3,
  21. M_SOF5 = 0xc5,
  22. M_SOF6 = 0xc6,
  23. M_SOF7 = 0xc7,
  24. M_JPG = 0xc8,
  25. M_SOF9 = 0xc9,
  26. M_SOF10 = 0xca,
  27. M_SOF11 = 0xcb,
  28. M_SOF13 = 0xcd,
  29. M_SOF14 = 0xce,
  30. M_SOF15 = 0xcf,
  31. M_DHT = 0xc4,
  32. M_DAC = 0xcc,
  33. M_RST0 = 0xd0,
  34. M_RST1 = 0xd1,
  35. M_RST2 = 0xd2,
  36. M_RST3 = 0xd3,
  37. M_RST4 = 0xd4,
  38. M_RST5 = 0xd5,
  39. M_RST6 = 0xd6,
  40. M_RST7 = 0xd7,
  41. M_SOI = 0xd8,
  42. M_EOI = 0xd9,
  43. M_SOS = 0xda,
  44. M_DQT = 0xdb,
  45. M_DNL = 0xdc,
  46. M_DRI = 0xdd,
  47. M_DHP = 0xde,
  48. M_EXP = 0xdf,
  49. M_APP0 = 0xe0,
  50. M_APP1 = 0xe1,
  51. M_APP2 = 0xe2,
  52. M_APP3 = 0xe3,
  53. M_APP4 = 0xe4,
  54. M_APP5 = 0xe5,
  55. M_APP6 = 0xe6,
  56. M_APP7 = 0xe7,
  57. M_APP8 = 0xe8,
  58. M_APP9 = 0xe9,
  59. M_APP10 = 0xea,
  60. M_APP11 = 0xeb,
  61. M_APP12 = 0xec,
  62. M_APP13 = 0xed,
  63. M_APP14 = 0xee,
  64. M_APP15 = 0xef,
  65. M_JPG0 = 0xf0,
  66. M_JPG13 = 0xfd,
  67. M_COM = 0xfe,
  68. M_TEM = 0x01,
  69. M_ERROR = 0x100
  70. } JPEG_MARKER;
  71. /*
  72. * Basic output routines.
  73. *
  74. * Note that we do not support suspension while writing a marker.
  75. * Therefore, an application using suspension must ensure that there is
  76. * enough buffer space for the initial markers (typ. 600-700 bytes) before
  77. * calling jpeg_start_compress, and enough space to write the trailing EOI
  78. * (a few bytes) before calling jpeg_finish_compress. Multipass compression
  79. * modes are not supported at all with suspension, so those two are the only
  80. * points where markers will be written.
  81. */
  82. LOCAL void
  83. emit_byte (j_compress_ptr cinfo, int val)
  84. /* Emit a byte */
  85. {
  86. struct jpeg_destination_mgr * dest = cinfo->dest;
  87. *(dest->next_output_byte)++ = (JOCTET) val;
  88. if (--dest->free_in_buffer == 0) {
  89. if (! (*dest->empty_output_buffer) (cinfo))
  90. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  91. }
  92. }
  93. LOCAL void
  94. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  95. /* Emit a marker code */
  96. {
  97. emit_byte(cinfo, 0xFF);
  98. emit_byte(cinfo, (int) mark);
  99. }
  100. LOCAL void
  101. emit_2bytes (j_compress_ptr cinfo, int value)
  102. /* Emit a 2-byte integer; these are always MSB first in JPEG files */
  103. {
  104. emit_byte(cinfo, (value >> 8) & 0xFF);
  105. emit_byte(cinfo, value & 0xFF);
  106. }
  107. /*
  108. * Routines to write specific marker types.
  109. */
  110. LOCAL int
  111. emit_dqt (j_compress_ptr cinfo, int index)
  112. /* Emit a DQT marker */
  113. /* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */
  114. {
  115. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  116. int prec;
  117. int i;
  118. if (qtbl == NULL)
  119. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  120. prec = 0;
  121. for (i = 0; i < DCTSIZE2; i++) {
  122. if (qtbl->quantval[i] > 255)
  123. prec = 1;
  124. }
  125. if (! qtbl->sent_table) {
  126. emit_marker(cinfo, M_DQT);
  127. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  128. emit_byte(cinfo, index + (prec<<4));
  129. for (i = 0; i < DCTSIZE2; i++) {
  130. if (prec)
  131. emit_byte(cinfo, qtbl->quantval[i] >> 8);
  132. emit_byte(cinfo, qtbl->quantval[i] & 0xFF);
  133. }
  134. qtbl->sent_table = TRUE;
  135. }
  136. return prec;
  137. }
  138. LOCAL void
  139. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  140. /* Emit a DHT marker */
  141. {
  142. JHUFF_TBL * htbl;
  143. int length, i;
  144. if (is_ac) {
  145. htbl = cinfo->ac_huff_tbl_ptrs[index];
  146. index += 0x10; /* output index has AC bit set */
  147. } else {
  148. htbl = cinfo->dc_huff_tbl_ptrs[index];
  149. }
  150. if (htbl == NULL)
  151. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  152. if (! htbl->sent_table) {
  153. emit_marker(cinfo, M_DHT);
  154. length = 0;
  155. for (i = 1; i <= 16; i++)
  156. length += htbl->bits[i];
  157. emit_2bytes(cinfo, length + 2 + 1 + 16);
  158. emit_byte(cinfo, index);
  159. for (i = 1; i <= 16; i++)
  160. emit_byte(cinfo, htbl->bits[i]);
  161. for (i = 0; i < length; i++)
  162. emit_byte(cinfo, htbl->huffval[i]);
  163. htbl->sent_table = TRUE;
  164. }
  165. }
  166. LOCAL void
  167. emit_dac (j_compress_ptr cinfo)
  168. /* Emit a DAC marker */
  169. /* Since the useful info is so small, we want to emit all the tables in */
  170. /* one DAC marker. Therefore this routine does its own scan of the table. */
  171. {
  172. #ifdef C_ARITH_CODING_SUPPORTED
  173. char dc_in_use[NUM_ARITH_TBLS];
  174. char ac_in_use[NUM_ARITH_TBLS];
  175. int length, i;
  176. jpeg_component_info *compptr;
  177. for (i = 0; i < NUM_ARITH_TBLS; i++)
  178. dc_in_use[i] = ac_in_use[i] = 0;
  179. for (i = 0; i < cinfo->comps_in_scan; i++) {
  180. compptr = cinfo->cur_comp_info[i];
  181. dc_in_use[compptr->dc_tbl_no] = 1;
  182. ac_in_use[compptr->ac_tbl_no] = 1;
  183. }
  184. length = 0;
  185. for (i = 0; i < NUM_ARITH_TBLS; i++)
  186. length += dc_in_use[i] + ac_in_use[i];
  187. emit_marker(cinfo, M_DAC);
  188. emit_2bytes(cinfo, length*2 + 2);
  189. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  190. if (dc_in_use[i]) {
  191. emit_byte(cinfo, i);
  192. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  193. }
  194. if (ac_in_use[i]) {
  195. emit_byte(cinfo, i + 0x10);
  196. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  197. }
  198. }
  199. #endif /* C_ARITH_CODING_SUPPORTED */
  200. }
  201. LOCAL void
  202. emit_dri (j_compress_ptr cinfo)
  203. /* Emit a DRI marker */
  204. {
  205. emit_marker(cinfo, M_DRI);
  206. emit_2bytes(cinfo, 4); /* fixed length */
  207. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  208. }
  209. LOCAL void
  210. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  211. /* Emit a SOF marker */
  212. {
  213. int ci;
  214. jpeg_component_info *compptr;
  215. emit_marker(cinfo, code);
  216. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  217. /* Make sure image isn't bigger than SOF field can handle */
  218. if ((long) cinfo->image_height > 65535L ||
  219. (long) cinfo->image_width > 65535L)
  220. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  221. emit_byte(cinfo, cinfo->data_precision);
  222. emit_2bytes(cinfo, (int) cinfo->image_height);
  223. emit_2bytes(cinfo, (int) cinfo->image_width);
  224. emit_byte(cinfo, cinfo->num_components);
  225. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  226. ci++, compptr++) {
  227. emit_byte(cinfo, compptr->component_id);
  228. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  229. emit_byte(cinfo, compptr->quant_tbl_no);
  230. }
  231. }
  232. LOCAL void
  233. emit_sos (j_compress_ptr cinfo)
  234. /* Emit a SOS marker */
  235. {
  236. int i, td, ta;
  237. jpeg_component_info *compptr;
  238. emit_marker(cinfo, M_SOS);
  239. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  240. emit_byte(cinfo, cinfo->comps_in_scan);
  241. for (i = 0; i < cinfo->comps_in_scan; i++) {
  242. compptr = cinfo->cur_comp_info[i];
  243. emit_byte(cinfo, compptr->component_id);
  244. td = compptr->dc_tbl_no;
  245. ta = compptr->ac_tbl_no;
  246. if (cinfo->progressive_mode) {
  247. /* Progressive mode: only DC or only AC tables are used in one scan;
  248. * furthermore, Huffman coding of DC refinement uses no table at all.
  249. * We emit 0 for unused field(s); this is recommended by the P&M text
  250. * but does not seem to be specified in the standard.
  251. */
  252. if (cinfo->Ss == 0) {
  253. ta = 0; /* DC scan */
  254. if (cinfo->Ah != 0 && !cinfo->arith_code)
  255. td = 0; /* no DC table either */
  256. } else {
  257. td = 0; /* AC scan */
  258. }
  259. }
  260. emit_byte(cinfo, (td << 4) + ta);
  261. }
  262. emit_byte(cinfo, cinfo->Ss);
  263. emit_byte(cinfo, cinfo->Se);
  264. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  265. }
  266. LOCAL void
  267. emit_jfif_app0 (j_compress_ptr cinfo)
  268. /* Emit a JFIF-compliant APP0 marker */
  269. {
  270. /*
  271. * Length of APP0 block (2 bytes)
  272. * Block ID (4 bytes - ASCII "JFIF")
  273. * Zero byte (1 byte to terminate the ID string)
  274. * Version Major, Minor (2 bytes - 0x01, 0x01)
  275. * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
  276. * Xdpu (2 bytes - dots per unit horizontal)
  277. * Ydpu (2 bytes - dots per unit vertical)
  278. * Thumbnail X size (1 byte)
  279. * Thumbnail Y size (1 byte)
  280. */
  281. emit_marker(cinfo, M_APP0);
  282. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  283. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  284. emit_byte(cinfo, 0x46);
  285. emit_byte(cinfo, 0x49);
  286. emit_byte(cinfo, 0x46);
  287. emit_byte(cinfo, 0);
  288. /* We currently emit version code 1.01 since we use no 1.02 features.
  289. * This may avoid complaints from some older decoders.
  290. */
  291. emit_byte(cinfo, 1); /* Major version */
  292. emit_byte(cinfo, 1); /* Minor version */
  293. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  294. emit_2bytes(cinfo, (int) cinfo->X_density);
  295. emit_2bytes(cinfo, (int) cinfo->Y_density);
  296. emit_byte(cinfo, 0); /* No thumbnail image */
  297. emit_byte(cinfo, 0);
  298. }
  299. LOCAL void
  300. emit_adobe_app14 (j_compress_ptr cinfo)
  301. /* Emit an Adobe APP14 marker */
  302. {
  303. /*
  304. * Length of APP14 block (2 bytes)
  305. * Block ID (5 bytes - ASCII "Adobe")
  306. * Version Number (2 bytes - currently 100)
  307. * Flags0 (2 bytes - currently 0)
  308. * Flags1 (2 bytes - currently 0)
  309. * Color transform (1 byte)
  310. *
  311. * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
  312. * now in circulation seem to use Version = 100, so that's what we write.
  313. *
  314. * We write the color transform byte as 1 if the JPEG color space is
  315. * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
  316. * whether the encoder performed a transformation, which is pretty useless.
  317. */
  318. emit_marker(cinfo, M_APP14);
  319. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  320. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  321. emit_byte(cinfo, 0x64);
  322. emit_byte(cinfo, 0x6F);
  323. emit_byte(cinfo, 0x62);
  324. emit_byte(cinfo, 0x65);
  325. emit_2bytes(cinfo, 100); /* Version */
  326. emit_2bytes(cinfo, 0); /* Flags0 */
  327. emit_2bytes(cinfo, 0); /* Flags1 */
  328. switch (cinfo->jpeg_color_space) {
  329. case JCS_YCbCr:
  330. emit_byte(cinfo, 1); /* Color transform = 1 */
  331. break;
  332. case JCS_YCCK:
  333. emit_byte(cinfo, 2); /* Color transform = 2 */
  334. break;
  335. default:
  336. emit_byte(cinfo, 0); /* Color transform = 0 */
  337. break;
  338. }
  339. }
  340. /*
  341. * This routine is exported for possible use by applications.
  342. * The intended use is to emit COM or APPn markers after calling
  343. * jpeg_start_compress() and before the first jpeg_write_scanlines() call
  344. * (hence, after write_file_header but before write_frame_header).
  345. * Other uses are not guaranteed to produce desirable results.
  346. */
  347. METHODDEF void
  348. write_any_marker (j_compress_ptr cinfo, int marker,
  349. const JOCTET *dataptr, unsigned int datalen)
  350. /* Emit an arbitrary marker with parameters */
  351. {
  352. if (datalen <= (unsigned int) 65533) { /* safety check */
  353. emit_marker(cinfo, (JPEG_MARKER) marker);
  354. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  355. while (datalen--) {
  356. emit_byte(cinfo, *dataptr);
  357. dataptr++;
  358. }
  359. }
  360. }
  361. /*
  362. * Write datastream header.
  363. * This consists of an SOI and optional APPn markers.
  364. * We recommend use of the JFIF marker, but not the Adobe marker,
  365. * when using YCbCr or grayscale data. The JFIF marker should NOT
  366. * be used for any other JPEG colorspace. The Adobe marker is helpful
  367. * to distinguish RGB, CMYK, and YCCK colorspaces.
  368. * Note that an application can write additional header markers after
  369. * jpeg_start_compress returns.
  370. */
  371. METHODDEF void
  372. write_file_header (j_compress_ptr cinfo)
  373. {
  374. emit_marker(cinfo, M_SOI); /* first the SOI */
  375. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  376. emit_jfif_app0(cinfo);
  377. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  378. emit_adobe_app14(cinfo);
  379. }
  380. /*
  381. * Write frame header.
  382. * This consists of DQT and SOFn markers.
  383. * Note that we do not emit the SOF until we have emitted the DQT(s).
  384. * This avoids compatibility problems with incorrect implementations that
  385. * try to error-check the quant table numbers as soon as they see the SOF.
  386. */
  387. METHODDEF void
  388. write_frame_header (j_compress_ptr cinfo)
  389. {
  390. int ci, prec;
  391. boolean is_baseline;
  392. jpeg_component_info *compptr;
  393. /* Emit DQT for each quantization table.
  394. * Note that emit_dqt() suppresses any duplicate tables.
  395. */
  396. prec = 0;
  397. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  398. ci++, compptr++) {
  399. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  400. }
  401. /* now prec is nonzero iff there are any 16-bit quant tables. */
  402. /* Check for a non-baseline specification.
  403. * Note we assume that Huffman table numbers won't be changed later.
  404. */
  405. if (cinfo->arith_code || cinfo->progressive_mode ||
  406. cinfo->data_precision != 8) {
  407. is_baseline = FALSE;
  408. } else {
  409. is_baseline = TRUE;
  410. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  411. ci++, compptr++) {
  412. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  413. is_baseline = FALSE;
  414. }
  415. if (prec && is_baseline) {
  416. is_baseline = FALSE;
  417. /* If it's baseline except for quantizer size, warn the user */
  418. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  419. }
  420. }
  421. /* Emit the proper SOF marker */
  422. if (cinfo->arith_code) {
  423. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  424. } else {
  425. if (cinfo->progressive_mode)
  426. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  427. else if (is_baseline)
  428. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  429. else
  430. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  431. }
  432. }
  433. /*
  434. * Write scan header.
  435. * This consists of DHT or DAC markers, optional DRI, and SOS.
  436. * Compressed data will be written following the SOS.
  437. */
  438. METHODDEF void
  439. write_scan_header (j_compress_ptr cinfo)
  440. {
  441. int i;
  442. jpeg_component_info *compptr;
  443. if (cinfo->arith_code) {
  444. /* Emit arith conditioning info. We may have some duplication
  445. * if the file has multiple scans, but it's so small it's hardly
  446. * worth worrying about.
  447. */
  448. emit_dac(cinfo);
  449. } else {
  450. /* Emit Huffman tables.
  451. * Note that emit_dht() suppresses any duplicate tables.
  452. */
  453. for (i = 0; i < cinfo->comps_in_scan; i++) {
  454. compptr = cinfo->cur_comp_info[i];
  455. if (cinfo->progressive_mode) {
  456. /* Progressive mode: only DC or only AC tables are used in one scan */
  457. if (cinfo->Ss == 0) {
  458. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  459. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  460. } else {
  461. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  462. }
  463. } else {
  464. /* Sequential mode: need both DC and AC tables */
  465. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  466. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  467. }
  468. }
  469. }
  470. /* Emit DRI if required --- note that DRI value could change for each scan.
  471. * If it doesn't, a tiny amount of space is wasted in multiple-scan files.
  472. * We assume DRI will never be nonzero for one scan and zero for a later one.
  473. */
  474. if (cinfo->restart_interval)
  475. emit_dri(cinfo);
  476. emit_sos(cinfo);
  477. }
  478. /*
  479. * Write datastream trailer.
  480. */
  481. METHODDEF void
  482. write_file_trailer (j_compress_ptr cinfo)
  483. {
  484. emit_marker(cinfo, M_EOI);
  485. }
  486. /*
  487. * Write an abbreviated table-specification datastream.
  488. * This consists of SOI, DQT and DHT tables, and EOI.
  489. * Any table that is defined and not marked sent_table = TRUE will be
  490. * emitted. Note that all tables will be marked sent_table = TRUE at exit.
  491. */
  492. METHODDEF void
  493. write_tables_only (j_compress_ptr cinfo)
  494. {
  495. int i;
  496. emit_marker(cinfo, M_SOI);
  497. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  498. if (cinfo->quant_tbl_ptrs[i] != NULL)
  499. (void) emit_dqt(cinfo, i);
  500. }
  501. if (! cinfo->arith_code) {
  502. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  503. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  504. emit_dht(cinfo, i, FALSE);
  505. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  506. emit_dht(cinfo, i, TRUE);
  507. }
  508. }
  509. emit_marker(cinfo, M_EOI);
  510. }
  511. /*
  512. * Initialize the marker writer module.
  513. */
  514. GLOBAL void
  515. jinit_marker_writer (j_compress_ptr cinfo)
  516. {
  517. /* Create the subobject */
  518. cinfo->marker = (struct jpeg_marker_writer *)
  519. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  520. SIZEOF(struct jpeg_marker_writer));
  521. /* Initialize method pointers */
  522. cinfo->marker->write_any_marker = write_any_marker;
  523. cinfo->marker->write_file_header = write_file_header;
  524. cinfo->marker->write_frame_header = write_frame_header;
  525. cinfo->marker->write_scan_header = write_scan_header;
  526. cinfo->marker->write_file_trailer = write_file_trailer;
  527. cinfo->marker->write_tables_only = write_tables_only;
  528. }