Advertisement
Guest User

Untitled

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