Repo for the search and displace ingest module that takes odf, docx and pdf and transforms it into .md to be used with search and displace operations
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.

724 lines
18 KiB

3 years ago
  1. unit imjcmarker;
  2. { This file contains routines to write JPEG datastream markers. }
  3. { Original: jcmarker.c; Copyright (C) 1991-1998, Thomas G. Lane. }
  4. interface
  5. {$I imjconfig.inc}
  6. uses
  7. imjinclude, imjmorecfg, imjerror,
  8. imjdeferr, imjpeglib, imjutils;
  9. const
  10. { JPEG marker codes }
  11. M_SOF0 = $c0;
  12. M_SOF1 = $c1;
  13. M_SOF2 = $c2;
  14. M_SOF3 = $c3;
  15. M_SOF5 = $c5;
  16. M_SOF6 = $c6;
  17. M_SOF7 = $c7;
  18. M_JPG = $c8;
  19. M_SOF9 = $c9;
  20. M_SOF10 = $ca;
  21. M_SOF11 = $cb;
  22. M_SOF13 = $cd;
  23. M_SOF14 = $ce;
  24. M_SOF15 = $cf;
  25. M_DHT = $c4;
  26. M_DAC = $cc;
  27. M_RST0 = $d0;
  28. M_RST1 = $d1;
  29. M_RST2 = $d2;
  30. M_RST3 = $d3;
  31. M_RST4 = $d4;
  32. M_RST5 = $d5;
  33. M_RST6 = $d6;
  34. M_RST7 = $d7;
  35. M_SOI = $d8;
  36. M_EOI = $d9;
  37. M_SOS = $da;
  38. M_DQT = $db;
  39. M_DNL = $dc;
  40. M_DRI = $dd;
  41. M_DHP = $de;
  42. M_EXP = $df;
  43. M_APP0 = $e0;
  44. M_APP1 = $e1;
  45. M_APP2 = $e2;
  46. M_APP3 = $e3;
  47. M_APP4 = $e4;
  48. M_APP5 = $e5;
  49. M_APP6 = $e6;
  50. M_APP7 = $e7;
  51. M_APP8 = $e8;
  52. M_APP9 = $e9;
  53. M_APP10 = $ea;
  54. M_APP11 = $eb;
  55. M_APP12 = $ec;
  56. M_APP13 = $ed;
  57. M_APP14 = $ee;
  58. M_APP15 = $ef;
  59. M_JPG0 = $f0;
  60. M_JPG13 = $fd;
  61. M_COM = $fe;
  62. M_TEM = $01;
  63. M_ERROR = $100;
  64. type
  65. JPEG_MARKER = Word;
  66. { Private state }
  67. type
  68. my_marker_ptr = ^my_marker_writer;
  69. my_marker_writer = record
  70. pub : jpeg_marker_writer; { public fields }
  71. last_restart_interval : uint; { last DRI value emitted; 0 after SOI }
  72. end;
  73. {GLOBAL}
  74. procedure jinit_marker_writer (cinfo : j_compress_ptr);
  75. implementation
  76. { Basic output routines.
  77. Note that we do not support suspension while writing a marker.
  78. Therefore, an application using suspension must ensure that there is
  79. enough buffer space for the initial markers (typ. 600-700 bytes) before
  80. calling jpeg_start_compress, and enough space to write the trailing EOI
  81. (a few bytes) before calling jpeg_finish_compress. Multipass compression
  82. modes are not supported at all with suspension, so those two are the only
  83. points where markers will be written. }
  84. {LOCAL}
  85. procedure emit_byte (cinfo : j_compress_ptr; val : int);
  86. { Emit a byte }
  87. var
  88. dest : jpeg_destination_mgr_ptr;
  89. begin
  90. dest := cinfo^.dest;
  91. dest^.next_output_byte^ := JOCTET(val);
  92. Inc(dest^.next_output_byte);
  93. Dec(dest^.free_in_buffer);
  94. if (dest^.free_in_buffer = 0) then
  95. begin
  96. if not dest^.empty_output_buffer(cinfo) then
  97. ERREXIT(j_common_ptr(cinfo), JERR_CANT_SUSPEND);
  98. end;
  99. end;
  100. {LOCAL}
  101. procedure emit_marker(cinfo : j_compress_ptr; mark : JPEG_MARKER);
  102. { Emit a marker code }
  103. begin
  104. emit_byte(cinfo, $FF);
  105. emit_byte(cinfo, int(mark));
  106. end;
  107. {LOCAL}
  108. procedure emit_2bytes (cinfo : j_compress_ptr; value : int);
  109. { Emit a 2-byte integer; these are always MSB first in JPEG files }
  110. begin
  111. emit_byte(cinfo, (value shr 8) and $FF);
  112. emit_byte(cinfo, value and $FF);
  113. end;
  114. { Routines to write specific marker types. }
  115. {LOCAL}
  116. function emit_dqt (cinfo : j_compress_ptr; index : int) : int;
  117. { Emit a DQT marker }
  118. { Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking }
  119. var
  120. qtbl : JQUANT_TBL_PTR;
  121. prec : int;
  122. i : int;
  123. var
  124. qval : uint;
  125. begin
  126. qtbl := cinfo^.quant_tbl_ptrs[index];
  127. if (qtbl = NIL) then
  128. ERREXIT1(j_common_ptr(cinfo), JERR_NO_QUANT_TABLE, index);
  129. prec := 0;
  130. for i := 0 to Pred(DCTSIZE2) do
  131. begin
  132. if (qtbl^.quantval[i] > 255) then
  133. prec := 1;
  134. end;
  135. if not qtbl^.sent_table then
  136. begin
  137. emit_marker(cinfo, M_DQT);
  138. if (prec <> 0) then
  139. emit_2bytes(cinfo, DCTSIZE2*2 + 1 + 2)
  140. else
  141. emit_2bytes(cinfo, DCTSIZE2 + 1 + 2);
  142. emit_byte(cinfo, index + (prec shl 4));
  143. for i := 0 to Pred(DCTSIZE2) do
  144. begin
  145. { The table entries must be emitted in zigzag order. }
  146. qval := qtbl^.quantval[jpeg_natural_order[i]];
  147. if (prec <> 0) then
  148. emit_byte(cinfo, int(qval shr 8));
  149. emit_byte(cinfo, int(qval and $FF));
  150. end;
  151. qtbl^.sent_table := TRUE;
  152. end;
  153. emit_dqt := prec;
  154. end;
  155. {LOCAL}
  156. procedure emit_dht (cinfo : j_compress_ptr; index : int; is_ac : boolean);
  157. { Emit a DHT marker }
  158. var
  159. htbl : JHUFF_TBL_PTR;
  160. length, i : int;
  161. begin
  162. if (is_ac) then
  163. begin
  164. htbl := cinfo^.ac_huff_tbl_ptrs[index];
  165. index := index + $10; { output index has AC bit set }
  166. end
  167. else
  168. begin
  169. htbl := cinfo^.dc_huff_tbl_ptrs[index];
  170. end;
  171. if (htbl = NIL) then
  172. ERREXIT1(j_common_ptr(cinfo), JERR_NO_HUFF_TABLE, index);
  173. if not htbl^.sent_table then
  174. begin
  175. emit_marker(cinfo, M_DHT);
  176. length := 0;
  177. for i := 1 to 16 do
  178. length := length + htbl^.bits[i];
  179. emit_2bytes(cinfo, length + 2 + 1 + 16);
  180. emit_byte(cinfo, index);
  181. for i := 1 to 16 do
  182. emit_byte(cinfo, htbl^.bits[i]);
  183. for i := 0 to Pred(length) do
  184. emit_byte(cinfo, htbl^.huffval[i]);
  185. htbl^.sent_table := TRUE;
  186. end;
  187. end;
  188. {LOCAL}
  189. procedure emit_dac (cinfo : j_compress_ptr);
  190. { Emit a DAC marker }
  191. { Since the useful info is so small, we want to emit all the tables in }
  192. { one DAC marker. Therefore this routine does its own scan of the table. }
  193. {$ifdef C_ARITH_CODING_SUPPORTED}
  194. var
  195. dc_in_use : array[0..NUM_ARITH_TBLS] of byte;
  196. ac_in_use : array[0..NUM_ARITH_TBLS] of byte;
  197. length, i : int;
  198. compptr : jpeg_component_info_ptr;
  199. begin
  200. for i := 0 to pred(NUM_ARITH_TBLS) do
  201. begin
  202. dc_in_use[i] := 0;
  203. ac_in_use[i] := 0;
  204. end;
  205. for i := 0 to pred(cinfo^.comps_in_scan) do
  206. begin
  207. compptr := cinfo^.cur_comp_info[i];
  208. dc_in_use[compptr^.dc_tbl_no] := 1;
  209. ac_in_use[compptr^.ac_tbl_no] := 1;
  210. end;
  211. length := 0;
  212. for i := 0 to pred(NUM_ARITH_TBLS) do
  213. Inc(length, dc_in_use[i] + ac_in_use[i]);
  214. emit_marker(cinfo, M_DAC);
  215. emit_2bytes(cinfo, length*2 + 2);
  216. for i := 0 to pred(NUM_ARITH_TBLS) do
  217. begin
  218. if (dc_in_use[i] <> 0) then
  219. begin
  220. emit_byte(cinfo, i);
  221. emit_byte(cinfo, cinfo^.arith_dc_L[i] + (cinfo^.arith_dc_U[i] shl 4));
  222. end;
  223. if (ac_in_use[i] <> 0) then
  224. begin
  225. emit_byte(cinfo, i + $10);
  226. emit_byte(cinfo, cinfo^.arith_ac_K[i]);
  227. end;
  228. end;
  229. end;
  230. {$else}
  231. begin
  232. end;
  233. {$endif} {C_ARITH_CODING_SUPPORTED}
  234. {LOCAL}
  235. procedure emit_dri (cinfo : j_compress_ptr);
  236. { Emit a DRI marker }
  237. begin
  238. emit_marker(cinfo, M_DRI);
  239. emit_2bytes(cinfo, 4); { fixed length }
  240. emit_2bytes(cinfo, int(cinfo^.restart_interval));
  241. end;
  242. {LOCAL}
  243. procedure emit_sof (cinfo : j_compress_ptr; code : JPEG_MARKER);
  244. { Emit a SOF marker }
  245. var
  246. ci : int;
  247. compptr : jpeg_component_info_ptr;
  248. begin
  249. emit_marker(cinfo, code);
  250. emit_2bytes(cinfo, 3 * cinfo^.num_components + 2 + 5 + 1); { length }
  251. { Make sure image isn't bigger than SOF field can handle }
  252. if (long(cinfo^.image_height) > long(65535)) or
  253. (long(cinfo^.image_width) > long(65535)) then
  254. ERREXIT1(j_common_ptr(cinfo), JERR_IMAGE_TOO_BIG, uInt(65535));
  255. emit_byte(cinfo, cinfo^.data_precision);
  256. emit_2bytes(cinfo, int(cinfo^.image_height));
  257. emit_2bytes(cinfo, int(cinfo^.image_width));
  258. emit_byte(cinfo, cinfo^.num_components);
  259. compptr := jpeg_component_info_ptr(cinfo^.comp_info);
  260. for ci := 0 to Pred(cinfo^.num_components) do
  261. begin
  262. emit_byte(cinfo, compptr^.component_id);
  263. emit_byte(cinfo, (compptr^.h_samp_factor shl 4) + compptr^.v_samp_factor);
  264. emit_byte(cinfo, compptr^.quant_tbl_no);
  265. Inc(compptr);
  266. end;
  267. end;
  268. {LOCAL}
  269. procedure emit_sos (cinfo : j_compress_ptr);
  270. { Emit a SOS marker }
  271. var
  272. i, td, ta : int;
  273. compptr : jpeg_component_info_ptr;
  274. begin
  275. emit_marker(cinfo, M_SOS);
  276. emit_2bytes(cinfo, 2 * cinfo^.comps_in_scan + 2 + 1 + 3); { length }
  277. emit_byte(cinfo, cinfo^.comps_in_scan);
  278. for i := 0 to Pred(cinfo^.comps_in_scan) do
  279. begin
  280. compptr := cinfo^.cur_comp_info[i];
  281. emit_byte(cinfo, compptr^.component_id);
  282. td := compptr^.dc_tbl_no;
  283. ta := compptr^.ac_tbl_no;
  284. if (cinfo^.progressive_mode) then
  285. begin
  286. { Progressive mode: only DC or only AC tables are used in one scan;
  287. furthermore, Huffman coding of DC refinement uses no table at all.
  288. We emit 0 for unused field(s); this is recommended by the P&M text
  289. but does not seem to be specified in the standard. }
  290. if (cinfo^.Ss = 0) then
  291. begin
  292. ta := 0; { DC scan }
  293. if (cinfo^.Ah <> 0) and not cinfo^.arith_code then
  294. td := 0; { no DC table either }
  295. end
  296. else
  297. begin
  298. td := 0; { AC scan }
  299. end;
  300. end;
  301. emit_byte(cinfo, (td shl 4) + ta);
  302. end;
  303. emit_byte(cinfo, cinfo^.Ss);
  304. emit_byte(cinfo, cinfo^.Se);
  305. emit_byte(cinfo, (cinfo^.Ah shl 4) + cinfo^.Al);
  306. end;
  307. {LOCAL}
  308. procedure emit_jfif_app0 (cinfo : j_compress_ptr);
  309. { Emit a JFIF-compliant APP0 marker }
  310. {
  311. Length of APP0 block (2 bytes)
  312. Block ID (4 bytes - ASCII "JFIF")
  313. Zero byte (1 byte to terminate the ID string)
  314. Version Major, Minor (2 bytes - major first)
  315. Units (1 byte - $00 = none, $01 = inch, $02 = cm)
  316. Xdpu (2 bytes - dots per unit horizontal)
  317. Ydpu (2 bytes - dots per unit vertical)
  318. Thumbnail X size (1 byte)
  319. Thumbnail Y size (1 byte)
  320. }
  321. begin
  322. emit_marker(cinfo, M_APP0);
  323. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); { length }
  324. emit_byte(cinfo, $4A); { Identifier: ASCII "JFIF" }
  325. emit_byte(cinfo, $46);
  326. emit_byte(cinfo, $49);
  327. emit_byte(cinfo, $46);
  328. emit_byte(cinfo, 0);
  329. emit_byte(cinfo, cinfo^.JFIF_major_version); { Version fields }
  330. emit_byte(cinfo, cinfo^.JFIF_minor_version);
  331. emit_byte(cinfo, cinfo^.density_unit); { Pixel size information }
  332. emit_2bytes(cinfo, int(cinfo^.X_density));
  333. emit_2bytes(cinfo, int(cinfo^.Y_density));
  334. emit_byte(cinfo, 0); { No thumbnail image }
  335. emit_byte(cinfo, 0);
  336. end;
  337. {LOCAL}
  338. procedure emit_adobe_app14 (cinfo : j_compress_ptr);
  339. { Emit an Adobe APP14 marker }
  340. {
  341. Length of APP14 block (2 bytes)
  342. Block ID (5 bytes - ASCII "Adobe")
  343. Version Number (2 bytes - currently 100)
  344. Flags0 (2 bytes - currently 0)
  345. Flags1 (2 bytes - currently 0)
  346. Color transform (1 byte)
  347. Although Adobe TN 5116 mentions Version = 101, all the Adobe files
  348. now in circulation seem to use Version = 100, so that's what we write.
  349. We write the color transform byte as 1 if the JPEG color space is
  350. YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with
  351. whether the encoder performed a transformation, which is pretty useless.
  352. }
  353. begin
  354. emit_marker(cinfo, M_APP14);
  355. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); { length }
  356. emit_byte(cinfo, $41); { Identifier: ASCII "Adobe" }
  357. emit_byte(cinfo, $64);
  358. emit_byte(cinfo, $6F);
  359. emit_byte(cinfo, $62);
  360. emit_byte(cinfo, $65);
  361. emit_2bytes(cinfo, 100); { Version }
  362. emit_2bytes(cinfo, 0); { Flags0 }
  363. emit_2bytes(cinfo, 0); { Flags1 }
  364. case (cinfo^.jpeg_color_space) of
  365. JCS_YCbCr:
  366. emit_byte(cinfo, 1); { Color transform = 1 }
  367. JCS_YCCK:
  368. emit_byte(cinfo, 2); { Color transform = 2 }
  369. else
  370. emit_byte(cinfo, 0); { Color transform = 0 }
  371. end;
  372. end;
  373. { These routines allow writing an arbitrary marker with parameters.
  374. The only intended use is to emit COM or APPn markers after calling
  375. write_file_header and before calling write_frame_header.
  376. Other uses are not guaranteed to produce desirable results.
  377. Counting the parameter bytes properly is the caller's responsibility. }
  378. {METHODDEF}
  379. procedure write_marker_header (cinfo : j_compress_ptr;
  380. marker : int;
  381. datalen : uint);
  382. { Emit an arbitrary marker header }
  383. begin
  384. if (datalen > uint(65533)) then { safety check }
  385. ERREXIT(j_common_ptr(cinfo), JERR_BAD_LENGTH);
  386. emit_marker(cinfo, JPEG_MARKER(marker));
  387. emit_2bytes(cinfo, int(datalen + 2)); { total length }
  388. end;
  389. {METHODDEF}
  390. procedure write_marker_byte (cinfo : j_compress_ptr; val : int);
  391. { Emit one byte of marker parameters following write_marker_header }
  392. begin
  393. emit_byte(cinfo, val);
  394. end;
  395. { Write datastream header.
  396. This consists of an SOI and optional APPn markers.
  397. We recommend use of the JFIF marker, but not the Adobe marker,
  398. when using YCbCr or grayscale data. The JFIF marker should NOT
  399. be used for any other JPEG colorspace. The Adobe marker is helpful
  400. to distinguish RGB, CMYK, and YCCK colorspaces.
  401. Note that an application can write additional header markers after
  402. jpeg_start_compress returns. }
  403. {METHODDEF}
  404. procedure write_file_header (cinfo : j_compress_ptr);
  405. var
  406. marker : my_marker_ptr;
  407. begin
  408. marker := my_marker_ptr(cinfo^.marker);
  409. emit_marker(cinfo, M_SOI); { first the SOI }
  410. { SOI is defined to reset restart interval to 0 }
  411. marker^.last_restart_interval := 0;
  412. if (cinfo^.write_JFIF_header) then { next an optional JFIF APP0 }
  413. emit_jfif_app0(cinfo);
  414. if (cinfo^.write_Adobe_marker) then { next an optional Adobe APP14 }
  415. emit_adobe_app14(cinfo);
  416. end;
  417. { Write frame header.
  418. This consists of DQT and SOFn markers.
  419. Note that we do not emit the SOF until we have emitted the DQT(s).
  420. This avoids compatibility problems with incorrect implementations that
  421. try to error-check the quant table numbers as soon as they see the SOF. }
  422. {METHODDEF}
  423. procedure write_frame_header (cinfo : j_compress_ptr);
  424. var
  425. ci, prec : int;
  426. is_baseline : boolean;
  427. compptr : jpeg_component_info_ptr;
  428. begin
  429. { Emit DQT for each quantization table.
  430. Note that emit_dqt() suppresses any duplicate tables. }
  431. prec := 0;
  432. compptr := jpeg_component_info_ptr(cinfo^.comp_info);
  433. for ci := 0 to Pred(cinfo^.num_components) do
  434. begin
  435. prec := prec + emit_dqt(cinfo, compptr^.quant_tbl_no);
  436. Inc(compptr);
  437. end;
  438. { now prec is nonzero iff there are any 16-bit quant tables. }
  439. { Check for a non-baseline specification.
  440. Note we assume that Huffman table numbers won't be changed later. }
  441. if (cinfo^.arith_code) or (cinfo^.progressive_mode)
  442. or (cinfo^.data_precision <> 8) then
  443. begin
  444. is_baseline := FALSE;
  445. end
  446. else
  447. begin
  448. is_baseline := TRUE;
  449. compptr := jpeg_component_info_ptr(cinfo^.comp_info);
  450. for ci := 0 to Pred(cinfo^.num_components) do
  451. begin
  452. if (compptr^.dc_tbl_no > 1) or (compptr^.ac_tbl_no > 1) then
  453. is_baseline := FALSE;
  454. Inc(compptr);
  455. end;
  456. if (prec <> 0) and (is_baseline) then
  457. begin
  458. is_baseline := FALSE;
  459. { If it's baseline except for quantizer size, warn the user }
  460. {$IFDEF DEBUG}
  461. TRACEMS(j_common_ptr(cinfo), 0, JTRC_16BIT_TABLES);
  462. {$ENDIF}
  463. end;
  464. end;
  465. { Emit the proper SOF marker }
  466. if (cinfo^.arith_code) then
  467. begin
  468. emit_sof(cinfo, M_SOF9); { SOF code for arithmetic coding }
  469. end
  470. else
  471. begin
  472. if (cinfo^.progressive_mode) then
  473. emit_sof(cinfo, M_SOF2) { SOF code for progressive Huffman }
  474. else if (is_baseline) then
  475. emit_sof(cinfo, M_SOF0) { SOF code for baseline implementation }
  476. else
  477. emit_sof(cinfo, M_SOF1); { SOF code for non-baseline Huffman file }
  478. end;
  479. end;
  480. { Write scan header.
  481. This consists of DHT or DAC markers, optional DRI, and SOS.
  482. Compressed data will be written following the SOS. }
  483. {METHODDEF}
  484. procedure write_scan_header (cinfo : j_compress_ptr);
  485. var
  486. marker : my_marker_ptr;
  487. i : int;
  488. compptr : jpeg_component_info_ptr;
  489. begin
  490. marker := my_marker_ptr(cinfo^.marker);
  491. if (cinfo^.arith_code) then
  492. begin
  493. { Emit arith conditioning info. We may have some duplication
  494. if the file has multiple scans, but it's so small it's hardly
  495. worth worrying about. }
  496. emit_dac(cinfo);
  497. end
  498. else
  499. begin
  500. { Emit Huffman tables.
  501. Note that emit_dht() suppresses any duplicate tables. }
  502. for i := 0 to Pred(cinfo^.comps_in_scan) do
  503. begin
  504. compptr := cinfo^.cur_comp_info[i];
  505. if (cinfo^.progressive_mode) then
  506. begin
  507. { Progressive mode: only DC or only AC tables are used in one scan }
  508. if (cinfo^.Ss = 0) then
  509. begin
  510. if (cinfo^.Ah = 0) then { DC needs no table for refinement scan }
  511. emit_dht(cinfo, compptr^.dc_tbl_no, FALSE);
  512. end
  513. else
  514. begin
  515. emit_dht(cinfo, compptr^.ac_tbl_no, TRUE);
  516. end;
  517. end
  518. else
  519. begin
  520. { Sequential mode: need both DC and AC tables }
  521. emit_dht(cinfo, compptr^.dc_tbl_no, FALSE);
  522. emit_dht(cinfo, compptr^.ac_tbl_no, TRUE);
  523. end;
  524. end;
  525. end;
  526. { Emit DRI if required --- note that DRI value could change for each scan.
  527. We avoid wasting space with unnecessary DRIs, however. }
  528. if (cinfo^.restart_interval <> marker^.last_restart_interval) then
  529. begin
  530. emit_dri(cinfo);
  531. marker^.last_restart_interval := cinfo^.restart_interval;
  532. end;
  533. emit_sos(cinfo);
  534. end;
  535. { Write datastream trailer. }
  536. {METHODDEF}
  537. procedure write_file_trailer (cinfo : j_compress_ptr);
  538. begin
  539. emit_marker(cinfo, M_EOI);
  540. end;
  541. { Write an abbreviated table-specification datastream.
  542. This consists of SOI, DQT and DHT tables, and EOI.
  543. Any table that is defined and not marked sent_table = TRUE will be
  544. emitted. Note that all tables will be marked sent_table = TRUE at exit. }
  545. {METHODDEF}
  546. procedure write_tables_only (cinfo : j_compress_ptr);
  547. var
  548. i : int;
  549. begin
  550. emit_marker(cinfo, M_SOI);
  551. for i := 0 to Pred(NUM_QUANT_TBLS) do
  552. begin
  553. if (cinfo^.quant_tbl_ptrs[i] <> NIL) then
  554. emit_dqt(cinfo, i); { dummy := ... }
  555. end;
  556. if (not cinfo^.arith_code) then
  557. begin
  558. for i := 0 to Pred(NUM_HUFF_TBLS) do
  559. begin
  560. if (cinfo^.dc_huff_tbl_ptrs[i] <> NIL) then
  561. emit_dht(cinfo, i, FALSE);
  562. if (cinfo^.ac_huff_tbl_ptrs[i] <> NIL) then
  563. emit_dht(cinfo, i, TRUE);
  564. end;
  565. end;
  566. emit_marker(cinfo, M_EOI);
  567. end;
  568. { Initialize the marker writer module. }
  569. {GLOBAL}
  570. procedure jinit_marker_writer (cinfo : j_compress_ptr);
  571. var
  572. marker : my_marker_ptr;
  573. begin
  574. { Create the subobject }
  575. marker := my_marker_ptr(
  576. cinfo^.mem^.alloc_small (j_common_ptr(cinfo), JPOOL_IMAGE,
  577. SIZEOF(my_marker_writer)) );
  578. cinfo^.marker := jpeg_marker_writer_ptr(marker);
  579. { Initialize method pointers }
  580. marker^.pub.write_file_header := write_file_header;
  581. marker^.pub.write_frame_header := write_frame_header;
  582. marker^.pub.write_scan_header := write_scan_header;
  583. marker^.pub.write_file_trailer := write_file_trailer;
  584. marker^.pub.write_tables_only := write_tables_only;
  585. marker^.pub.write_marker_header := write_marker_header;
  586. marker^.pub.write_marker_byte := write_marker_byte;
  587. { Initialize private state }
  588. marker^.last_restart_interval := 0;
  589. end;
  590. end.