source: trunk/Packages/bgrabitmap/bgrathumbnail.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 19.3 KB
Line 
1unit BGRAThumbnail;
2
3{$mode objfpc}{$H+}
4{$i bgrabitmap.inc}
5
6interface
7
8uses
9 Classes, SysUtils, BGRABitmap, BGRABitmapTypes, FPimage;
10
11function GetBitmapThumbnail(ABitmap: TBGRACustomBitmap; AWidth,AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil; AVerticalShrink: single = 1; AHorizShrink: single = 1): TBGRABitmap; overload;
12function GetBitmapThumbnail(ABitmap: TBGRACustomBitmap; AFormat: TBGRAImageFormat; AWidth,AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil; AVerticalShrink: single = 1; AHorizShrink: single = 1): TBGRABitmap; overload;
13function GetFileThumbnail(AFilenameUTF8: string; AWidth,AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
14function GetStreamThumbnail(AStream: TStream; AWidth,AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ASuggestedExtensionUTF8: string = ''; ADest: TBGRABitmap= nil): TBGRABitmap; overload;
15function GetStreamThumbnail(AStream: TStream; AReader: TFPCustomImageReader; AWidth,AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap; overload;
16
17function GetOpenRasterThumbnail(AStream: TStream; AWidth,AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
18function GetLazPaintThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
19function GetPhoxoThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
20function GetJpegThumbnail(AStream: TStream; AWidth,AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
21function GetPsdThumbnail(AStream: TStream; AWidth,AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
22function GetPngThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
23function GetPaintDotNetThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
24function GetBmpThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
25function GetIcoThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
26function GetCurThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
27
28function GetPcxThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
29function GetTargaThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
30function GetTiffThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
31function GetGifThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
32function GetXwdThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
33function GetXPixMapThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
34function GetBmpMioMapThumbnail(AStream: TStream; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
35
36procedure DrawThumbnailCheckers(bmp: TBGRABitmap; ARect: TRect; AIconCheckers: boolean = false);
37
38var
39 ImageCheckersColor1,ImageCheckersColor2 : TBGRAPixel;
40 IconCheckersColor1,IconCheckersColor2 : TBGRAPixel;
41
42implementation
43
44uses Types, base64, BGRAUTF8,
45 DOM, XMLRead, BGRAReadJPEG, BGRAReadPng, BGRAReadGif, BGRAReadBMP,
46 BGRAReadPSD, BGRAReadIco, UnzipperExt, BGRAReadLzp;
47
48procedure DrawThumbnailCheckers(bmp: TBGRABitmap; ARect: TRect; AIconCheckers: boolean);
49begin
50 if AIconCheckers then
51 bmp.DrawCheckers(ARect, IconCheckersColor1, IconCheckersColor2)
52 else
53 bmp.DrawCheckers(ARect, ImageCheckersColor1, ImageCheckersColor2);
54end;
55
56function InternalGetBitmapThumbnail(ABitmap: TBGRACustomBitmap; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean;
57 ADest: TBGRABitmap; AVerticalShrink: single = 1; AHorizShrink: single = 1; AShowHotSpot: boolean = false; ADarkCheckers: boolean = false): TBGRABitmap;
58var
59 factorX, factorY, factor: single;
60 xIcon,yIcon,wIcon,hIcon: Integer;
61 hotspot: TPoint;
62begin
63 result := nil;
64 try
65 if (ABitmap <> nil) and (ABitmap.Width <> 0) and (ABitmap.Height <> 0) then
66 begin
67 If Assigned(ADest) then
68 begin
69 result := ADest;
70 result.SetSize(AWidth,AHeight);
71 result.Fill(ABackColor);
72 end else
73 result := TBGRABitmap.Create(AWidth,AHeight,ABackColor);
74 factorX := result.Width/(ABitmap.Width*AHorizShrink);
75 factorY := result.Height/(ABitmap.Height*AVerticalShrink);
76 if factorX < factorY then factor := factorX else factor := factorY;
77 wIcon := round(ABitmap.Width*AHorizShrink*factor);
78 if wIcon = 0 then wIcon := 1;
79 hIcon := round(ABitmap.Height*AVerticalShrink*factor);
80 if hIcon = 0 then hIcon := 1;
81 xIcon:= (result.Width-wIcon) div 2;
82 yIcon:= (result.Height-hIcon) div 2;
83 if ACheckers then DrawThumbnailCheckers(result,Rect(xIcon,yIcon,xIcon+wIcon,yIcon+hIcon),ADarkCheckers);
84 if AShowHotSpot and (wIcon > 0) and (hIcon > 0) then
85 begin
86 hotspot := Point(xIcon+ABitmap.HotSpot.X*wIcon div ABitmap.Width,yIcon+ABitmap.HotSpot.Y*hIcon div ABitmap.Height);
87 result.HorizLine(xIcon,hotspot.y-1,xIcon+wIcon-1,CSSLime,dmDrawWithTransparency);
88 result.HorizLine(xIcon,hotspot.y,xIcon+wIcon-1,CSSLime,dmDrawWithTransparency);
89 result.HorizLine(xIcon,hotspot.y+1,xIcon+wIcon-1,CSSLime,dmDrawWithTransparency);
90 result.VertLine(hotspot.x-1,yIcon,yIcon+hIcon-1,CSSLime,dmDrawWithTransparency);
91 result.VertLine(hotspot.x,yIcon,yIcon+hIcon-1,CSSLime,dmDrawWithTransparency);
92 result.VertLine(hotspot.x+1,yIcon,yIcon+hIcon-1,CSSLime,dmDrawWithTransparency);
93 end;
94 if (ABackColor.alpha <> 0) or ACheckers then
95 result.StretchPutImage(Rect(xIcon,yIcon,xIcon+wIcon,yIcon+hIcon),ABitmap,dmDrawWithTransparency) else
96 result.StretchPutImage(Rect(xIcon,yIcon,xIcon+wIcon,yIcon+hIcon),ABitmap,dmSet);
97 if AShowHotSpot and (wIcon > 0) and (hIcon > 0) then
98 begin
99 result.HorizLine(xIcon,yIcon+ABitmap.HotSpot.Y*hIcon div ABitmap.Height,xIcon+wIcon-1,BGRA(255,0,255,96),dmDrawWithTransparency);
100 result.VertLine(xIcon+ABitmap.HotSpot.X*wIcon div ABitmap.Width,yIcon,yIcon+hIcon-1,BGRA(255,0,255,96),dmDrawWithTransparency);
101 end;
102 end;
103 except
104 end;
105end;
106
107function GetBitmapThumbnail(ABitmap: TBGRACustomBitmap; AWidth, AHeight: integer;
108 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap = nil;
109 AVerticalShrink: single = 1; AHorizShrink: single = 1): TBGRABitmap;
110begin
111 result := InternalGetBitmapThumbnail(ABitmap,AWidth,AHeight,ABackColor,ACheckers,ADest,AVerticalShrink,AHorizShrink,
112 false,false);
113end;
114
115function GetBitmapThumbnail(ABitmap: TBGRACustomBitmap; AFormat: TBGRAImageFormat; AWidth, AHeight: integer;
116 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap = nil; AVerticalShrink: single = 1; AHorizShrink: single = 1): TBGRABitmap;
117begin
118 result := InternalGetBitmapThumbnail(ABitmap,AWidth,AHeight,ABackColor,ACheckers,ADest,AVerticalShrink,AHorizShrink,
119 AFormat = ifCur, AFormat in[ifCur,ifIco]);
120
121end;
122
123function GetFileThumbnail(AFilenameUTF8: string; AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
124var stream: TFileStreamUTF8;
125begin
126 result := nil;
127 try
128 stream := TFileStreamUTF8.Create(AFilenameUTF8,fmOpenRead or fmShareDenyWrite);
129 except
130 exit;
131 end;
132 try
133 result := GetStreamThumbnail(stream, AWidth,AHeight,ABackColor,ACheckers,ExtractFileExt(AFilenameUTF8),ADest);
134 finally
135 stream.free;
136 end;
137end;
138
139function GetStreamThumbnail(AStream: TStream; AWidth, AHeight: integer;
140 ABackColor: TBGRAPixel; ACheckers: boolean; ASuggestedExtensionUTF8: string;
141 ADest: TBGRABitmap): TBGRABitmap;
142var
143 ff: TBGRAImageFormat;
144 reader: TFPCustomImageReader;
145begin
146 ff := DetectFileFormat(AStream,ASuggestedExtensionUTF8);
147 case ff of
148 ifJpeg: result := GetJpegThumbnail(AStream, AWidth,AHeight, ABackColor, ACheckers, ADest);
149 ifIco: result := GetIcoThumbnail(AStream, AWidth,AHeight, ABackColor, ACheckers, ADest);
150 ifCur: result := GetCurThumbnail(AStream, AWidth,AHeight, ABackColor, ACheckers, ADest);
151 ifPaintDotNet: result := GetPaintDotNetThumbnail(AStream, AWidth,AHeight, ABackColor, ACheckers, ADest);
152 ifLazPaint: result := GetLazPaintThumbnail(AStream, AWidth,AHeight, ABackColor, ACheckers, ADest);
153 ifOpenRaster: result := GetOpenRasterThumbnail(AStream, AWidth,AHeight, ABackColor, ACheckers, ADest);
154 ifPhoxo: result := GetPhoxoThumbnail(AStream, AWidth,AHeight, ABackColor, ACheckers, ADest);
155 ifPsd: result := GetPsdThumbnail(AStream, AWidth,AHeight, ABackColor, ACheckers, ADest);
156 else
157 begin
158 if (ff = ifUnknown) or (DefaultBGRAImageReader[ff] = nil) then
159 result := nil
160 else
161 begin
162 result := nil;
163 reader := nil;
164 try
165 reader := CreateBGRAImageReader(ff);
166 result := GetStreamThumbnail(AStream, reader, AWidth, AHeight, ABackColor, ACheckers, ADest);
167 finally
168 reader.Free;
169 end;
170 end;
171 end;
172 end;
173end;
174
175function GetStreamThumbnail(AStream: TStream; AReader: TFPCustomImageReader;
176 AWidth, AHeight: integer; ABackColor: TBGRAPixel; ACheckers: boolean;
177 ADest: TBGRABitmap): TBGRABitmap;
178var
179 bmp: TBGRACustomBitmap;
180 AOriginalWidth, AOriginalHeight: integer;
181begin
182 if AReader is TBGRAImageReader then
183 begin
184 bmp := nil;
185 try
186 bmp := TBGRAImageReader(AReader).GetBitmapDraft(AStream, AWidth,AHeight, AOriginalWidth,AOriginalHeight);
187 if Assigned(bmp) and (bmp.Height <> 0) and (bmp.Width <> 0) then
188 result := GetBitmapThumbnail(bmp, AWidth, AHeight, ABackColor, ACheckers, ADest,
189 AOriginalHeight/bmp.Height, AOriginalWidth/bmp.Width);
190 except
191 result := nil;
192 end;
193 bmp.free;
194 exit;
195 end;
196
197 bmp := TBGRABitmap.Create;
198 try
199 bmp.LoadFromStream(AStream, AReader);
200 except
201 FreeAndNil(bmp);
202 end;
203 if bmp = nil then
204 result := nil
205 else
206 begin
207 result := GetBitmapThumbnail(bmp, AWidth, AHeight, ABackColor, ACheckers, ADest);
208 bmp.Free;
209 end;
210end;
211
212function GetOpenRasterThumbnail(AStream: TStream; AWidth, AHeight: integer;
213 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
214var
215 unzip: TUnzipperStreamUtf8;
216 png: TMemoryStream;
217begin
218 result := nil;
219 unzip := TUnzipperStreamUtf8.Create;
220 try
221 unzip.InputStream := AStream;
222 png := TMemoryStream.Create;
223 try
224 if unzip.UnzipFileToStream('Thumbnails\thumbnail.png', png, False) then
225 begin
226 png.Position:= 0;
227 result := GetPngThumbnail(png,AWidth,AHeight,ABackColor,ACheckers,ADest);
228 end;
229 finally
230 png.Free;
231 end;
232 except
233 end;
234 unzip.Free;
235end;
236
237function GetLazPaintThumbnail(AStream: TStream; AWidth, AHeight: integer;
238 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
239var
240 reader: TBGRAReaderLazPaint;
241begin
242 reader:= TBGRAReaderLazPaint.Create;
243 reader.WantThumbnail := true;
244 result := GetStreamThumbnail(AStream,reader,AWidth,AHeight,ABackColor,ACheckers,ADest);
245 reader.Free;
246end;
247
248function GetPhoxoThumbnail(AStream: TStream; AWidth, AHeight: integer;
249 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
250var
251 reader: TFPCustomImageReader;
252begin
253 if DefaultBGRAImageReader[ifPhoxo] = nil then
254 result := nil
255 else
256 begin
257 reader := CreateBGRAImageReader(ifPhoxo);
258 result := GetStreamThumbnail(AStream, reader, AWidth,AHeight,ABackColor,ACheckers,ADest);
259 reader.Free;
260 end;
261end;
262
263function GetJpegThumbnail(AStream: TStream; AWidth, AHeight: integer
264 ; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
265var
266 jpeg: TBGRAReaderJpeg;
267begin
268 jpeg := TBGRAReaderJpeg.Create;
269 jpeg.Performance := jpBestSpeed;
270 jpeg.MinWidth := AWidth;
271 jpeg.MinHeight := AHeight;
272 result := GetStreamThumbnail(AStream, jpeg, AWidth,AHeight,ABackColor,ACheckers,ADest);
273 jpeg.Free;
274end;
275
276function GetPsdThumbnail(AStream: TStream; AWidth, AHeight: integer
277 ; ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
278var
279 psd: TBGRAReaderPSD;
280 bmp: TBGRABitmap;
281begin
282 psd:= TBGRAReaderPSD.Create;
283 psd.MinifyHeight:= AHeight;
284 bmp := TBGRABitmap.Create;
285 try
286 bmp.LoadFromStream(AStream, psd);
287 except
288 FreeAndNil(bmp);
289 end;
290 if bmp = nil then
291 result := nil
292 else
293 begin
294 result := GetBitmapThumbnail(bmp, AWidth, AHeight, ABackColor, ACheckers, ADest, psd.Height/bmp.Height);
295 bmp.Free;
296 end;
297 psd.Free;
298end;
299
300function GetPngThumbnail(AStream: TStream; AWidth, AHeight: integer;
301 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap= nil): TBGRABitmap;
302var
303 pngFormat: TBGRAReaderPNG;
304begin
305 pngFormat:= TBGRAReaderPNG.Create;
306 result:= GetStreamThumbnail(AStream, pngFormat, AWidth,AHeight, ABackColor, ACheckers, ADest);
307 pngFormat.Free;
308end;
309
310function GetPaintDotNetThumbnail(AStream: TStream; AWidth, AHeight: integer;
311 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
312var
313 {%H-}magic: packed array[0..6] of byte;
314 xmlHeader: TMemoryStream;
315 xmlHeaderSize: longint;
316 doc: TXMLDocument;
317 custom,thumb,pngNode: TDOMNode;
318 png64: TStringStream;
319 decode64: TBase64DecodingStream;
320begin
321 result := nil;
322 if AStream.Read({%H-}magic,sizeof(magic)) <> sizeof(magic) then exit;
323 if chr(magic[0])+chr(magic[1])+chr(magic[2])+chr(magic[3]) <> 'PDN3' then exit;
324 xmlHeaderSize := magic[4] + (magic[5] shl 8) + (magic[6] shl 16);
325 if xmlHeaderSize >= 10*1024*1024 then exit;
326 xmlHeader:= TMemoryStream.Create;
327 try
328 if xmlHeader.CopyFrom(AStream,xmlHeaderSize) <> xmlHeaderSize then
329 begin
330 xmlHeader.Free;
331 exit;
332 end;
333 except
334 xmlHeader.Free;
335 exit;
336 end;
337 xmlHeader.Position := 0;
338 try
339 XMLRead.ReadXMLFile(doc, xmlHeader);
340 except
341 xmlHeader.Free;
342 exit;
343 end;
344 xmlHeader.Free;
345 try
346 custom := doc.DocumentElement.FindNode('custom');
347 if Assigned(custom) then
348 begin
349 thumb := custom.FindNode('thumb');
350 if Assigned(thumb) then
351 begin
352 pngNode := thumb.Attributes.GetNamedItem('png');
353 if Assigned(pngNode) then
354 begin
355 png64 := TStringStream.Create(string(pngNode.NodeValue));
356 try
357 png64.Position := 0;
358 decode64 := TBase64DecodingStream.Create(png64);
359 try
360 result := GetPngThumbnail(decode64,AWidth,AHeight,ABackColor,ACheckers, ADest);
361 finally
362 decode64.Free;
363 end;
364 finally
365 png64.free;
366 end;
367 end;
368 end;
369 end;
370 except
371 end;
372 doc.Free;
373end;
374
375function GetBmpThumbnail(AStream: TStream; AWidth, AHeight: integer;
376 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
377var
378 bmpFormat: TBGRAReaderBMP;
379begin
380 bmpFormat:= TBGRAReaderBMP.Create;
381 result:= GetStreamThumbnail(AStream, bmpFormat, AWidth,AHeight, ABackColor, ACheckers, ADest);
382 bmpFormat.Free;
383end;
384
385function GetIcoThumbnail(AStream: TStream; AWidth, AHeight: integer;
386 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
387var
388 reader: TBGRAReaderIco;
389 icoBmp: TBGRABitmap;
390begin
391 result := nil;
392 reader := TBGRAReaderIco.Create;
393 reader.WantedWidth:= AWidth;
394 reader.WantedHeight:= AHeight;
395 icoBmp := TBGRABitmap.Create;
396 try
397 icoBmp.LoadFromStream(AStream, reader);
398 result := GetBitmapThumbnail(icoBmp, ifIco, AWidth, AHeight, ABackColor, ACheckers, ADest);
399 except
400 end;
401 icoBmp.Free;
402 reader.Free;
403end;
404
405function GetCurThumbnail(AStream: TStream; AWidth, AHeight: integer;
406 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
407var
408 reader: TBGRAReaderCur;
409 icoBmp: TBGRABitmap;
410begin
411 result := nil;
412 reader := TBGRAReaderCur.Create;
413 reader.WantedWidth:= AWidth;
414 reader.WantedHeight:= AHeight;
415 icoBmp := TBGRABitmap.Create;
416 try
417 icoBmp.LoadFromStream(AStream, reader);
418 result := GetBitmapThumbnail(icoBmp, ifCur, AWidth, AHeight, ABackColor, ACheckers, ADest);
419 except
420 end;
421 icoBmp.Free;
422 reader.Free;
423end;
424
425function GetPcxThumbnail(AStream: TStream; AWidth, AHeight: integer;
426 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
427var
428 reader: TFPCustomImageReader;
429begin
430 reader:= CreateBGRAImageReader(ifPcx);
431 result := GetStreamThumbnail(AStream,reader,AWidth,AHeight,ABackColor,ACheckers,ADest);
432 reader.Free;
433end;
434
435function GetTargaThumbnail(AStream: TStream; AWidth, AHeight: integer;
436 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
437var
438 reader: TFPCustomImageReader;
439begin
440 reader:= CreateBGRAImageReader(ifTarga);
441 result := GetStreamThumbnail(AStream,reader,AWidth,AHeight,ABackColor,ACheckers, ADest);
442 reader.Free;
443end;
444
445function GetTiffThumbnail(AStream: TStream; AWidth, AHeight: integer;
446 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
447var
448 reader: TFPCustomImageReader;
449begin
450 reader:= CreateBGRAImageReader(ifTiff);
451 result := GetStreamThumbnail(AStream,reader,AWidth,AHeight,ABackColor,ACheckers,ADest);
452 reader.Free;
453end;
454
455function GetGifThumbnail(AStream: TStream; AWidth, AHeight: integer;
456 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
457var
458 reader: TFPCustomImageReader;
459begin
460 reader:= CreateBGRAImageReader(ifGif);
461 result := GetStreamThumbnail(AStream,reader,AWidth,AHeight,ABackColor,ACheckers, ADest);
462 reader.Free;
463end;
464
465function GetXwdThumbnail(AStream: TStream; AWidth, AHeight: integer;
466 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
467var
468 reader: TFPCustomImageReader;
469begin
470 reader:= CreateBGRAImageReader(ifXwd);
471 result := GetStreamThumbnail(AStream,reader,AWidth,AHeight,ABackColor,ACheckers, ADest);
472 reader.Free;
473end;
474
475function GetXPixMapThumbnail(AStream: TStream; AWidth, AHeight: integer;
476 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
477var
478 reader: TFPCustomImageReader;
479begin
480 reader:= CreateBGRAImageReader(ifXPixMap);
481 result := GetStreamThumbnail(AStream,reader,AWidth,AHeight,ABackColor,ACheckers,ADest);
482 reader.Free;
483end;
484
485function GetBmpMioMapThumbnail(AStream: TStream; AWidth, AHeight: integer;
486 ABackColor: TBGRAPixel; ACheckers: boolean; ADest: TBGRABitmap): TBGRABitmap;
487var
488 reader: TFPCustomImageReader;
489begin
490 reader:= CreateBGRAImageReader(ifBmpMioMap);
491 result := GetStreamThumbnail(AStream,reader,AWidth,AHeight,ABackColor,ACheckers,ADest);
492 reader.Free;
493end;
494
495initialization
496
497 IconCheckersColor1 := BGRA(140,180,180);
498 IconCheckersColor2 := BGRA(80,140,140);
499
500 ImageCheckersColor1 := BGRA(255,255,255);
501 ImageCheckersColor2 := BGRA(220,220,220);
502
503end.
Note: See TracBrowser for help on using the repository browser.