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.

222 lines
8.1 KiB

3 years ago
  1. unit imjcapistd;
  2. { Original : jcapistd.c ; Copyright (C) 1994-1996, Thomas G. Lane. }
  3. { This file is part of the Independent JPEG Group's software.
  4. For conditions of distribution and use, see the accompanying README file.
  5. This file contains application interface code for the compression half
  6. of the JPEG library. These are the "standard" API routines that are
  7. used in the normal full-compression case. They are not used by a
  8. transcoding-only application. Note that if an application links in
  9. jpeg_start_compress, it will end up linking in the entire compressor.
  10. We thus must separate this file from jcapimin.c to avoid linking the
  11. whole compression library into a transcoder. }
  12. interface
  13. {$I imjconfig.inc}
  14. uses
  15. imjmorecfg,
  16. imjinclude,
  17. imjdeferr,
  18. imjerror,
  19. imjpeglib,
  20. imjcapimin, imjcinit;
  21. { Compression initialization.
  22. Before calling this, all parameters and a data destination must be set up.
  23. We require a write_all_tables parameter as a failsafe check when writing
  24. multiple datastreams from the same compression object. Since prior runs
  25. will have left all the tables marked sent_table=TRUE, a subsequent run
  26. would emit an abbreviated stream (no tables) by default. This may be what
  27. is wanted, but for safety's sake it should not be the default behavior:
  28. programmers should have to make a deliberate choice to emit abbreviated
  29. images. Therefore the documentation and examples should encourage people
  30. to pass write_all_tables=TRUE; then it will take active thought to do the
  31. wrong thing. }
  32. {GLOBAL}
  33. procedure jpeg_start_compress (cinfo : j_compress_ptr;
  34. write_all_tables : boolean);
  35. { Write some scanlines of data to the JPEG compressor.
  36. The return value will be the number of lines actually written.
  37. This should be less than the supplied num_lines only in case that
  38. the data destination module has requested suspension of the compressor,
  39. or if more than image_height scanlines are passed in.
  40. Note: we warn about excess calls to jpeg_write_scanlines() since
  41. this likely signals an application programmer error. However,
  42. excess scanlines passed in the last valid call are *silently* ignored,
  43. so that the application need not adjust num_lines for end-of-image
  44. when using a multiple-scanline buffer. }
  45. {GLOBAL}
  46. function jpeg_write_scanlines (cinfo : j_compress_ptr;
  47. scanlines : JSAMPARRAY;
  48. num_lines : JDIMENSION) : JDIMENSION;
  49. { Alternate entry point to write raw data.
  50. Processes exactly one iMCU row per call, unless suspended. }
  51. {GLOBAL}
  52. function jpeg_write_raw_data (cinfo : j_compress_ptr;
  53. data : JSAMPIMAGE;
  54. num_lines : JDIMENSION) : JDIMENSION;
  55. implementation
  56. { Compression initialization.
  57. Before calling this, all parameters and a data destination must be set up.
  58. We require a write_all_tables parameter as a failsafe check when writing
  59. multiple datastreams from the same compression object. Since prior runs
  60. will have left all the tables marked sent_table=TRUE, a subsequent run
  61. would emit an abbreviated stream (no tables) by default. This may be what
  62. is wanted, but for safety's sake it should not be the default behavior:
  63. programmers should have to make a deliberate choice to emit abbreviated
  64. images. Therefore the documentation and examples should encourage people
  65. to pass write_all_tables=TRUE; then it will take active thought to do the
  66. wrong thing. }
  67. {GLOBAL}
  68. procedure jpeg_start_compress (cinfo : j_compress_ptr;
  69. write_all_tables : boolean);
  70. begin
  71. if (cinfo^.global_state <> CSTATE_START) then
  72. ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
  73. if (write_all_tables) then
  74. jpeg_suppress_tables(cinfo, FALSE); { mark all tables to be written }
  75. { (Re)initialize error mgr and destination modules }
  76. cinfo^.err^.reset_error_mgr (j_common_ptr(cinfo));
  77. cinfo^.dest^.init_destination (cinfo);
  78. { Perform master selection of active modules }
  79. jinit_compress_master(cinfo);
  80. { Set up for the first pass }
  81. cinfo^.master^.prepare_for_pass (cinfo);
  82. { Ready for application to drive first pass through jpeg_write_scanlines
  83. or jpeg_write_raw_data. }
  84. cinfo^.next_scanline := 0;
  85. if cinfo^.raw_data_in then
  86. cinfo^.global_state := CSTATE_RAW_OK
  87. else
  88. cinfo^.global_state := CSTATE_SCANNING;
  89. end;
  90. { Write some scanlines of data to the JPEG compressor.
  91. The return value will be the number of lines actually written.
  92. This should be less than the supplied num_lines only in case that
  93. the data destination module has requested suspension of the compressor,
  94. or if more than image_height scanlines are passed in.
  95. Note: we warn about excess calls to jpeg_write_scanlines() since
  96. this likely signals an application programmer error. However,
  97. excess scanlines passed in the last valid call are *silently* ignored,
  98. so that the application need not adjust num_lines for end-of-image
  99. when using a multiple-scanline buffer. }
  100. {GLOBAL}
  101. function jpeg_write_scanlines (cinfo : j_compress_ptr;
  102. scanlines : JSAMPARRAY;
  103. num_lines : JDIMENSION) : JDIMENSION;
  104. var
  105. row_ctr, rows_left : JDIMENSION;
  106. begin
  107. if (cinfo^.global_state <> CSTATE_SCANNING) then
  108. ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
  109. if (cinfo^.next_scanline >= cinfo^.image_height) then
  110. WARNMS(j_common_ptr(cinfo), JWRN_TOO_MUCH_DATA);
  111. { Call progress monitor hook if present }
  112. if (cinfo^.progress <> NIL) then
  113. begin
  114. cinfo^.progress^.pass_counter := long (cinfo^.next_scanline);
  115. cinfo^.progress^.pass_limit := long (cinfo^.image_height);
  116. cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
  117. end;
  118. { Give master control module another chance if this is first call to
  119. jpeg_write_scanlines. This lets output of the frame/scan headers be
  120. delayed so that application can write COM, etc, markers between
  121. jpeg_start_compress and jpeg_write_scanlines. }
  122. if (cinfo^.master^.call_pass_startup) then
  123. cinfo^.master^.pass_startup (cinfo);
  124. { Ignore any extra scanlines at bottom of image. }
  125. rows_left := cinfo^.image_height - cinfo^.next_scanline;
  126. if (num_lines > rows_left) then
  127. num_lines := rows_left;
  128. row_ctr := 0;
  129. cinfo^.main^.process_data (cinfo, scanlines, {var}row_ctr, num_lines);
  130. Inc(cinfo^.next_scanline, row_ctr);
  131. jpeg_write_scanlines := row_ctr;
  132. end;
  133. { Alternate entry point to write raw data.
  134. Processes exactly one iMCU row per call, unless suspended. }
  135. {GLOBAL}
  136. function jpeg_write_raw_data (cinfo : j_compress_ptr;
  137. data : JSAMPIMAGE;
  138. num_lines : JDIMENSION) : JDIMENSION;
  139. var
  140. lines_per_iMCU_row : JDIMENSION;
  141. begin
  142. if (cinfo^.global_state <> CSTATE_RAW_OK) then
  143. ERREXIT1(j_common_ptr(cinfo), JERR_BAD_STATE, cinfo^.global_state);
  144. if (cinfo^.next_scanline >= cinfo^.image_height) then
  145. begin
  146. WARNMS(j_common_ptr(cinfo), JWRN_TOO_MUCH_DATA);
  147. jpeg_write_raw_data := 0;
  148. exit;
  149. end;
  150. { Call progress monitor hook if present }
  151. if (cinfo^.progress <> NIL) then
  152. begin
  153. cinfo^.progress^.pass_counter := long(cinfo^.next_scanline);
  154. cinfo^.progress^.pass_limit := long(cinfo^.image_height);
  155. cinfo^.progress^.progress_monitor (j_common_ptr(cinfo));
  156. end;
  157. { Give master control module another chance if this is first call to
  158. jpeg_write_raw_data. This lets output of the frame/scan headers be
  159. delayed so that application can write COM, etc, markers between
  160. jpeg_start_compress and jpeg_write_raw_data. }
  161. if (cinfo^.master^.call_pass_startup) then
  162. cinfo^.master^.pass_startup (cinfo);
  163. { Verify that at least one iMCU row has been passed. }
  164. lines_per_iMCU_row := cinfo^.max_v_samp_factor * DCTSIZE;
  165. if (num_lines < lines_per_iMCU_row) then
  166. ERREXIT(j_common_ptr(cinfo), JERR_BUFFER_SIZE);
  167. { Directly compress the row. }
  168. if (not cinfo^.coef^.compress_data (cinfo, data)) then
  169. begin
  170. { If compressor did not consume the whole row, suspend processing. }
  171. jpeg_write_raw_data := 0;
  172. exit;
  173. end;
  174. { OK, we processed one iMCU row. }
  175. Inc(cinfo^.next_scanline, lines_per_iMCU_row);
  176. jpeg_write_raw_data := lines_per_iMCU_row;
  177. end;
  178. end.