Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TNalaBitmap.Thumbnail(NewWidth, NewHeight: UInt32; TargetBitmap: TNalaBitmap);
- var
- w,h,x,y,rx,ry,dx,dy:Int32;
- xx,yy,r,g,b,n,rr,gg,bb:Int32;
- wr,hr:Double;
- TargetData,rowPtr:PRGB32;
- offset:PtrUInt;
- begin
- TargetBitmap.SetSize(NewWidth, NewHeight);
- TargetData := TargetBitmap.FData;
- wr := FWidth / NewWidth;
- hr := FHeight / NewHeight;
- w := FWidth - 1;
- h := FHeight - 1;
- for y:=0 to NewHeight - 1 do
- begin
- ry := Trunc(y*hr);
- dy := Min(ry+Trunc(hr), h);
- for x:=0 to NewWidth - 1 do
- begin
- rx := Trunc(x*wr);
- dx := Min(rx+Trunc(wr), w);
- r := 0;
- g := 0;
- b := 0;
- n := 0;
- rowPtr := @FData[ry * FWidth];
- offset := PtrUInt(@FData[dy * FWidth]);
- while PtrUInt(rowPtr) <= offset do
- begin
- for xx:=rx to dx do
- begin
- R += rowPtr[xx].R;
- G += rowPtr[xx].G;
- B += rowPtr[xx].B;
- Inc(n);
- end;
- Inc(rowPtr,FWidth);
- end;
- r := r div n;
- g := g div n;
- b := b div n;
- Ptr := @TargetData[y * NewWidth + x];
- Ptr^.R := r;
- Ptr^.G := g;
- Ptr^.B := b;
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement