/*1* jinclude.h2*3* Copyright (C) 1991-1994, Thomas G. Lane.4* Modified 2017-2022 by Guido Vollbeding.5* This file is part of the Independent JPEG Group's software.6* For conditions of distribution and use, see the accompanying README file.7*8* This file exists to provide a single place to fix any problems with9* including the wrong system include files. (Common problems are taken10* care of by the standard jconfig symbols, but on really weird systems11* you may have to edit this file.)12*13* NOTE: this file is NOT intended to be included by applications using14* the JPEG library. Most applications need only include jpeglib.h.15*/161718/* Include auto-config file to find out which system include files we need. */1920#include "jconfig.h" /* auto configuration options */21#define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */2223/*24* We need the NULL macro and size_t typedef.25* On an ANSI-conforming system it is sufficient to include <stddef.h>.26* Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to27* pull in <sys/types.h> as well.28* Note that the core JPEG library does not require <stdio.h>;29* only the default error handler and data source/destination modules do.30* But we must pull it in because of the references to FILE in jpeglib.h.31* You can remove those references if you want to compile without <stdio.h>.32*/3334#ifdef HAVE_STDDEF_H35#include <stddef.h>36#endif3738#ifdef HAVE_STDLIB_H39#include <stdlib.h>40#endif4142#ifdef NEED_SYS_TYPES_H43#include <sys/types.h>44#endif4546#include <stdio.h>4748/*49* We need memory copying and zeroing functions, plus strncpy().50* ANSI and System V implementations declare these in <string.h>.51* BSD doesn't have the mem() functions, but it does have bcopy()/bzero().52* Some systems may declare memset and memcpy in <memory.h>.53*54* NOTE: we assume the size parameters to these functions are of type size_t.55* Change the casts in these macros if not!56*/5758#ifdef NEED_BSD_STRINGS5960#include <strings.h>61#define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))62#define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))6364#else /* not BSD, assume ANSI/SysV string lib */6566#include <string.h>67#define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))68#define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))6970#endif7172/*73* In ANSI C, and indeed any rational implementation, size_t is also the74* type returned by sizeof(). However, it seems there are some irrational75* implementations out there, in which sizeof() returns an int even though76* size_t is defined as long or unsigned long. To ensure consistent results77* we always use this SIZEOF() macro in place of using sizeof() directly.78*/7980#define SIZEOF(object) ((size_t) sizeof(object))8182/*83* The modules that use fread() and fwrite() always invoke them through84* these macros. On some systems you may need to twiddle the argument casts.85* CAUTION: argument order is different from underlying functions!86*87* Furthermore, macros are provided for fflush() and ferror() in order88* to facilitate adaption by applications using an own FILE class.89*90* You can define your own custom file I/O functions in jconfig.h and91* #define JPEG_HAVE_FILE_IO_CUSTOM there to prevent redefinition here.92*93* You can #define JPEG_USE_FILE_IO_CUSTOM in jconfig.h to use custom file94* I/O functions implemented in Delphi VCL (Visual Component Library)95* in Vcl.Imaging.jpeg.pas for the TJPEGImage component utilizing96* the Delphi RTL (Run-Time Library) TMemoryStream component:97*98* procedure jpeg_stdio_src(var cinfo: jpeg_decompress_struct;99* input_file: TStream); external;100*101* procedure jpeg_stdio_dest(var cinfo: jpeg_compress_struct;102* output_file: TStream); external;103*104* function jfread(var buf; recsize, reccount: Integer; S: TStream): Integer;105* begin106* Result := S.Read(buf, recsize * reccount);107* end;108*109* function jfwrite(const buf; recsize, reccount: Integer; S: TStream): Integer;110* begin111* Result := S.Write(buf, recsize * reccount);112* end;113*114* function jfflush(S: TStream): Integer;115* begin116* Result := 0;117* end;118*119* function jferror(S: TStream): Integer;120* begin121* Result := 0;122* end;123*124* TMemoryStream of Delphi RTL has the distinctive feature to provide dynamic125* memory buffer management with a file/stream-based interface, particularly for126* the write (output) operation, which is easier to apply compared with direct127* implementations as given in jdatadst.c for memory destination. Those direct128* implementations of dynamic memory write tend to be more difficult to use,129* so providing an option like TMemoryStream may be a useful alternative.130*131* The CFile/CMemFile classes of the Microsoft Foundation Class (MFC) Library132* may be used in a similar fashion.133*/134135#ifndef JPEG_HAVE_FILE_IO_CUSTOM136#ifdef JPEG_USE_FILE_IO_CUSTOM137extern size_t jfread(void * __ptr, size_t __size, size_t __n, FILE * __stream);138extern size_t jfwrite(const void * __ptr, size_t __size, size_t __n, FILE * __stream);139extern int jfflush(FILE * __stream);140extern int jferror(FILE * __fp);141142#define JFREAD(file,buf,sizeofbuf) \143((size_t) jfread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))144#define JFWRITE(file,buf,sizeofbuf) \145((size_t) jfwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))146#define JFFLUSH(file) jfflush(file)147#define JFERROR(file) jferror(file)148#else149#define JFREAD(file,buf,sizeofbuf) \150((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))151#define JFWRITE(file,buf,sizeofbuf) \152((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))153#define JFFLUSH(file) fflush(file)154#define JFERROR(file) ferror(file)155#endif156#endif157158159