Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

680 lines
17 KiB

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