jinclude.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * jinclude.h
  3. *
  4. * Copyright (C) 1991-1994, Thomas G. Lane.
  5. * Modified 2017-2022 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 exists to provide a single place to fix any problems with
  10. * including the wrong system include files. (Common problems are taken
  11. * care of by the standard jconfig symbols, but on really weird systems
  12. * you may have to edit this file.)
  13. *
  14. * NOTE: this file is NOT intended to be included by applications using
  15. * the JPEG library. Most applications need only include jpeglib.h.
  16. */
  17. /* Include auto-config file to find out which system include files we need. */
  18. #include "jconfig.h" /* auto configuration options */
  19. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  20. /*
  21. * We need the NULL macro and size_t typedef.
  22. * On an ANSI-conforming system it is sufficient to include <stddef.h>.
  23. * Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to
  24. * pull in <sys/types.h> as well.
  25. * Note that the core JPEG library does not require <stdio.h>;
  26. * only the default error handler and data source/destination modules do.
  27. * But we must pull it in because of the references to FILE in jpeglib.h.
  28. * You can remove those references if you want to compile without <stdio.h>.
  29. */
  30. #ifdef HAVE_STDDEF_H
  31. #include <stddef.h>
  32. #endif
  33. #ifdef HAVE_STDLIB_H
  34. #include <stdlib.h>
  35. #endif
  36. #ifdef NEED_SYS_TYPES_H
  37. #include <sys/types.h>
  38. #endif
  39. #include <stdio.h>
  40. /*
  41. * We need memory copying and zeroing functions, plus strncpy().
  42. * ANSI and System V implementations declare these in <string.h>.
  43. * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
  44. * Some systems may declare memset and memcpy in <memory.h>.
  45. *
  46. * NOTE: we assume the size parameters to these functions are of type size_t.
  47. * Change the casts in these macros if not!
  48. */
  49. #ifdef NEED_BSD_STRINGS
  50. #include <strings.h>
  51. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  52. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  53. #else /* not BSD, assume ANSI/SysV string lib */
  54. #include <string.h>
  55. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  56. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  57. #endif
  58. /*
  59. * In ANSI C, and indeed any rational implementation, size_t is also the
  60. * type returned by sizeof(). However, it seems there are some irrational
  61. * implementations out there, in which sizeof() returns an int even though
  62. * size_t is defined as long or unsigned long. To ensure consistent results
  63. * we always use this SIZEOF() macro in place of using sizeof() directly.
  64. */
  65. #define SIZEOF(object) ((size_t) sizeof(object))
  66. /*
  67. * The modules that use fread() and fwrite() always invoke them through
  68. * these macros. On some systems you may need to twiddle the argument casts.
  69. * CAUTION: argument order is different from underlying functions!
  70. *
  71. * Furthermore, macros are provided for fflush() and ferror() in order
  72. * to facilitate adaption by applications using an own FILE class.
  73. *
  74. * You can define your own custom file I/O functions in jconfig.h and
  75. * #define JPEG_HAVE_FILE_IO_CUSTOM there to prevent redefinition here.
  76. *
  77. * You can #define JPEG_USE_FILE_IO_CUSTOM in jconfig.h to use custom file
  78. * I/O functions implemented in Delphi VCL (Visual Component Library)
  79. * in Vcl.Imaging.jpeg.pas for the TJPEGImage component utilizing
  80. * the Delphi RTL (Run-Time Library) TMemoryStream component:
  81. *
  82. * procedure jpeg_stdio_src(var cinfo: jpeg_decompress_struct;
  83. * input_file: TStream); external;
  84. *
  85. * procedure jpeg_stdio_dest(var cinfo: jpeg_compress_struct;
  86. * output_file: TStream); external;
  87. *
  88. * function jfread(var buf; recsize, reccount: Integer; S: TStream): Integer;
  89. * begin
  90. * Result := S.Read(buf, recsize * reccount);
  91. * end;
  92. *
  93. * function jfwrite(const buf; recsize, reccount: Integer; S: TStream): Integer;
  94. * begin
  95. * Result := S.Write(buf, recsize * reccount);
  96. * end;
  97. *
  98. * function jfflush(S: TStream): Integer;
  99. * begin
  100. * Result := 0;
  101. * end;
  102. *
  103. * function jferror(S: TStream): Integer;
  104. * begin
  105. * Result := 0;
  106. * end;
  107. *
  108. * TMemoryStream of Delphi RTL has the distinctive feature to provide dynamic
  109. * memory buffer management with a file/stream-based interface, particularly for
  110. * the write (output) operation, which is easier to apply compared with direct
  111. * implementations as given in jdatadst.c for memory destination. Those direct
  112. * implementations of dynamic memory write tend to be more difficult to use,
  113. * so providing an option like TMemoryStream may be a useful alternative.
  114. *
  115. * The CFile/CMemFile classes of the Microsoft Foundation Class (MFC) Library
  116. * may be used in a similar fashion.
  117. */
  118. #ifndef JPEG_HAVE_FILE_IO_CUSTOM
  119. #ifdef JPEG_USE_FILE_IO_CUSTOM
  120. extern size_t jfread(void * __ptr, size_t __size, size_t __n, FILE * __stream);
  121. extern size_t jfwrite(const void * __ptr, size_t __size, size_t __n, FILE * __stream);
  122. extern int jfflush(FILE * __stream);
  123. extern int jferror(FILE * __fp);
  124. #define JFREAD(file,buf,sizeofbuf) \
  125. ((size_t) jfread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  126. #define JFWRITE(file,buf,sizeofbuf) \
  127. ((size_t) jfwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  128. #define JFFLUSH(file) jfflush(file)
  129. #define JFERROR(file) jferror(file)
  130. #else
  131. #define JFREAD(file,buf,sizeofbuf) \
  132. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  133. #define JFWRITE(file,buf,sizeofbuf) \
  134. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  135. #define JFFLUSH(file) fflush(file)
  136. #define JFERROR(file) ferror(file)
  137. #endif
  138. #endif