{
Here is the routine I use in my thumbnail component and I belive it is quite
fast.
A tip to gain faster loading of jpegs is to use the TJpegScale.Scale
property. You can gain a lot by using this correct.
This routine can only downscale images no upscaling is supported and you
must correctly set the dest image size. The src.image will be scaled to fit
in dest bitmap.
}
procedure MakeThumbNail(src, dest: TBitmap; ThumbSize: Word); type PRGB24 = ^TRGB24;
TRGB24 = packed record B: Byte;
G: Byte;
R: Byte; end; var x, y, ix, iy: integer;
x1, x2, x3: integer;
begin
if src.PixelFormat <> pf24bit then src.PixelFormat := pf24bit; if dest.PixelFormat <> pf24bit then dest.PixelFormat := pf24bit;
dest.Width := ThumbSize;
dest.Height := ThumbSize;
w := ThumbSize;
h := ThumbSize;
if (src.Width <= ThumbSize) and (src.Height <= ThumbSize) then
begin dest.Assign(src);
exit; end;
iDst := (w * 24 + 31) and not 31;
iDst := iDst div 8; //BytesPerScanline iSrc := (Src.Width * 24 + 31) and not 31;
iSrc := iSrc div 8;
r := (c1.R + c2.R + (c3.R * -12) + c4.R + c5.R) div -8;
g := (c1.G + c2.G + (c3.G * -12) + c4.G + c5.G) div -8;
b := (c1.B + c2.B + (c3.B * -12) + c4.B + c5.B) div -8;
if r < 0 then r := 0 else if r > 255 then r := 255; if g < 0 then g := 0 else if g > 255 then g := 255; if b < 0 then b := 0 else if b > 255 then b := 255;