Advertisement
WarPie90

Encode Loc Image

Nov 20th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.45 KB | None | 0 0
  1. program EncodeLoc;
  2. {$I SRL/OSR.simba}
  3.  
  4. type
  5.   PInt32 = ^Int32;
  6.  
  7. function EncodeLocColor(color, index: Int32): Int32;
  8. var
  9.   R,G,B,vR,vG,vB,vA:Int32;
  10. begin
  11.   ColorToRGB(color, R,G,B);
  12.   R := (R div 32) * 32;
  13.   G := (G div 16) * 16;
  14.   B := (B div 32) * 32;
  15.   vR := index shr 0 and 31;
  16.   vG := index shr 5 and 15;
  17.   vB := index shr 9 and 31;
  18.   Result := (R+vR) or ((G+vG) shl 8) or ((B+vB) shl 16);
  19. end;
  20.  
  21. procedure EncodeImage(im: TMufasaBitmap); //max 512x512
  22. var
  23.   x,y,w,h,idx: Int32;
  24. begin
  25.   W := im.GetWidth;
  26.   H := im.GetHeight;
  27.   for y:=50 to H-51 do
  28.     for x:=50 to W-51 do
  29.     begin
  30.       idx := (y div 4) * (W  div 4) + (x div 4);
  31.       im.SetPixel(x,y, EncodeLocColor(im.GetPixel(x,y), idx));
  32.     end;
  33. end;
  34.  
  35. function GetLocation(im: TMufasaBitmap; wid,hei: Int32): TPoint;
  36. var
  37.   color, R,G,B,A,t: Int32;
  38. begin
  39.   color := im.GetPixel(0,0); //some pixel in the image, subtract this offset from result..
  40.   R := (color shr 00 and $FF) mod 32;
  41.   G := (color shr 08 and $FF) mod 16;
  42.   B := (color shr 16 and $FF) mod 32;
  43.   t := (R) or (G shl 5) or (B shl 9);
  44.   Result.x := (t mod wid) * 4; //(t - (t div wid)*wid) * 4
  45.   Result.y := (t div wid) * 4;
  46. end;  
  47.  
  48. var
  49.   tiny,im: TMufasaBitmap;
  50. begin
  51.   im := GetMufasaBitmap(LoadBitmap('images/memimage.png'));
  52.   EncodeImage(im);
  53.   im.Debug();
  54.  
  55.   tiny := im.Copy(388,152, 500,500);
  56.   WriteLn GetLocation(tiny, im.GetWidth div 4, im.GetHeight div 4);
  57.  
  58.   tiny.Free();
  59.   im.Free();
  60. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement