DEADSOFTWARE

added Vampyre Imaging Library; now textures can be in various formats, including...
[d2df-sdl.git] / src / lib / vampimg / ImagingExport.pas
1 {
2 $Id: ImagingExport.pas 173 2009-09-04 17:05:52Z galfar $
3 Vampyre Imaging Library
4 by Marek Mauder
5 http://imaginglib.sourceforge.net
7 The contents of this file are used with permission, subject to the Mozilla
8 Public License Version 1.1 (the "License"); you may not use this file except
9 in compliance with the License. You may obtain a copy of the License at
10 http://www.mozilla.org/MPL/MPL-1.1.html
12 Software distributed under the License is distributed on an "AS IS" basis,
13 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 the specific language governing rights and limitations under the License.
16 Alternatively, the contents of this file may be used under the terms of the
17 GNU Lesser General Public License (the "LGPL License"), in which case the
18 provisions of the LGPL License are applicable instead of those above.
19 If you wish to allow use of your version of this file only under the terms
20 of the LGPL License and not to allow others to use your version of this file
21 under the MPL, indicate your decision by deleting the provisions above and
22 replace them with the notice and other provisions required by the LGPL
23 License. If you do not delete the provisions above, a recipient may use
24 your version of this file under either the MPL or the LGPL License.
26 For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html
27 }
29 { This function contains functions exported from Imaging dynamic link library.
30 All string are exported as PChars and all var parameters are exported
31 as pointers. All posible exceptions getting out of dll are catched.}
32 unit ImagingExport;
34 {$I ImagingOptions.inc}
36 interface
38 uses
39 ImagingTypes,
40 Imaging;
42 { Returns version of Imaging library. }
43 procedure ImGetVersion(var Major, Minor, Patch: LongInt); cdecl;
44 { Look at InitImage for details.}
45 procedure ImInitImage(var Image: TImageData); cdecl;
46 { Look at NewImage for details.}
47 function ImNewImage(Width, Height: LongInt; Format: TImageFormat;
48 var Image: TImageData): Boolean; cdecl;
49 { Look at TestImage for details.}
50 function ImTestImage(var Image: TImageData): Boolean; cdecl;
51 { Look at FreeImage for details.}
52 function ImFreeImage(var Image: TImageData): Boolean; cdecl;
53 { Look at DetermineFileFormat for details. Ext should have enough space for
54 result file extension.}
55 function ImDetermineFileFormat(FileName, Ext: PAnsiChar): Boolean; cdecl;
56 { Look at DetermineMemoryFormat for details. Ext should have enough space for
57 result file extension.}
58 function ImDetermineMemoryFormat(Data: Pointer; Size: LongInt; Ext: PAnsiChar): Boolean; cdecl;
59 { Look at IsFileFormatSupported for details.}
60 function ImIsFileFormatSupported(FileName: PAnsiChar): Boolean; cdecl;
61 { Look at EnumFileFormats for details.}
62 function ImEnumFileFormats(var Index: LongInt; Name, DefaultExt, Masks: PAnsiChar;
63 var CanSave, IsMultiImageFormat: Boolean): Boolean; cdecl;
65 { Inits image list.}
66 function ImInitImageList(Size: LongInt; var ImageList: TImageDataList): Boolean; cdecl;
67 { Returns size of image list.}
68 function ImGetImageListSize(ImageList: TImageDataList): LongInt; cdecl;
69 { Returns image list's element at given index. Output image is not cloned it's
70 Bits point to Bits in list => do not free OutImage.}
71 function ImGetImageListElement(ImageList: TImageDataList; Index: LongInt;
72 var OutImage: TImageData): Boolean; cdecl;
73 { Sets size of image list.}
74 function ImSetImageListSize(ImageList: TImageDataList; NewSize: LongInt): Boolean; cdecl;
75 { Sets image list element at given index. Input image is not cloned - image in
76 list will point to InImage's Bits.}
77 function ImSetImageListElement(ImageList: TImageDataList; Index: LongInt;
78 const InImage: TImageData): Boolean; cdecl;
79 { Returns True if all images in list pass ImTestImage test. }
80 function ImTestImagesInList(ImageList: TImageDataList): Boolean; cdecl;
81 { Frees image list and all images in it.}
82 function ImFreeImageList(var ImageList: TImageDataList): Boolean; cdecl;
84 { Look at LoadImageFromFile for details.}
85 function ImLoadImageFromFile(FileName: PAnsiChar; var Image: TImageData): Boolean; cdecl;
86 { Look at LoadImageFromMemory for details.}
87 function ImLoadImageFromMemory(Data: Pointer; Size: LongInt; var Image: TImageData): Boolean; cdecl;
88 { Look at LoadMultiImageFromFile for details.}
89 function ImLoadMultiImageFromFile(FileName: PAnsiChar; var ImageList: TImageDataList): Boolean; cdecl;
90 { Look at LoadMultiImageFromMemory for details.}
91 function ImLoadMultiImageFromMemory(Data: Pointer; Size: LongInt;
92 var ImageList: TImageDataList): Boolean; cdecl;
94 { Look at SaveImageToFile for details.}
95 function ImSaveImageToFile(FileName: PAnsiChar; const Image: TImageData): Boolean; cdecl;
96 { Look at SaveImageToMemory for details.}
97 function ImSaveImageToMemory(Ext: PAnsiChar; Data: Pointer; var Size: LongInt;
98 const Image: TImageData): Boolean; cdecl;
99 { Look at SaveMultiImageToFile for details.}
100 function ImSaveMultiImageToFile(FileName: PAnsiChar; ImageList: TImageDataList): Boolean; cdecl;
101 { Look at SaveMultiImageToMemory for details.}
102 function ImSaveMultiImageToMemory(Ext: PAnsiChar; Data: Pointer; Size: PLongInt;
103 ImageList: TImageDataList): Boolean; cdecl;
105 { Look at CloneImage for details.}
106 function ImCloneImage(const Image: TImageData; var Clone: TImageData): Boolean; cdecl;
107 { Look at ConvertImage for details.}
108 function ImConvertImage(var Image: TImageData; DestFormat: TImageFormat): Boolean; cdecl;
109 { Look at FlipImage for details.}
110 function ImFlipImage(var Image: TImageData): Boolean; cdecl;
111 { Look at MirrorImage for details.}
112 function ImMirrorImage(var Image: TImageData): Boolean; cdecl;
113 { Look at ResizeImage for details.}
114 function ImResizeImage(var Image: TImageData; NewWidth, NewHeight: LongInt;
115 Filter: TResizeFilter): Boolean; cdecl;
116 { Look at SwapChannels for details.}
117 function ImSwapChannels(var Image: TImageData; SrcChannel, DstChannel: LongInt): Boolean; cdecl;
118 { Look at ReduceColors for details.}
119 function ImReduceColors(var Image: TImageData; MaxColors: LongInt): Boolean; cdecl;
120 { Look at GenerateMipMaps for details.}
121 function ImGenerateMipMaps(const Image: TImageData; Levels: LongInt;
122 var MipMaps: TImageDataList): Boolean; cdecl;
123 { Look at MapImageToPalette for details.}
124 function ImMapImageToPalette(var Image: TImageData; Pal: PPalette32;
125 Entries: LongInt): Boolean; cdecl;
126 { Look at SplitImage for details.}
127 function ImSplitImage(var Image: TImageData; var Chunks: TImageDataList;
128 ChunkWidth, ChunkHeight: LongInt; var XChunks, YChunks: LongInt;
129 PreserveSize: Boolean; Fill: Pointer): Boolean; cdecl;
130 { Look at MakePaletteForImages for details.}
131 function ImMakePaletteForImages(Images: TImageDataList; Pal: PPalette32;
132 MaxColors: LongInt; ConvertImages: Boolean): Boolean; cdecl;
133 { Look at RotateImage for details.}
134 function ImRotateImage(var Image: TImageData; Angle: Single): Boolean; cdecl;
136 { Look at CopyRect for details.}
137 function ImCopyRect(const SrcImage: TImageData; SrcX, SrcY, Width, Height: LongInt;
138 var DstImage: TImageData; DstX, DstY: LongInt): Boolean; cdecl;
139 { Look at FillRect for details.}
140 function ImFillRect(var Image: TImageData; X, Y, Width, Height: LongInt;
141 Fill: Pointer): Boolean; cdecl;
142 { Look at ReplaceColor for details.}
143 function ImReplaceColor(var Image: TImageData; X, Y, Width, Height: LongInt;
144 OldPixel, NewPixel: Pointer): Boolean; cdecl;
145 { Look at StretchRect for details.}
146 function ImStretchRect(const SrcImage: TImageData; SrcX, SrcY, SrcWidth,
147 SrcHeight: LongInt; var DstImage: TImageData; DstX, DstY, DstWidth,
148 DstHeight: LongInt; Filter: TResizeFilter): Boolean; cdecl;
149 { Look at GetPixelDirect for details.}
150 procedure ImGetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer); cdecl;
151 { Look at SetPixelDirect for details.}
152 procedure ImSetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer); cdecl;
153 { Look at GetPixel32 for details.}
154 function ImGetPixel32(const Image: TImageData; X, Y: LongInt): TColor32Rec; cdecl;
155 { Look at SetPixel32 for details.}
156 procedure ImSetPixel32(const Image: TImageData; X, Y: LongInt; const Color: TColor32Rec); cdecl;
157 { Look at GetPixelFP for details.}
158 function ImGetPixelFP(const Image: TImageData; X, Y: LongInt): TColorFPRec; cdecl;
159 { Look at SetPixelFP for details.}
160 procedure ImSetPixelFP(const Image: TImageData; X, Y: LongInt; const Color: TColorFPRec); cdecl;
162 { Look at NewPalette for details.}
163 function ImNewPalette(Entries: LongInt; var Pal: PPalette32): Boolean; cdecl;
164 { Look at FreePalette for details.}
165 function ImFreePalette(var Pal: PPalette32): Boolean; cdecl;
166 { Look at CopyPalette for details.}
167 function ImCopyPalette(SrcPal, DstPal: PPalette32; SrcIdx, DstIdx, Count: LongInt): Boolean; cdecl;
168 { Look at FindColor for details.}
169 function ImFindColor(Pal: PPalette32; Entries: LongInt; Color: TColor32): LongInt; cdecl;
170 { Look at FillGrayscalePalette for details.}
171 function ImFillGrayscalePalette(Pal: PPalette32; Entries: LongInt): Boolean; cdecl;
172 { Look at FillCustomPalette for details.}
173 function ImFillCustomPalette(Pal: PPalette32; Entries: LongInt; RBits, GBits,
174 BBits: Byte; Alpha: Byte): Boolean; cdecl;
175 { Look at SwapChannelsOfPalette for details.}
176 function ImSwapChannelsOfPalette(Pal: PPalette32; Entries, SrcChannel,
177 DstChannel: LongInt): Boolean; cdecl;
179 { Look at SetOption for details.}
180 function ImSetOption(OptionId, Value: LongInt): Boolean; cdecl;
181 { Look at GetOption for details.}
182 function ImGetOption(OptionId: LongInt): LongInt; cdecl;
183 { Look at PushOptions for details.}
184 function ImPushOptions: Boolean; cdecl;
185 { Look at PopOptions for details.}
186 function ImPopOptions: Boolean; cdecl;
188 { Look at GetImageFormatInfo for details.}
189 function ImGetImageFormatInfo(Format: TImageFormat; var Info: TImageFormatInfo): Boolean; cdecl;
190 { Look at GetPixelsSize for details.}
191 function ImGetPixelsSize(Format: TImageFormat; Width, Height: LongInt): LongInt; cdecl;
193 { Look at SetUserFileIO for details.}
194 procedure ImSetUserFileIO(OpenReadProc: TOpenReadProc; OpenWriteProc:
195 TOpenWriteProc; CloseProc: TCloseProc; EofProc: TEofProc; SeekProc: TSeekProc;
196 TellProc: TTellProc; ReadProc: TReadProc; WriteProc: TWriteProc); cdecl;
197 { Look at ResetFileIO for details.}
198 procedure ImResetFileIO; cdecl;
200 { These are only for documentation generation reasons.}
201 { Loads Imaging functions from dll/so library.}
202 function ImLoadLibrary: Boolean;
203 { Frees Imaging functions loaded from dll/so and releases library.}
204 function ImFreeLibrary: Boolean;
206 implementation
208 uses
209 SysUtils,
210 ImagingUtility;
212 function ImLoadLibrary: Boolean; begin Result := True; end;
213 function ImFreeLibrary: Boolean; begin Result := True; end;
215 type
216 TInternalList = record
217 List: TDynImageDataArray;
218 end;
219 PInternalList = ^TInternalList;
221 procedure ImGetVersion(var Major, Minor, Patch: LongInt);
222 begin
223 Major := ImagingVersionMajor;
224 Minor := ImagingVersionMinor;
225 Patch := ImagingVersionPatch;
226 end;
228 procedure ImInitImage(var Image: TImageData);
229 begin
230 try
231 Imaging.InitImage(Image);
232 except
233 end;
234 end;
236 function ImNewImage(Width, Height: LongInt; Format: TImageFormat;
237 var Image: TImageData): Boolean;
238 begin
239 try
240 Result := Imaging.NewImage(Width, Height, Format, Image);
241 except
242 Result := False;
243 end;
244 end;
246 function ImTestImage(var Image: TImageData): Boolean;
247 begin
248 try
249 Result := Imaging.TestImage(Image);
250 except
251 Result := False;
252 end;
253 end;
255 function ImFreeImage(var Image: TImageData): Boolean;
256 begin
257 try
258 Imaging.FreeImage(Image);
259 Result := True;
260 except
261 Result := False;
262 end;
263 end;
265 function ImDetermineFileFormat(FileName, Ext: PAnsiChar): Boolean;
266 var
267 S: string;
268 begin
269 try
270 S := Imaging.DetermineFileFormat(FileName);
271 Result := S <> '';
272 StrCopy(Ext, PAnsiChar(AnsiString(S)));
273 except
274 Result := False;
275 end;
276 end;
278 function ImDetermineMemoryFormat(Data: Pointer; Size: LongInt; Ext: PAnsiChar): Boolean;
279 var
280 S: string;
281 begin
282 try
283 S := Imaging.DetermineMemoryFormat(Data, Size);
284 Result := S <> '';
285 StrCopy(Ext, PAnsiChar(AnsiString(S)));
286 except
287 Result := False;
288 end;
289 end;
291 function ImIsFileFormatSupported(FileName: PAnsiChar): Boolean;
292 begin
293 try
294 Result := Imaging.IsFileFormatSupported(FileName);
295 except
296 Result := False;
297 end;
298 end;
300 function ImEnumFileFormats(var Index: LongInt; Name, DefaultExt, Masks: PAnsiChar;
301 var CanSave, IsMultiImageFormat: Boolean): Boolean;
302 var
303 StrName, StrDefaultExt, StrMasks: string;
304 begin
305 try
306 Result := Imaging.EnumFileFormats(Index, StrName, StrDefaultExt, StrMasks, CanSave,
307 IsMultiImageFormat);
308 StrCopy(Name, PAnsiChar(AnsiString(StrName)));
309 StrCopy(DefaultExt, PAnsiChar(AnsiString(StrDefaultExt)));
310 StrCopy(Masks, PAnsiChar(AnsiString(StrMasks)));
311 except
312 Result := False;
313 end;
314 end;
316 function ImInitImageList(Size: LongInt; var ImageList: TImageDataList): Boolean;
317 var
318 Int: PInternalList;
319 begin
320 try
321 try
322 ImFreeImageList(ImageList);
323 except
324 end;
325 New(Int);
326 SetLength(Int.List, Size);
327 ImageList := TImageDataList(Int);
328 Result := True;
329 except
330 Result := False;
331 ImageList := nil;
332 end;
333 end;
335 function ImGetImageListSize(ImageList: TImageDataList): LongInt;
336 begin
337 try
338 Result := Length(PInternalList(ImageList).List);
339 except
340 Result := -1;
341 end;
342 end;
344 function ImGetImageListElement(ImageList: TImageDataList; Index: LongInt;
345 var OutImage: TImageData): Boolean;
346 begin
347 try
348 Index := ClampInt(Index, 0, Length(PInternalList(ImageList).List) - 1);
349 ImCloneImage(PInternalList(ImageList).List[Index], OutImage);
350 Result := True;
351 except
352 Result := False;
353 end;
354 end;
356 function ImSetImageListSize(ImageList: TImageDataList; NewSize: LongInt):
357 Boolean;
358 var
359 I, OldSize: LongInt;
360 begin
361 try
362 OldSize := Length(PInternalList(ImageList).List);
363 if NewSize < OldSize then
364 for I := NewSize to OldSize - 1 do
365 Imaging.FreeImage(PInternalList(ImageList).List[I]);
366 SetLength(PInternalList(ImageList).List, NewSize);
367 Result := True;
368 except
369 Result := False;
370 end;
371 end;
373 function ImSetImageListElement(ImageList: TImageDataList; Index: LongInt;
374 const InImage: TImageData): Boolean;
375 begin
376 try
377 Index := ClampInt(Index, 0, Length(PInternalList(ImageList).List) - 1);
378 ImCloneImage(InImage, PInternalList(ImageList).List[Index]);
379 Result := True;
380 except
381 Result := False;
382 end;
383 end;
385 function ImTestImagesInList(ImageList: TImageDataList): Boolean;
386 var
387 I: LongInt;
388 Arr: TDynImageDataArray;
389 begin
390 Arr := nil;
391 try
392 Arr := PInternalList(ImageList).List;
393 Result := True;
394 for I := 0 to Length(Arr) - 1 do
395 begin
396 Result := Result and Imaging.TestImage(Arr[I]);
397 if not Result then Break;
398 end;
399 except
400 Result := False;
401 end;
402 end;
404 function ImFreeImageList(var ImageList: TImageDataList): Boolean;
405 var
406 Int: PInternalList;
407 begin
408 try
409 if ImageList <> nil then
410 begin
411 Int := PInternalList(ImageList);
412 FreeImagesInArray(Int.List);
413 Dispose(Int);
414 ImageList := nil;
415 end;
416 Result := True;
417 except
418 Result := False;
419 end;
420 end;
422 function ImLoadImageFromFile(FileName: PAnsiChar; var Image: TImageData): Boolean;
423 begin
424 try
425 Result := Imaging.LoadImageFromFile(FileName, Image);
426 except
427 Result := False;
428 end;
429 end;
431 function ImLoadImageFromMemory(Data: Pointer; Size: LongInt; var Image: TImageData): Boolean;
432 begin
433 try
434 Result := Imaging.LoadImageFromMemory(Data, Size, Image);
435 except
436 Result := False;
437 end;
438 end;
440 function ImLoadMultiImageFromFile(FileName: PAnsiChar; var ImageList: TImageDataList):
441 Boolean;
442 begin
443 try
444 ImInitImageList(0, ImageList);
445 Result := Imaging.LoadMultiImageFromFile(FileName,
446 PInternalList(ImageList).List);
447 except
448 Result := False;
449 end;
450 end;
452 function ImLoadMultiImageFromMemory(Data: Pointer; Size: LongInt;
453 var ImageList: TImageDataList): Boolean;
454 begin
455 try
456 ImInitImageList(0, ImageList);
457 Result := Imaging.LoadMultiImageFromMemory(Data, Size, PInternalList(ImageList).List);
458 except
459 Result := False;
460 end;
461 end;
463 function ImSaveImageToFile(FileName: PAnsiChar; const Image: TImageData): Boolean;
464 begin
465 try
466 Result := Imaging.SaveImageToFile(FileName, Image);
467 except
468 Result := False;
469 end;
470 end;
472 function ImSaveImageToMemory(Ext: PAnsiChar; Data: Pointer; var Size: LongInt;
473 const Image: TImageData): Boolean;
474 begin
475 try
476 Result := Imaging.SaveImageToMemory(Ext, Data, Size, Image);
477 except
478 Result := False;
479 end;
480 end;
482 function ImSaveMultiImageToFile(FileName: PAnsiChar;
483 ImageList: TImageDataList): Boolean;
484 begin
485 try
486 Result := Imaging.SaveMultiImageToFile(FileName,
487 PInternalList(ImageList).List);
488 except
489 Result := False;
490 end;
491 end;
493 function ImSaveMultiImageToMemory(Ext: PAnsiChar; Data: Pointer; Size: PLongInt;
494 ImageList: TImageDataList): Boolean;
495 begin
496 try
497 Result := Imaging.SaveMultiImageToMemory(Ext, Data, Size^,
498 PInternalList(ImageList).List);
499 except
500 Result := False;
501 end;
502 end;
504 function ImCloneImage(const Image: TImageData; var Clone: TImageData): Boolean;
505 begin
506 try
507 Result := Imaging.CloneImage(Image, Clone);
508 except
509 Result := False;
510 end;
511 end;
513 function ImConvertImage(var Image: TImageData; DestFormat: TImageFormat): Boolean;
514 begin
515 try
516 Result := Imaging.ConvertImage(Image, DestFormat);
517 except
518 Result := False;
519 end;
520 end;
522 function ImFlipImage(var Image: TImageData): Boolean;
523 begin
524 try
525 Result := Imaging.FlipImage(Image);
526 except
527 Result := False;
528 end;
529 end;
531 function ImMirrorImage(var Image: TImageData): Boolean;
532 begin
533 try
534 Result := Imaging.MirrorImage(Image);
535 except
536 Result := False;
537 end;
538 end;
540 function ImResizeImage(var Image: TImageData; NewWidth, NewHeight: LongInt;
541 Filter: TResizeFilter): Boolean;
542 begin
543 try
544 Result := Imaging.ResizeImage(Image, NewWidth, NewHeight, Filter);
545 except
546 Result := False;
547 end;
548 end;
550 function ImSwapChannels(var Image: TImageData; SrcChannel, DstChannel: LongInt):
551 Boolean;
552 begin
553 try
554 Result := Imaging.SwapChannels(Image, SrcChannel, DstChannel);
555 except
556 Result := False;
557 end;
558 end;
560 function ImReduceColors(var Image: TImageData; MaxColors: LongInt): Boolean;
561 begin
562 try
563 Result := Imaging.ReduceColors(Image, MaxColors);
564 except
565 Result := False;
566 end;
567 end;
569 function ImGenerateMipMaps(const Image: TImageData; Levels: LongInt;
570 var MipMaps: TImageDataList): Boolean;
571 begin
572 try
573 ImInitImageList(0, MipMaps);
574 Result := Imaging.GenerateMipMaps(Image, Levels,
575 PInternalList(MipMaps).List);
576 except
577 Result := False;
578 end;
579 end;
581 function ImMapImageToPalette(var Image: TImageData; Pal: PPalette32;
582 Entries: LongInt): Boolean;
583 begin
584 try
585 Result := Imaging.MapImageToPalette(Image, Pal, Entries);
586 except
587 Result := False;
588 end;
589 end;
591 function ImSplitImage(var Image: TImageData; var Chunks: TImageDataList;
592 ChunkWidth, ChunkHeight: LongInt; var XChunks, YChunks: LongInt;
593 PreserveSize: Boolean; Fill: Pointer): Boolean;
594 begin
595 try
596 ImInitImageList(0, Chunks);
597 Result := Imaging.SplitImage(Image, PInternalList(Chunks).List,
598 ChunkWidth, ChunkHeight, XChunks, YChunks, PreserveSize, Fill);
599 except
600 Result := False;
601 end;
602 end;
604 function ImMakePaletteForImages(Images: TImageDataList; Pal: PPalette32;
605 MaxColors: LongInt; ConvertImages: Boolean): Boolean;
606 begin
607 try
608 Result := Imaging.MakePaletteForImages(PInternalList(Images).List,
609 Pal, MaxColors, ConvertImages);
610 except
611 Result := False;
612 end;
613 end;
615 function ImRotateImage(var Image: TImageData; Angle: Single): Boolean;
616 begin
617 try
618 Result := Imaging.RotateImage(Image, Angle);
619 except
620 Result := False;
621 end;
622 end;
624 function ImCopyRect(const SrcImage: TImageData; SrcX, SrcY, Width, Height: LongInt;
625 var DstImage: TImageData; DstX, DstY: LongInt): Boolean; cdecl;
626 begin
627 try
628 Result := Imaging.CopyRect(SrcImage, SrcX, SrcY, Width, Height,
629 DstImage, DstX, DstY);
630 except
631 Result := False;
632 end;
633 end;
635 function ImFillRect(var Image: TImageData; X, Y, Width, Height: LongInt;
636 Fill: Pointer): Boolean;
637 begin
638 try
639 Result := Imaging.FillRect(Image, X, Y, Width, Height, Fill);
640 except
641 Result := False;
642 end;
643 end;
645 function ImReplaceColor(var Image: TImageData; X, Y, Width, Height: LongInt;
646 OldPixel, NewPixel: Pointer): Boolean;
647 begin
648 try
649 Result := Imaging.ReplaceColor(Image, X, Y, Width, Height, OldPixel, NewPixel);
650 except
651 Result := False;
652 end;
653 end;
655 function ImStretchRect(const SrcImage: TImageData; SrcX, SrcY, SrcWidth,
656 SrcHeight: LongInt; var DstImage: TImageData; DstX, DstY, DstWidth,
657 DstHeight: LongInt; Filter: TResizeFilter): Boolean; cdecl;
658 begin
659 try
660 Result := Imaging.StretchRect(SrcImage, SrcX, SrcY, SrcWidth, SrcHeight,
661 DstImage, DstX, DstY, DstWidth, DstHeight, Filter);
662 except
663 Result := False;
664 end;
665 end;
667 procedure ImGetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer);
668 begin
669 try
670 Imaging.GetPixelDirect(Image, X, Y, Pixel);
671 except
672 end;
673 end;
675 procedure ImSetPixelDirect(const Image: TImageData; X, Y: LongInt; Pixel: Pointer);
676 begin
677 try
678 Imaging.SetPixelDirect(Image, X, Y, Pixel);
679 except
680 end;
681 end;
683 function ImGetPixel32(const Image: TImageData; X, Y: LongInt): TColor32Rec; cdecl;
684 begin
685 try
686 Result := Imaging.GetPixel32(Image, X, Y);
687 except
688 Result.Color := 0;
689 end;
690 end;
692 procedure ImSetPixel32(const Image: TImageData; X, Y: LongInt; const Color: TColor32Rec);
693 begin
694 try
695 Imaging.SetPixel32(Image, X, Y, Color);
696 except
697 end;
698 end;
700 function ImGetPixelFP(const Image: TImageData; X, Y: LongInt): TColorFPRec; cdecl;
701 begin
702 try
703 Result := Imaging.GetPixelFP(Image, X, Y);
704 except
705 FillChar(Result, SizeOf(Result), 0);
706 end;
707 end;
709 procedure ImSetPixelFP(const Image: TImageData; X, Y: LongInt; const Color: TColorFPRec);
710 begin
711 try
712 Imaging.SetPixelFP(Image, X, Y, Color);
713 except
714 end;
715 end;
717 function ImNewPalette(Entries: LongInt; var Pal: PPalette32): Boolean;
718 begin
719 try
720 Imaging.NewPalette(Entries, Pal);
721 Result := True;
722 except
723 Result := False;
724 end;
725 end;
727 function ImFreePalette(var Pal: PPalette32): Boolean;
728 begin
729 try
730 Imaging.FreePalette(Pal);
731 Result := True;
732 except
733 Result := False;
734 end;
735 end;
737 function ImCopyPalette(SrcPal, DstPal: PPalette32; SrcIdx, DstIdx, Count: LongInt): Boolean;
738 begin
739 try
740 Imaging.CopyPalette(SrcPal, DstPal, SrcIdx, DstIdx, Count);
741 Result := True;
742 except
743 Result := False;
744 end;
745 end;
747 function ImFindColor(Pal: PPalette32; Entries: LongInt; Color: TColor32): LongInt;
748 begin
749 try
750 Result := Imaging.FindColor(Pal, Entries, Color);
751 except
752 Result := 0;
753 end;
754 end;
756 function ImFillGrayscalePalette(Pal: PPalette32; Entries: LongInt): Boolean;
757 begin
758 try
759 Imaging.FillGrayscalePalette(Pal, Entries);
760 Result := True;
761 except
762 Result := False;
763 end;
764 end;
766 function ImFillCustomPalette(Pal: PPalette32; Entries: LongInt; RBits, GBits,
767 BBits: Byte; Alpha: Byte): Boolean;
768 begin
769 try
770 Imaging.FillCustomPalette(Pal, Entries, RBits, GBits, BBits, Alpha);
771 Result := True;
772 except
773 Result := False;
774 end;
775 end;
777 function ImSwapChannelsOfPalette(Pal: PPalette32; Entries, SrcChannel,
778 DstChannel: LongInt): Boolean;
779 begin
780 try
781 Imaging.SwapChannelsOfPalette(Pal, Entries, SrcChannel, DstChannel);
782 Result := True;
783 except
784 Result := False;
785 end;
786 end;
788 function ImSetOption(OptionId, Value: LongInt): Boolean;
789 begin
790 try
791 Result := Imaging.SetOption(OptionId, Value);
792 except
793 Result := False;
794 end;
795 end;
797 function ImGetOption(OptionId: LongInt): LongInt;
798 begin
799 try
800 Result := GetOption(OptionId);
801 except
802 Result := InvalidOption;
803 end;
804 end;
806 function ImPushOptions: Boolean;
807 begin
808 try
809 Result := Imaging.PushOptions;
810 except
811 Result := False;
812 end;
813 end;
815 function ImPopOptions: Boolean;
816 begin
817 try
818 Result := Imaging.PopOptions;
819 except
820 Result := False;
821 end;
822 end;
824 function ImGetImageFormatInfo(Format: TImageFormat; var Info: TImageFormatInfo): Boolean;
825 begin
826 try
827 Result := Imaging.GetImageFormatInfo(Format, Info);
828 except
829 Result := False;
830 end;
831 end;
833 function ImGetPixelsSize(Format: TImageFormat; Width, Height: LongInt): LongInt;
834 begin
835 try
836 Result := Imaging.GetPixelsSize(Format, Width, Height);
837 except
838 Result := 0;
839 end;
840 end;
842 procedure ImSetUserFileIO(OpenReadProc: TOpenReadProc; OpenWriteProc:
843 TOpenWriteProc; CloseProc: TCloseProc; EofProc: TEofProc; SeekProc: TSeekProc;
844 TellProc: TTellProc; ReadProc: TReadProc; WriteProc: TWriteProc);
845 begin
846 try
847 Imaging.SetUserFileIO(OpenReadProc, OpenWriteProc, CloseProc, EofProc,
848 SeekProc, TellProc, ReadProc, WriteProc);
849 except
850 end;
851 end;
853 procedure ImResetFileIO;
854 begin
855 try
856 Imaging.ResetFileIO;
857 except
858 end;
859 end;
862 Changes/Bug Fixes:
864 -- TODOS ----------------------------------------------------
865 - nothing now
867 -- 0.26.3 ---------------------------------------------------
868 - changed PChars to PAnsiChars and some more D2009 friendly
869 casts.
871 -- 0.19 -----------------------------------------------------
872 - updated to reflect changes in low level interface (added pixel set/get, ...)
873 - changed ImInitImage to procedure to reflect change in Imaging.pas
874 - added ImIsFileFormatSupported
876 -- 0.15 -----------------------------------------------------
877 - behaviour of ImGetImageListElement and ImSetImageListElement
878 has changed - list items are now cloned rather than referenced,
879 because of this ImFreeImageListKeepImages was no longer needed
880 and was removed
881 - many function headers were changed - mainly pointers were
882 replaced with var and const parameters
884 -- 0.13 -----------------------------------------------------
885 - added TestImagesInList function and new 0.13 functions
886 - images were not freed when image list was resized in ImSetImageListSize
887 - ImSaveMultiImageTo* recreated the input image list with size = 0
890 end.