Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program EncodeLoc;
- {$I SRL/OSR.simba}
- type
- PInt32 = ^Int32;
- function EncodeLocColor(color, index: Int32): Int32;
- var
- R,G,B,vR,vG,vB,vA:Int32;
- begin
- ColorToRGB(color, R,G,B);
- R := (R div 32) * 32;
- G := (G div 16) * 16;
- B := (B div 32) * 32;
- vR := index shr 0 and 31;
- vG := index shr 5 and 15;
- vB := index shr 9 and 31;
- Result := (R+vR) or ((G+vG) shl 8) or ((B+vB) shl 16);
- end;
- procedure EncodeImage(im: TMufasaBitmap); //max 512x512
- var
- x,y,w,h,idx: Int32;
- begin
- W := im.GetWidth;
- H := im.GetHeight;
- for y:=50 to H-51 do
- for x:=50 to W-51 do
- begin
- idx := (y div 4) * (W div 4) + (x div 4);
- im.SetPixel(x,y, EncodeLocColor(im.GetPixel(x,y), idx));
- end;
- end;
- function GetLocation(im: TMufasaBitmap; wid,hei: Int32): TPoint;
- var
- color, R,G,B,A,t: Int32;
- begin
- color := im.GetPixel(0,0); //some pixel in the image, subtract this offset from result..
- R := (color shr 00 and $FF) mod 32;
- G := (color shr 08 and $FF) mod 16;
- B := (color shr 16 and $FF) mod 32;
- t := (R) or (G shl 5) or (B shl 9);
- Result.x := (t mod wid) * 4; //(t - (t div wid)*wid) * 4
- Result.y := (t div wid) * 4;
- end;
- var
- tiny,im: TMufasaBitmap;
- begin
- im := GetMufasaBitmap(LoadBitmap('images/memimage.png'));
- EncodeImage(im);
- im.Debug();
- tiny := im.Copy(388,152, 500,500);
- WriteLn GetLocation(tiny, im.GetWidth div 4, im.GetHeight div 4);
- tiny.Free();
- im.Free();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement