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.

683 lines
17KB

  1. /*
  2. * jcmarker.c
  3. *
  4. * Copyright (C) 1991-1998, Thomas G. Lane.
  5. * Modified 2003-2010 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. if (length) {
  199. emit_marker(cinfo, M_DAC);
  200. emit_2bytes(cinfo, length*2 + 2);
  201. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  202. if (dc_in_use[i]) {
  203. emit_byte(cinfo, i);
  204. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  205. }
  206. if (ac_in_use[i]) {
  207. emit_byte(cinfo, i + 0x10);
  208. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  209. }
  210. }
  211. }
  212. #endif /* C_ARITH_CODING_SUPPORTED */
  213. }
  214. LOCAL(void)
  215. emit_dri (j_compress_ptr cinfo)
  216. /* Emit a DRI marker */
  217. {
  218. emit_marker(cinfo, M_DRI);
  219. emit_2bytes(cinfo, 4); /* fixed length */
  220. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  221. }
  222. LOCAL(void)
  223. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  224. /* Emit a SOF marker */
  225. {
  226. int ci;
  227. jpeg_component_info *compptr;
  228. emit_marker(cinfo, code);
  229. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  230. /* Make sure image isn't bigger than SOF field can handle */
  231. if ((long) cinfo->jpeg_height > 65535L ||
  232. (long) cinfo->jpeg_width > 65535L)
  233. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  234. emit_byte(cinfo, cinfo->data_precision);
  235. emit_2bytes(cinfo, (int) cinfo->jpeg_height);
  236. emit_2bytes(cinfo, (int) cinfo->jpeg_width);
  237. emit_byte(cinfo, cinfo->num_components);
  238. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  239. ci++, compptr++) {
  240. emit_byte(cinfo, compptr->component_id);
  241. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  242. emit_byte(cinfo, compptr->quant_tbl_no);
  243. }
  244. }
  245. LOCAL(void)
  246. emit_sos (j_compress_ptr cinfo)
  247. /* Emit a SOS marker */
  248. {
  249. int i, td, ta;
  250. jpeg_component_info *compptr;
  251. emit_marker(cinfo, M_SOS);
  252. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  253. emit_byte(cinfo, cinfo->comps_in_scan);
  254. for (i = 0; i < cinfo->comps_in_scan; i++) {
  255. compptr = cinfo->cur_comp_info[i];
  256. emit_byte(cinfo, compptr->component_id);
  257. /* We emit 0 for unused field(s); this is recommended by the P&M text
  258. * but does not seem to be specified in the standard.
  259. */
  260. /* DC needs no table for refinement scan */
  261. td = cinfo->Ss == 0 && cinfo->Ah == 0 ? compptr->dc_tbl_no : 0;
  262. /* AC needs no table when not present */
  263. ta = cinfo->Se ? compptr->ac_tbl_no : 0;
  264. emit_byte(cinfo, (td << 4) + ta);
  265. }
  266. emit_byte(cinfo, cinfo->Ss);
  267. emit_byte(cinfo, cinfo->Se);
  268. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  269. }
  270. LOCAL(void)
  271. emit_pseudo_sos (j_compress_ptr cinfo)
  272. /* Emit a pseudo SOS marker */
  273. {
  274. emit_marker(cinfo, M_SOS);
  275. emit_2bytes(cinfo, 2 + 1 + 3); /* length */
  276. emit_byte(cinfo, 0); /* Ns */
  277. emit_byte(cinfo, 0); /* Ss */
  278. emit_byte(cinfo, cinfo->block_size * cinfo->block_size - 1); /* Se */
  279. emit_byte(cinfo, 0); /* Ah/Al */
  280. }
  281. LOCAL(void)
  282. emit_jfif_app0 (j_compress_ptr cinfo)
  283. /* Emit a JFIF-compliant APP0 marker */
  284. {
  285. /*
  286. * Length of APP0 block (2 bytes)
  287. * Block ID (4 bytes - ASCII "JFIF")
  288. * Zero byte (1 byte to terminate the ID string)
  289. * Version Major, Minor (2 bytes - major first)
  290. * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)
  291. * Xdpu (2 bytes - dots per unit horizontal)
  292. * Ydpu (2 bytes - dots per unit vertical)
  293. * Thumbnail X size (1 byte)
  294. * Thumbnail Y size (1 byte)
  295. */
  296. emit_marker(cinfo, M_APP0);
  297. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  298. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  299. emit_byte(cinfo, 0x46);
  300. emit_byte(cinfo, 0x49);
  301. emit_byte(cinfo, 0x46);
  302. emit_byte(cinfo, 0);
  303. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  304. emit_byte(cinfo, cinfo->JFIF_minor_version);
  305. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  306. emit_2bytes(cinfo, (int) cinfo->X_density);
  307. emit_2bytes(cinfo, (int) cinfo->Y_density);
  308. emit_byte(cinfo, 0); /* No thumbnail image */
  309. emit_byte(cinfo, 0);
  310. }
  311. LOCAL(void)
  312. emit_adobe_app14 (j_compress_ptr cinfo)
  313. /* Emit an Adobe APP14 marker */
  314. {
  315. /*
  316. * Length of APP14 block (2 bytes)
  317. * Block ID (5 bytes - ASCII "Adobe")
  318. * Version Number (2 bytes - currently 100)
  319. * Flags0 (2 bytes - currently 0)
  320. * Flags1 (2 bytes - currently 0)
  321. * Color transform (1 byte)
  322. *
  323. * Although Adobe TN 5116 mentions Version = 101, all the Adobe files
  324. * now in circulation seem to use Version = 100, so that's what we write.
  325. *
  326. * We write the color transform byte as 1 if the JPEG color space is
  327. * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
  328. * whether the encoder performed a transformation, which is pretty useless.
  329. */
  330. emit_marker(cinfo, M_APP14);
  331. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  332. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  333. emit_byte(cinfo, 0x64);
  334. emit_byte(cinfo, 0x6F);
  335. emit_byte(cinfo, 0x62);
  336. emit_byte(cinfo, 0x65);
  337. emit_2bytes(cinfo, 100); /* Version */
  338. emit_2bytes(cinfo, 0); /* Flags0 */
  339. emit_2bytes(cinfo, 0); /* Flags1 */
  340. switch (cinfo->jpeg_color_space) {
  341. case JCS_YCbCr:
  342. emit_byte(cinfo, 1); /* Color transform = 1 */
  343. break;
  344. case JCS_YCCK:
  345. emit_byte(cinfo, 2); /* Color transform = 2 */
  346. break;
  347. default:
  348. emit_byte(cinfo, 0); /* Color transform = 0 */
  349. break;
  350. }
  351. }
  352. /*
  353. * These routines allow writing an arbitrary marker with parameters.
  354. * The only intended use is to emit COM or APPn markers after calling
  355. * write_file_header and before calling write_frame_header.
  356. * Other uses are not guaranteed to produce desirable results.
  357. * Counting the parameter bytes properly is the caller's responsibility.
  358. */
  359. METHODDEF(void)
  360. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  361. /* Emit an arbitrary marker header */
  362. {
  363. if (datalen > (unsigned int) 65533) /* safety check */
  364. ERREXIT(cinfo, JERR_BAD_LENGTH);
  365. emit_marker(cinfo, (JPEG_MARKER) marker);
  366. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  367. }
  368. METHODDEF(void)
  369. write_marker_byte (j_compress_ptr cinfo, int val)
  370. /* Emit one byte of marker parameters following write_marker_header */
  371. {
  372. emit_byte(cinfo, val);
  373. }
  374. /*
  375. * Write datastream header.
  376. * This consists of an SOI and optional APPn markers.
  377. * We recommend use of the JFIF marker, but not the Adobe marker,
  378. * when using YCbCr or grayscale data. The JFIF marker should NOT
  379. * be used for any other JPEG colorspace. The Adobe marker is helpful
  380. * to distinguish RGB, CMYK, and YCCK colorspaces.
  381. * Note that an application can write additional header markers after
  382. * jpeg_start_compress returns.
  383. */
  384. METHODDEF(void)
  385. write_file_header (j_compress_ptr cinfo)
  386. {
  387. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  388. emit_marker(cinfo, M_SOI); /* first the SOI */
  389. /* SOI is defined to reset restart interval to 0 */
  390. marker->last_restart_interval = 0;
  391. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  392. emit_jfif_app0(cinfo);
  393. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  394. emit_adobe_app14(cinfo);
  395. }
  396. /*
  397. * Write frame header.
  398. * This consists of DQT and SOFn markers, and a conditional pseudo SOS marker.
  399. * Note that we do not emit the SOF until we have emitted the DQT(s).
  400. * This avoids compatibility problems with incorrect implementations that
  401. * try to error-check the quant table numbers as soon as they see the SOF.
  402. */
  403. METHODDEF(void)
  404. write_frame_header (j_compress_ptr cinfo)
  405. {
  406. int ci, prec;
  407. boolean is_baseline;
  408. jpeg_component_info *compptr;
  409. /* Emit DQT for each quantization table.
  410. * Note that emit_dqt() suppresses any duplicate tables.
  411. */
  412. prec = 0;
  413. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  414. ci++, compptr++) {
  415. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  416. }
  417. /* now prec is nonzero iff there are any 16-bit quant tables. */
  418. /* Check for a non-baseline specification.
  419. * Note we assume that Huffman table numbers won't be changed later.
  420. */
  421. if (cinfo->arith_code || cinfo->progressive_mode ||
  422. cinfo->data_precision != 8 || cinfo->block_size != DCTSIZE) {
  423. is_baseline = FALSE;
  424. } else {
  425. is_baseline = TRUE;
  426. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  427. ci++, compptr++) {
  428. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  429. is_baseline = FALSE;
  430. }
  431. if (prec && is_baseline) {
  432. is_baseline = FALSE;
  433. /* If it's baseline except for quantizer size, warn the user */
  434. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  435. }
  436. }
  437. /* Emit the proper SOF marker */
  438. if (cinfo->arith_code) {
  439. if (cinfo->progressive_mode)
  440. emit_sof(cinfo, M_SOF10); /* SOF code for progressive arithmetic */
  441. else
  442. emit_sof(cinfo, M_SOF9); /* SOF code for sequential arithmetic */
  443. } else {
  444. if (cinfo->progressive_mode)
  445. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  446. else if (is_baseline)
  447. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  448. else
  449. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  450. }
  451. /* Check to emit pseudo SOS marker */
  452. if (cinfo->progressive_mode && cinfo->block_size != DCTSIZE)
  453. emit_pseudo_sos(cinfo);
  454. }
  455. /*
  456. * Write scan header.
  457. * This consists of DHT or DAC markers, optional DRI, and SOS.
  458. * Compressed data will be written following the SOS.
  459. */
  460. METHODDEF(void)
  461. write_scan_header (j_compress_ptr cinfo)
  462. {
  463. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  464. int i;
  465. jpeg_component_info *compptr;
  466. if (cinfo->arith_code) {
  467. /* Emit arith conditioning info. We may have some duplication
  468. * if the file has multiple scans, but it's so small it's hardly
  469. * worth worrying about.
  470. */
  471. emit_dac(cinfo);
  472. } else {
  473. /* Emit Huffman tables.
  474. * Note that emit_dht() suppresses any duplicate tables.
  475. */
  476. for (i = 0; i < cinfo->comps_in_scan; i++) {
  477. compptr = cinfo->cur_comp_info[i];
  478. /* DC needs no table for refinement scan */
  479. if (cinfo->Ss == 0 && cinfo->Ah == 0)
  480. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  481. /* AC needs no table when not present */
  482. if (cinfo->Se)
  483. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  484. }
  485. }
  486. /* Emit DRI if required --- note that DRI value could change for each scan.
  487. * We avoid wasting space with unnecessary DRIs, however.
  488. */
  489. if (cinfo->restart_interval != marker->last_restart_interval) {
  490. emit_dri(cinfo);
  491. marker->last_restart_interval = cinfo->restart_interval;
  492. }
  493. emit_sos(cinfo);
  494. }
  495. /*
  496. * Write datastream trailer.
  497. */
  498. METHODDEF(void)
  499. write_file_trailer (j_compress_ptr cinfo)
  500. {
  501. emit_marker(cinfo, M_EOI);
  502. }
  503. /*
  504. * Write an abbreviated table-specification datastream.
  505. * This consists of SOI, DQT and DHT tables, and EOI.
  506. * Any table that is defined and not marked sent_table = TRUE will be
  507. * emitted. Note that all tables will be marked sent_table = TRUE at exit.
  508. */
  509. METHODDEF(void)
  510. write_tables_only (j_compress_ptr cinfo)
  511. {
  512. int i;
  513. emit_marker(cinfo, M_SOI);
  514. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  515. if (cinfo->quant_tbl_ptrs[i] != NULL)
  516. (void) emit_dqt(cinfo, i);
  517. }
  518. if (! cinfo->arith_code) {
  519. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  520. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  521. emit_dht(cinfo, i, FALSE);
  522. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  523. emit_dht(cinfo, i, TRUE);
  524. }
  525. }
  526. emit_marker(cinfo, M_EOI);
  527. }
  528. /*
  529. * Initialize the marker writer module.
  530. */
  531. GLOBAL(void)
  532. jinit_marker_writer (j_compress_ptr cinfo)
  533. {
  534. my_marker_ptr marker;
  535. /* Create the subobject */
  536. marker = (my_marker_ptr)
  537. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  538. SIZEOF(my_marker_writer));
  539. cinfo->marker = (struct jpeg_marker_writer *) marker;
  540. /* Initialize method pointers */
  541. marker->pub.write_file_header = write_file_header;
  542. marker->pub.write_frame_header = write_frame_header;
  543. marker->pub.write_scan_header = write_scan_header;
  544. marker->pub.write_file_trailer = write_file_trailer;
  545. marker->pub.write_tables_only = write_tables_only;
  546. marker->pub.write_marker_header = write_marker_header;
  547. marker->pub.write_marker_byte = write_marker_byte;
  548. /* Initialize private state */
  549. marker->last_restart_interval = 0;
  550. }