Bladeren bron

Added GameBoy filter

lainz 11 jaren geleden
bovenliggende
commit
f4941de89b
2 gewijzigde bestanden met toevoegingen van 35 en 3 verwijderingen
  1. 34 2
      bcfilters.pas
  2. 1 1
      test/test_bccontrols/test_bcfilters/unit1.pas

+ 34 - 2
bcfilters.pas

@@ -46,7 +46,7 @@ uses
 
 type
   TBCSimpleFilter = (bcsNone, bcsInvert, bcsGrayScale, bcsGrayScaleA,
-    bcsGrayScaleBGRA, bcsNoise,
+    bcsGrayScaleBGRA, bcsGameBoy, bcsNoise,
     bcsNoiseA, bcsNoiseBW, bcsNoiseBWA, bcsTVScanLinesH, bcsTVScanLinesV,
     bcsCheckeredL, bcsCheckeredR, bcsBlackAndWhite, bcsInstagram1,
     bcsInstagram2, bcsInstagram3, bcsInstagram4, bcsInstagram5, bcsInstagram6,
@@ -57,7 +57,7 @@ type
 
 const
   BCSimpleFilterStr: array [TBCSimpleFilter] of string =
-    ('None', 'Invert', 'GrayScale', 'GrayScaleA', 'GrayScaleBGRA',
+    ('None', 'Invert', 'GrayScale', 'GrayScaleA', 'GrayScaleBGRA', 'GameBoy',
     'Noise', 'NoiseA', 'NoiseBW', 'NoiseBWA', 'TVScanLinesH', 'TVScanLinesV',
     'CheckeredL', 'CheckeredR', 'BlackAndWhite', 'Instagram1', 'Instagram2',
     'Instagram3', 'Instagram4', 'Instagram5', 'Instagram6', 'PhotoNoise',
@@ -111,6 +111,9 @@ procedure GrayScaleA(Bitmap: TBGRABitmap);
 { GrayScale, using BGRAToGrayScale }
 procedure GrayScaleBGRA(Bitmap: TBGRABitmap);
 
+{ like GameBoy}
+procedure GameBoy(Bitmap: TBGRABitmap);
+
 { Noise random color, keep alpha }
 procedure Noise(Bitmap: TBGRABitmap);
 { Noise random color, advanced options }
@@ -332,6 +335,34 @@ begin
   end;}
 end;
 
+procedure GameBoy(Bitmap: TBGRABitmap);
+var
+  i: integer;
+  p: PBGRAPixel;
+  c: byte;
+  color: TBGRAPixel;
+begin
+  p := Bitmap.Data;
+
+  for i := Bitmap.NBPixels - 1 downto 0 do
+  begin
+    c := (p^.red + p^.green + p^.blue) div 3;
+
+    case c of
+      0..63: color := BGRA(0,80,32,255);
+      64..127: color := BGRA(0,104,24,255);
+      128..191: color := BGRA(0,176,0,255);
+      192..255: color := BGRA(112,224,48,255);
+    end;
+
+    p^.red := color.red;
+    p^.green := color.green;
+    p^.blue := color.blue;
+    //p^.alpha := 255;
+    Inc(p);
+  end;
+end;
+
 procedure Noise(Bitmap: TBGRABitmap);
 var
   i: integer;
@@ -611,6 +642,7 @@ begin
     bcsGrayScale: GrayScale(Bitmap);
     bcsGrayScaleA: GrayScaleA(Bitmap);
     bcsGrayScaleBGRA: GrayScaleBGRA(Bitmap);
+    bcsGameBoy: GameBoy(Bitmap);
     bcsNoise: Noise(Bitmap);
     bcsNoiseA: NoiseA(Bitmap);
     bcsNoiseBW: NoiseBW(Bitmap);

+ 1 - 1
test/test_bccontrols/test_bcfilters/unit1.pas

@@ -60,7 +60,7 @@ begin
   BCSimpleFilterStrList(ListBox4.Items);
   ListBox1.Selected[20] := True;
   ListBox2.Selected[21] := True;
-  ListBox3.Selected[0] := True;
+  ListBox3.Selected[5] := True;
   ListBox4.Selected[0] := True;
 
   Fade.Mode := fmFadeOut;