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