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.

130 lines
3.5 KiB

3 years ago
  1. unit imjcomapi;
  2. { This file contains application interface routines that are used for both
  3. compression and decompression. }
  4. { Original: jcomapi.c; Copyright (C) 1994-1997, Thomas G. Lane. }
  5. interface
  6. {$I imjconfig.inc}
  7. uses
  8. imjmorecfg,
  9. imjinclude,
  10. imjpeglib;
  11. { Abort processing of a JPEG compression or decompression operation,
  12. but don't destroy the object itself. }
  13. {GLOBAL}
  14. procedure jpeg_abort (cinfo : j_common_ptr);
  15. { Destruction of a JPEG object. }
  16. {GLOBAL}
  17. procedure jpeg_destroy (cinfo : j_common_ptr);
  18. {GLOBAL}
  19. function jpeg_alloc_quant_table (cinfo : j_common_ptr) : JQUANT_TBL_PTR;
  20. {GLOBAL}
  21. function jpeg_alloc_huff_table (cinfo : j_common_ptr) : JHUFF_TBL_PTR;
  22. implementation
  23. { Abort processing of a JPEG compression or decompression operation,
  24. but don't destroy the object itself.
  25. For this, we merely clean up all the nonpermanent memory pools.
  26. Note that temp files (virtual arrays) are not allowed to belong to
  27. the permanent pool, so we will be able to close all temp files here.
  28. Closing a data source or destination, if necessary, is the application's
  29. responsibility. }
  30. {GLOBAL}
  31. procedure jpeg_abort (cinfo : j_common_ptr);
  32. var
  33. pool : int;
  34. begin
  35. { Do nothing if called on a not-initialized or destroyed JPEG object. }
  36. if (cinfo^.mem = NIL) then
  37. exit;
  38. { Releasing pools in reverse order might help avoid fragmentation
  39. with some (brain-damaged) malloc libraries. }
  40. for pool := JPOOL_NUMPOOLS-1 downto JPOOL_PERMANENT+1 do
  41. begin
  42. cinfo^.mem^.free_pool (cinfo, pool);
  43. end;
  44. { Reset overall state for possible reuse of object }
  45. if (cinfo^.is_decompressor) then
  46. begin
  47. cinfo^.global_state := DSTATE_START;
  48. { Try to keep application from accessing now-deleted marker list.
  49. A bit kludgy to do it here, but this is the most central place. }
  50. j_decompress_ptr(cinfo)^.marker_list := NIL;
  51. end
  52. else
  53. begin
  54. cinfo^.global_state := CSTATE_START;
  55. end;
  56. end;
  57. { Destruction of a JPEG object.
  58. Everything gets deallocated except the master jpeg_compress_struct itself
  59. and the error manager struct. Both of these are supplied by the application
  60. and must be freed, if necessary, by the application. (Often they are on
  61. the stack and so don't need to be freed anyway.)
  62. Closing a data source or destination, if necessary, is the application's
  63. responsibility. }
  64. {GLOBAL}
  65. procedure jpeg_destroy (cinfo : j_common_ptr);
  66. begin
  67. { We need only tell the memory manager to release everything. }
  68. { NB: mem pointer is NIL if memory mgr failed to initialize. }
  69. if (cinfo^.mem <> NIL) then
  70. cinfo^.mem^.self_destruct (cinfo);
  71. cinfo^.mem := NIL; { be safe if jpeg_destroy is called twice }
  72. cinfo^.global_state := 0; { mark it destroyed }
  73. end;
  74. { Convenience routines for allocating quantization and Huffman tables.
  75. (Would jutils.c be a more reasonable place to put these?) }
  76. {GLOBAL}
  77. function jpeg_alloc_quant_table (cinfo : j_common_ptr) : JQUANT_TBL_PTR;
  78. var
  79. tbl : JQUANT_TBL_PTR;
  80. begin
  81. tbl := JQUANT_TBL_PTR(
  82. cinfo^.mem^.alloc_small (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL))
  83. );
  84. tbl^.sent_table := FALSE; { make sure this is false in any new table }
  85. jpeg_alloc_quant_table := tbl;
  86. end;
  87. {GLOBAL}
  88. function jpeg_alloc_huff_table (cinfo : j_common_ptr) : JHUFF_TBL_PTR;
  89. var
  90. tbl : JHUFF_TBL_PTR;
  91. begin
  92. tbl := JHUFF_TBL_PTR(
  93. cinfo^.mem^.alloc_small (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL))
  94. );
  95. tbl^.sent_table := FALSE; { make sure this is false in any new table }
  96. jpeg_alloc_huff_table := tbl;
  97. end;
  98. end.