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.

100 lines
2.8 KiB

  1. --- a/src/plugins/jpeg_extractor.c
  2. +++ b/src/plugins/jpeg_extractor.c
  3. @@ -31,8 +31,97 @@ typedef int boolean;
  4. #define HAVE_BOOLEAN
  5. #endif
  6. #include <jpeglib.h>
  7. +#include <jerror.h>
  8. #include <setjmp.h>
  9. +#if JPEG_LIB_VERSION < 80 && !defined(MEM_SRCDST_SUPPORTED)
  10. +typedef struct {
  11. + struct jpeg_source_mgr pub; /* public fields */
  12. +
  13. + JOCTET eoi_buffer[2]; /* a place to put a dummy EOI */
  14. +} my_source_mgr;
  15. +
  16. +typedef my_source_mgr * my_src_ptr;
  17. +
  18. +static void
  19. +init_source (j_decompress_ptr cinfo)
  20. +{
  21. + /* No work, since jpeg_mem_src set up the buffer pointer and count.
  22. + * Indeed, if we want to read multiple JPEG images from one buffer,
  23. + * this *must* not do anything to the pointer.
  24. + */
  25. +}
  26. +
  27. +static boolean
  28. +fill_input_buffer (j_decompress_ptr cinfo)
  29. +{
  30. + my_src_ptr src = (my_src_ptr) cinfo->src;
  31. +
  32. + WARNMS(cinfo, JWRN_JPEG_EOF);
  33. +
  34. + /* Create a fake EOI marker */
  35. + src->eoi_buffer[0] = (JOCTET) 0xFF;
  36. + src->eoi_buffer[1] = (JOCTET) JPEG_EOI;
  37. + src->pub.next_input_byte = src->eoi_buffer;
  38. + src->pub.bytes_in_buffer = 2;
  39. +
  40. + return TRUE;
  41. +}
  42. +
  43. +static void
  44. +skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  45. +{
  46. + my_src_ptr src = (my_src_ptr) cinfo->src;
  47. +
  48. + if (num_bytes > 0) {
  49. + while (num_bytes > (long) src->pub.bytes_in_buffer) {
  50. + num_bytes -= (long) src->pub.bytes_in_buffer;
  51. + (void) fill_input_buffer(cinfo);
  52. + /* note we assume that fill_input_buffer will never
  53. + * return FALSE, so suspension need not be handled.
  54. + */
  55. + }
  56. + src->pub.next_input_byte += (size_t) num_bytes;
  57. + src->pub.bytes_in_buffer -= (size_t) num_bytes;
  58. + }
  59. +}
  60. +
  61. +static void
  62. +term_source (j_decompress_ptr cinfo)
  63. +{
  64. + /* no work necessary here */
  65. +}
  66. +
  67. +static void
  68. +jpeg_mem_src (j_decompress_ptr cinfo, unsigned char * buffer,
  69. + unsigned long bufsize)
  70. +{
  71. + my_src_ptr src;
  72. +
  73. + /* The source object is made permanent so that a series of JPEG images
  74. + * can be read from a single buffer by calling jpeg_mem_src
  75. + * only before the first one.
  76. + * This makes it unsafe to use this manager and a different source
  77. + * manager serially with the same JPEG object. Caveat programmer.
  78. + */
  79. + if (cinfo->src == NULL) { /* first time for this JPEG object? */
  80. + cinfo->src = (struct jpeg_source_mgr *)
  81. + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
  82. + JPOOL_PERMANENT,
  83. + sizeof(my_source_mgr));
  84. + }
  85. +
  86. + src = (my_src_ptr) cinfo->src;
  87. + src->pub.init_source = init_source;
  88. + src->pub.fill_input_buffer = fill_input_buffer;
  89. + src->pub.skip_input_data = skip_input_data;
  90. + src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  91. + src->pub.term_source = term_source;
  92. +
  93. + src->pub.next_input_byte = buffer;
  94. + src->pub.bytes_in_buffer = bufsize;
  95. +}
  96. +#endif
  97. /**
  98. * Context for custom functions.