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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 2003 by the Free Pascal development team
fpImage base definitions.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{$mode objfpc}{$h+}
unit FPimage;
interface
uses sysutils, classes;
type
TFPCustomImageReader = class;
TFPCustomImageWriter = class;
TFPCustomImage = class;
FPImageException = class (exception);
TFPColor = record
red,green,blue,alpha : word;
end;
PFPColor = ^TFPColor;
TColorFormat = (cfMono,cfGray2,cfGray4,cfGray8,cfGray16,cfGray24,
cfGrayA8,cfGrayA16,cfGrayA32,
cfRGB15,cfRGB16,cfRGB24,cfRGB32,cfRGB48,
cfRGBA8,cfRGBA16,cfRGBA32,cfRGBA64,
cfBGR15,cfBGR16,cfBGR24,cfBGR32,cfBGR48,
cfABGR8,cfABGR16,cfABGR32,cfABGR64);
TColorData = qword;
PColorData = ^TColorData;
TDeviceColor = record
Fmt : TColorFormat;
Data : TColorData;
end;
{$ifdef CPU68K}
{ 1.0 m68k cpu compiler does not allow
types larger than 32k....
if we remove range checking all should be fine PM }
TFPColorArray = array [0..0] of TFPColor;
{$R-}
{$else not CPU68K}
TFPColorArray = array [0..(maxint-1) div sizeof(TFPColor)-1] of TFPColor;
{$endif CPU68K}
PFPColorArray = ^TFPColorArray;
TFPImgProgressStage = (psStarting, psRunning, psEnding);
TFPImgProgressEvent = procedure (Sender: TObject; Stage: TFPImgProgressStage;
PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
const Msg: AnsiString; var Continue : Boolean) of object;
// Delphi compatibility
TProgressStage = TFPImgProgressStage;
TProgressEvent = TFPImgProgressEvent;
TFPPalette = class
protected
FData : PFPColorArray;
FCount, FCapacity : integer;
procedure SetCount (Value:integer); virtual;
function GetCount : integer;
procedure SetColor (index:integer; const Value:TFPColor); virtual;
function GetColor (index:integer) : TFPColor;
procedure SetCapacity (ind : Integer);
procedure CheckIndex (index:integer); virtual;
procedure EnlargeData; virtual;
public
constructor Create (ACount : integer);
destructor Destroy; override;
procedure Build (Img : TFPCustomImage); virtual;
procedure Copy (APalette: TFPPalette); virtual;
procedure Merge (pal : TFPPalette); virtual;
function IndexOf (const AColor: TFPColor) : integer; virtual;
function Add (const Value: TFPColor) : integer; virtual;
procedure Clear; virtual;
property Color [Index : integer] : TFPColor read GetColor write SetColor; default;
property Count : integer read GetCount write SetCount;
property Capacity : integer read FCapacity write SetCapacity;
end;
TFPCustomImage = class(TPersistent)
private
FOnProgress : TFPImgProgressEvent;
FExtra : TStringlist;
FPalette : TFPPalette;
FHeight, FWidth : integer;
procedure SetHeight (Value : integer);
procedure SetWidth (Value : integer);
procedure SetExtra (const key:String; const AValue:string);
function GetExtra (const key:String) : string;
procedure SetExtraValue (index:integer; const AValue:string);
function GetExtraValue (index:integer) : string;
procedure SetExtraKey (index:integer; const AValue:string);
function GetExtraKey (index:integer) : string;
procedure CheckIndex (x,y:integer);
procedure CheckPaletteIndex (PalIndex:integer);
procedure SetColor (x,y:integer; const Value:TFPColor);
function GetColor (x,y:integer) : TFPColor;
procedure SetPixel (x,y:integer; Value:integer);
function GetPixel (x,y:integer) : integer;
function GetUsePalette : boolean;
protected
// Procedures to store the data. Implemented in descendants
procedure SetInternalColor (x,y:integer; const Value:TFPColor); virtual;
function GetInternalColor (x,y:integer) : TFPColor; virtual;
procedure SetInternalPixel (x,y:integer; Value:integer); virtual; abstract;
function GetInternalPixel (x,y:integer) : integer; virtual; abstract;
procedure SetUsePalette (Value:boolean);virtual;
procedure Progress(Sender: TObject; Stage: TProgressStage;
PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
const Msg: AnsiString; var Continue: Boolean); Virtual;
public
constructor create (AWidth,AHeight:integer); virtual;
destructor destroy; override;
procedure Assign(Source: TPersistent); override;
// Saving and loading
procedure LoadFromStream (Str:TStream; Handler:TFPCustomImageReader);
procedure LoadFromStream (Str:TStream);
procedure LoadFromFile (const filename:String; Handler:TFPCustomImageReader);
procedure LoadFromFile (const filename:String);
procedure SaveToStream (Str:TStream; Handler:TFPCustomImageWriter);
procedure SaveToFile (const filename:String; Handler:TFPCustomImageWriter);
procedure SaveToFile (const filename:String);
// Size and data
procedure SetSize (AWidth, AHeight : integer); virtual;
property Height : integer read FHeight write SetHeight;
property Width : integer read FWidth write SetWidth;
property Colors [x,y:integer] : TFPColor read GetColor write SetColor; default;
// Use of palette for colors
property UsePalette : boolean read GetUsePalette write SetUsePalette;
property Palette : TFPPalette read FPalette;
property Pixels [x,y:integer] : integer read GetPixel write SetPixel;
// Info unrelated with the image representation
property Extra [const key:string] : string read GetExtra write SetExtra;
property ExtraValue [index:integer] : string read GetExtraValue write SetExtraValue;
property ExtraKey [index:integer] : string read GetExtraKey write SetExtraKey;
procedure RemoveExtra (const key:string);
function ExtraCount : integer;
property OnProgress: TFPImgProgressEvent read FOnProgress write FOnProgress;
end;
TFPCustomImageClass = class of TFPCustomImage;
{$ifdef CPU68K}
{ 1.0 m68k cpu compiler does not allow
types larger than 32k....
if we remove range checking all should be fine PM }
TFPIntegerArray = array [0..0] of integer;
{$R-}
{$else not CPU68K}
TFPIntegerArray = array [0..(maxint-1) div sizeof(integer)-1] of integer;
{$endif CPU68K}
PFPIntegerArray = ^TFPIntegerArray;
TFPMemoryImage = class (TFPCustomImage)
private
function GetInternalColor(x,y:integer):TFPColor;override;
procedure SetInternalColor (x,y:integer; const Value:TFPColor);override;
procedure SetUsePalette (Value:boolean);override;
protected
FData : PFPIntegerArray;
procedure SetInternalPixel (x,y:integer; Value:integer); override;
function GetInternalPixel (x,y:integer) : integer; override;
public
constructor create (AWidth,AHeight:integer); override;
destructor destroy; override;
procedure SetSize (AWidth, AHeight : integer); override;
end;
TFPCustomImageHandler = class
private
FOnProgress : TFPImgProgressEvent;
FStream : TStream;
FImage : TFPCustomImage;
protected
procedure Progress(Stage: TProgressStage; PercentDone: Byte; RedrawNow: Boolean; const R: TRect;
const Msg: AnsiString; var Continue: Boolean); Virtual;
property TheStream : TStream read FStream;
property TheImage : TFPCustomImage read FImage;
public
constructor Create; virtual;
Property OnProgress : TFPImgProgressEvent Read FOnProgress Write FOnProgress;
end;
TFPCustomImageReader = class (TFPCustomImageHandler)
private
FDefImageClass:TFPCustomImageClass;
protected
procedure InternalRead (Str:TStream; Img:TFPCustomImage); virtual; abstract;
function InternalCheck (Str:TStream) : boolean; virtual; abstract;
public
constructor Create; override;
function ImageRead (Str:TStream; Img:TFPCustomImage) : TFPCustomImage;
// reads image
function CheckContents (Str:TStream) : boolean;
// Gives True if contents is readable
property DefaultImageClass : TFPCustomImageClass read FDefImageClass write FDefImageClass;
// Image Class to create when no img is given for reading
end;
TFPCustomImageReaderClass = class of TFPCustomImageReader;
TFPCustomImageWriter = class (TFPCustomImageHandler)
protected
procedure InternalWrite (Str:TStream; Img:TFPCustomImage); virtual; abstract;
public
procedure ImageWrite (Str:TStream; Img:TFPCustomImage);
// writes given image to stream
end;
TFPCustomImageWriterClass = class of TFPCustomImageWriter;
TIHData = class
private
FExtention, FTypeName, FDefaultExt : string;
FReader : TFPCustomImageReaderClass;
FWriter : TFPCustomImageWriterClass;
end;
TImageHandlersManager = class
private
FData : TList;
function GetReader (const TypeName:string) : TFPCustomImageReaderClass;
function GetWriter (const TypeName:string) : TFPCustomImageWriterClass;
function GetExt (const TypeName:string) : string;
function GetDefExt (const TypeName:string) : string;
function GetTypeName (index:integer) : string;
function GetData (const ATypeName:string) : TIHData;
function GetData (index : integer) : TIHData;
function GetCount : integer;
public
constructor Create;
destructor Destroy; override;
procedure RegisterImageHandlers (const ATypeName,TheExtentions:string;
AReader:TFPCustomImageReaderClass; AWriter:TFPCustomImageWriterClass);
procedure RegisterImageReader (const ATypeName,TheExtentions:string;
AReader:TFPCustomImageReaderClass);
procedure RegisterImageWriter (const ATypeName,TheExtentions:string;
AWriter:TFPCustomImageWriterClass);
property Count : integer read GetCount;
property ImageReader [const TypeName:string] : TFPCustomImageReaderClass read GetReader;
property ImageWriter [const TypeName:string] : TFPCustomImageWriterClass read GetWriter;
property Extentions [const TypeName:string] : string read GetExt;
property DefaultExtention [const TypeName:string] : string read GetDefExt;
property TypeNames [index:integer] : string read GetTypeName;
end;
{function ShiftAndFill (initial:word; CorrectBits:byte):word;
function FillOtherBits (initial:word;CorrectBits:byte):word;
}
function CalculateGray (const From : TFPColor) : word;
(*
function ConvertColor (const From : TDeviceColor) : TFPColor;
function ConvertColor (const From : TColorData; FromFmt:TColorFormat) : TFPColor;
function ConvertColorToData (const From : TFPColor; Fmt : TColorFormat) : TColorData;
function ConvertColorToData (const From : TDeviceColor; Fmt : TColorFormat) : TColorData;
function ConvertColor (const From : TFPColor; Fmt : TColorFormat) : TDeviceColor;
function ConvertColor (const From : TDeviceColor; Fmt : TColorFormat) : TDeviceColor;
*)
function AlphaBlend(color1, color2: TFPColor): TFPColor;
function FPColor (r,g,b,a:word) : TFPColor;
function FPColor (r,g,b:word) : TFPColor;
{$ifdef debug}function MakeHex (n:TColordata;nr:byte): string;{$endif}
operator = (const c,d:TFPColor) : boolean;
operator or (const c,d:TFPColor) : TFPColor;
operator and (const c,d:TFPColor) : TFPColor;
operator xor (const c,d:TFPColor) : TFPColor;
function CompareColors(const Color1, Color2: TFPColor): integer;
var ImageHandlers : TImageHandlersManager;
type
TErrorTextIndices = (
StrInvalidIndex,
StrNoImageToWrite,
StrNoFile,
StrNoStream,
StrPalette,
StrImageX,
StrImageY,
StrImageExtra,
StrTypeAlreadyExist,
StrTypeReaderAlreadyExist,
StrTypeWriterAlreadyExist,
StrCantDetermineType,
StrNoCorrectReaderFound,
StrReadWithError,
StrWriteWithError,
StrNoPaletteAvailable
);
const
// MG: ToDo: move to implementation and add a function to map to resourcestrings
ErrorText : array[TErrorTextIndices] of string =
('Invalid %s index %d',
'No image to write',
'File "%s" does not exist',
'No stream to write to',
'palette',
'horizontal pixel',
'vertical pixel',
'extra',
'Image type "%s" already exists',
'Image type "%s" already has a reader class',
'Image type "%s" already has a writer class',
'Error while determining image type of stream: %s',
'Can''t determine image type of stream',
'Error while reading stream: %s',
'Error while writing stream: %s',
'No palette available'
);
{$i fpcolors.inc}
type
TGrayConvMatrix = record
red, green, blue : single;
end;
var
GrayConvMatrix : TGrayConvMatrix;
const
GCM_NTSC : TGrayConvMatrix = (red:0.299; green:0.587; blue:0.114);
GCM_JPEG : TGrayConvMatrix = (red:0.299; green:0.587; blue:0.114);
GCM_Mathematical : TGrayConvMatrix = (red:0.334; green:0.333; blue:0.333);
GCM_Photoshop : TGrayConvMatrix = (red:0.213; green:0.715; blue:0.072);
function CreateBlackAndWhitePalette : TFPPalette;
function CreateWebSafePalette : TFPPalette;
function CreateGrayScalePalette : TFPPalette;
function CreateVGAPalette : TFPPalette;
Type
TFPCompactImgDesc = record
Gray: boolean; // true = red=green=blue, false: a RGB image
Depth: word; // 8 or 16 bit
HasAlpha: boolean; // has alpha channel
end;
{ TFPCompactImgBase }
TFPCompactImgBase = class(TFPCustomImage)
private
FDesc: TFPCompactImgDesc;
public
property Desc: TFPCompactImgDesc read FDesc;
end;
TFPCompactImgBaseClass = class of TFPCompactImgBase;
{ TFPCompactImgGray16Bit }
TFPCompactImgGray16Bit = class(TFPCompactImgBase)
protected
FData: PWord;
function GetInternalColor(x, y: integer): TFPColor; override;
function GetInternalPixel({%H-}x, {%H-}y: integer): integer; override;
procedure SetInternalColor (x, y: integer; const Value: TFPColor); override;
procedure SetInternalPixel({%H-}x, {%H-}y: integer; {%H-}Value: integer); override;
public
constructor Create(AWidth, AHeight: integer); override;
destructor Destroy; override;
procedure SetSize(AWidth, AHeight: integer); override;
end;
TFPCompactImgGrayAlpha16BitValue = packed record
g,a: word;
end;
PFPCompactImgGrayAlpha16BitValue = ^TFPCompactImgGrayAlpha16BitValue;
{ TFPCompactImgGrayAlpha16Bit }
TFPCompactImgGrayAlpha16Bit = class(TFPCompactImgBase)
protected
FData: PFPCompactImgGrayAlpha16BitValue;
function GetInternalColor(x, y: integer): TFPColor; override;
function GetInternalPixel({%H-}x, {%H-}y: integer): integer; override;
procedure SetInternalColor (x, y: integer; const Value: TFPColor); override;
procedure SetInternalPixel({%H-}x, {%H-}y: integer; {%H-}Value: integer); override;
public
constructor Create(AWidth, AHeight: integer); override;
destructor Destroy; override;
procedure SetSize(AWidth, AHeight: integer); override;
end;
{ TFPCompactImgGray8Bit }
TFPCompactImgGray8Bit = class(TFPCompactImgBase)
protected
FData: PByte;
function GetInternalColor(x, y: integer): TFPColor; override;
function GetInternalPixel({%H-}x, {%H-}y: integer): integer; override;
procedure SetInternalColor (x, y: integer; const Value: TFPColor); override;
procedure SetInternalPixel({%H-}x, {%H-}y: integer; {%H-}Value: integer); override;
public
constructor Create(AWidth, AHeight: integer); override;
destructor Destroy; override;
procedure SetSize(AWidth, AHeight: integer); override;
end;
TFPCompactImgGrayAlpha8BitValue = packed record
g,a: byte;
end;
PFPCompactImgGrayAlpha8BitValue = ^TFPCompactImgGrayAlpha8BitValue;
{ TFPCompactImgGrayAlpha8Bit }
TFPCompactImgGrayAlpha8Bit = class(TFPCompactImgBase)
protected
FData: PFPCompactImgGrayAlpha8BitValue;
function GetInternalColor(x, y: integer): TFPColor; override;
function GetInternalPixel({%H-}x, {%H-}y: integer): integer; override;
procedure SetInternalColor (x, y: integer; const Value: TFPColor); override;
procedure SetInternalPixel({%H-}x, {%H-}y: integer; {%H-}Value: integer); override;
public
constructor Create(AWidth, AHeight: integer); override;
destructor Destroy; override;
procedure SetSize(AWidth, AHeight: integer); override;
end;
TFPCompactImgRGBA8BitValue = packed record
r,g,b,a: byte;
end;
PFPCompactImgRGBA8BitValue = ^TFPCompactImgRGBA8BitValue;
{ TFPCompactImgRGBA8Bit }
TFPCompactImgRGBA8Bit = class(TFPCompactImgBase)
protected
FData: PFPCompactImgRGBA8BitValue;
function GetInternalColor(x, y: integer): TFPColor; override;
function GetInternalPixel({%H-}x, {%H-}y: integer): integer; override;
procedure SetInternalColor (x, y: integer; const Value: TFPColor); override;
procedure SetInternalPixel({%H-}x, {%H-}y: integer; {%H-}Value: integer); override;
public
constructor Create(AWidth, AHeight: integer); override;
destructor Destroy; override;
procedure SetSize(AWidth, AHeight: integer); override;
end;
TFPCompactImgRGB8BitValue = packed record
r,g,b: byte;
end;
PFPCompactImgRGB8BitValue = ^TFPCompactImgRGB8BitValue;
{ TFPCompactImgRGB8Bit }
TFPCompactImgRGB8Bit = class(TFPCompactImgBase)
protected
FData: PFPCompactImgRGB8BitValue;
function GetInternalColor(x, y: integer): TFPColor; override;
function GetInternalPixel({%H-}x, {%H-}y: integer): integer; override;
procedure SetInternalColor (x, y: integer; const Value: TFPColor); override;
procedure SetInternalPixel({%H-}x, {%H-}y: integer; {%H-}Value: integer); override;
public
constructor Create(AWidth, AHeight: integer); override;
destructor Destroy; override;
procedure SetSize(AWidth, AHeight: integer); override;
end;
TFPCompactImgRGB16BitValue = packed record
r,g,b: word;
end;
PFPCompactImgRGB16BitValue = ^TFPCompactImgRGB16BitValue;
{ TFPCompactImgRGB16Bit }
TFPCompactImgRGB16Bit = class(TFPCompactImgBase)
protected
FData: PFPCompactImgRGB16BitValue;
function GetInternalColor(x, y: integer): TFPColor; override;
function GetInternalPixel({%H-}x, {%H-}y: integer): integer; override;
procedure SetInternalColor (x, y: integer; const Value: TFPColor); override;
procedure SetInternalPixel({%H-}x, {%H-}y: integer; {%H-}Value: integer); override;
public
constructor Create(AWidth, AHeight: integer); override;
destructor Destroy; override;
procedure SetSize(AWidth, AHeight: integer); override;
end;
{ TFPCompactImgRGBA16Bit }
TFPCompactImgRGBA16Bit = class(TFPCompactImgBase)
protected
FData: PFPColor;
function GetInternalColor(x, y: integer): TFPColor; override;
function GetInternalPixel({%H-}x, {%H-}y: integer): integer; override;
procedure SetInternalColor (x, y: integer; const Value: TFPColor); override;
procedure SetInternalPixel({%H-}x, {%H-}y: integer; {%H-}Value: integer); override;
public
constructor Create(AWidth, AHeight: integer); override;
destructor Destroy; override;
procedure SetSize(AWidth, AHeight: integer); override;
end;
{ Create a descriptor to select a CompactImg class }
function GetFPCompactImgDesc(Gray: boolean; Depth: word; HasAlpha: boolean): TFPCompactImgDesc;
{ Returns a CompactImg class that fits the descriptor }
function GetFPCompactImgClass(const Desc: TFPCompactImgDesc): TFPCompactImgBaseClass;
{ Create a CompactImg with the descriptor }
function CreateFPCompactImg(const Desc: TFPCompactImgDesc; Width, Height: integer): TFPCustomImage;
{ Create a CompactImg with the same features as Img.
If Img is a TFPCompactImgBaseClass it will create that.
Otherwise it returns a CompactImg that fits the Img using GetMinimumPTDesc. }
function CreateCompatibleFPCompactImg(Img: TFPCustomImage; Width, Height: integer
): TFPCustomImage;
{ As CreateCompatibleFPCompactImg, but the image has always an alpha channel. }
function CreateCompatibleFPCompactImgWithAlpha(Img: TFPCustomImage;
Width, Height: integer): TFPCustomImage;
{ Returns the smallest descriptor that allows to store the Img.
It returns HasAlpha=false if all pixel are opaque.
It returns Gray=true if all red=green=blue.
It returns Depth=8 if all lo byte equals the hi byte or all lo bytes are 0.
To ignore rounding errors you can pass a FuzzyDepth. For example a FuzzyDepth
of 3 ignores the lower 3 bits when comparing. }
function GetMinimumPTDesc(Img: TFPCustomImage; FuzzyDepth: word = 4): TFPCompactImgDesc;
{ Create a smaller CompactImg with the same information as Img.
Pass FreeImg=true to call Img.Free }
function GetMinimumFPCompactImg(Img: TFPCustomImage; FreeImg: boolean;
FuzzyDepth: word = 4): TFPCustomImage;
implementation
procedure FPImgError (Fmt:TErrorTextIndices; data : array of const);
begin
raise FPImageException.CreateFmt (ErrorText[Fmt],data);
end;
procedure FPImgError (Fmt:TErrorTextIndices);
begin
raise FPImageException.Create (ErrorText[Fmt]);
end;
{$i FPImage.inc}
{$i FPHandler.inc}
{$i FPPalette.inc}
{$i FPColCnv.inc}
{$i fpcompactimg.inc}
function FPColor (r,g,b:word) : TFPColor;
begin
with result do
begin
red := r;
green := g;
blue := b;
alpha := alphaOpaque;
end;
end;
function FPColor (r,g,b,a:word) : TFPColor;
begin
with result do
begin
red := r;
green := g;
blue := b;
alpha := a;
end;
end;
operator = (const c,d:TFPColor) : boolean;
begin
result := (c.Red = d.Red) and
(c.Green = d.Green) and
(c.Blue = d.Blue) and
(c.Alpha = d.Alpha);
end;
function GetFullColorData (color:TFPColor) : TColorData;
begin
result := PColorData(@color)^;
end;
function SetFullColorData (color:TColorData) : TFPColor;
begin
result := PFPColor (@color)^;
end;
operator or (const c,d:TFPColor) : TFPColor;
begin
result := SetFullColorData(GetFullColorData(c) OR GetFullColorData(d));
end;
operator and (const c,d:TFPColor) : TFPColor;
begin
result := SetFullColorData(GetFullColorData(c) AND GetFullColorData(d));
end;
operator xor (const c,d:TFPColor) : TFPColor;
begin
result := SetFullColorData(GetFullColorData(c) XOR GetFullColorData(d));
end;
{$ifdef debug}
function MakeHex (n:TColordata;nr:byte): string;
const hexnums : array[0..15] of char =
('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
var r : integer;
begin
result := '';
for r := 0 to nr-1 do
begin
result := hexnums[n and $F] + result;
n := n shr 4;
if ((r+1) mod 4) = 0 then
result := ' ' + result;
end;
end;
{$endif}
initialization
ImageHandlers := TImageHandlersManager.Create;
GrayConvMatrix := GCM_JPEG;
// Following lines are here because the compiler 1.0 can't work with int64 constants
(* ColorBits [cfRGB48,1] := ColorBits [cfRGB48,1] shl 16;
ColorBits [cfRGBA64,1] := ColorBits [cfRGBA64,1] shl 32;
ColorBits [cfRGBA64,2] := ColorBits [cfRGBA64,2] shl 16;
ColorBits [cfABGR64,0] := ColorBits [cfABGR64,0] shl 32;
ColorBits [cfABGR64,3] := ColorBits [cfABGR64,3] shl 16;
ColorBits [cfBGR48,3] := ColorBits [cfBGR48,3] shl 16;
PrepareBitMasks;*)
finalization
ImageHandlers.Free;
end.
|