summaryrefslogtreecommitdiff
path: root/packages/pasjpeg/src/jinclude.pas
blob: fac33006bdc0e9b9a37d6b871bc0e6f93cdf06f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Unit jinclude;

{ This file exists to provide a single place to fix any problems with
  including the wrong system include files.  (Common problems are taken
  care of by the standard jconfig symbols, but on really weird systems
  you may have to edit this file.)

  NOTE: this file is NOT intended to be included by applications using the
  JPEG library.  Most applications need only include jpeglib.h. }

{ Original: jinclude.h Copyright (C) 1991-1994, Thomas G. Lane. }

interface

{$I jconfig.inc}

{ Include auto-config file to find out which system include files we need. }

uses
{$ifdef Delphi_Stream}
  classes,
{$endif}
  jmorecfg;

{ Nomssi:
  To write a dest/source manager that handle streams rather than files,
  you can edit the FILEptr definition and the JFREAD() and JFWRITE()
  functions in this unit, you don't need to change the default managers
  JDATASRC and JDATADST. }

{$ifdef Delphi_Stream}
type
  FILEptr = ^TStream;
{$else}
  {$ifdef Delphi_Jpeg}
  type
    FILEptr = TCustomMemoryStream;
  {$else}
  type
    FILEptr = ^File;
  {$endif}
{$endif}

{ We need the NULL macro and size_t typedef.
  On an ANSI-conforming system it is sufficient to include <stddef.h>.
  Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to
  pull in <sys/types.h> as well.
  Note that the core JPEG library does not require <stdio.h>;
  only the default error handler and data source/destination modules do.
  But we must pull it in because of the references to FILE in jpeglib.h.
  You can remove those references if you want to compile without <stdio.h>.}



{ We need memory copying and zeroing functions, plus strncpy().
  ANSI and System V implementations declare these in <string.h>.
  BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
  Some systems may declare memset and memcpy in <memory.h>.

  NOTE: we assume the size parameters to these functions are of type size_t.
  Change the casts in these macros if not! }

procedure MEMZERO(target : pointer; size : size_t);

procedure MEMCOPY(dest, src : pointer; size : size_t);

{function SIZEOF(object) : size_t;}

function JFREAD(fp : FILEptr; buf : pointer; sizeofbuf : size_t) : size_t;

function JFWRITE(fp : FILEptr; buf : pointer; sizeofbuf : size_t) : size_t;

implementation

procedure MEMZERO(target : pointer; size : size_t);
begin
  FillChar(target^, size, 0);
end;

procedure MEMCOPY(dest, src : pointer; size : size_t);
begin
  Move(src^, dest^, size);
end;

{ In ANSI C, and indeed any rational implementation, size_t is also the
  type returned by sizeof().  However, it seems there are some irrational
  implementations out there, in which sizeof() returns an int even though
  size_t is defined as long or unsigned long.  To ensure consistent results
  we always use this SIZEOF() macro in place of using sizeof() directly. }


{#define
  SIZEOF(object)  (size_t(sizeof(object))}


{ The modules that use fread() and fwrite() always invoke them through
  these macros.  On some systems you may need to twiddle the argument casts.
  CAUTION: argument order is different from underlying functions! }


function JFREAD(fp : FILEptr; buf : pointer; sizeofbuf : size_t) : size_t;
var
  count : uint;
begin
  {$ifdef Delphi_Stream}
  count := fp^.Read(buf^, sizeofbuf);
  {$else}
     blockread(fp^, buf^, sizeofbuf, count);
  {$endif}
  JFREAD := size_t(count);
end;

function JFWRITE(fp : FILEptr; buf : pointer; sizeofbuf : size_t) : size_t;
var
  count : uint;
begin
  {$ifdef Delphi_Stream}
  count := fp^.Write(buf^, sizeofbuf);
  {$else}
     blockwrite(fp^, buf^, sizeofbuf, count);
  {$endif}
  JFWRITE := size_t(count);
end;


end.