MainUnit.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. unit MainUnit;
  2. interface
  3. {$include GR32.inc}
  4. uses
  5. {$IFDEF FPC}LCLIntf, {$ELSE}Windows, {$ENDIF} Messages, SysUtils, Classes,
  6. Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, GR32, GR32_Image,
  7. GR32_RangeBars;
  8. type
  9. TFrmGammaCorrection = class(TForm)
  10. GbrContrast: TGaugeBar;
  11. GbrGamma: TGaugeBar;
  12. GbrThickness: TGaugeBar;
  13. LblContrast: TLabel;
  14. LblContrastValue: TLabel;
  15. LblGamma: TLabel;
  16. LblGammaValue: TLabel;
  17. LblThickness: TLabel;
  18. LblThicknessValue: TLabel;
  19. PaintBox32: TPaintBox32;
  20. PnControl: TPanel;
  21. procedure FormShow(Sender: TObject);
  22. procedure GbrContrastChange(Sender: TObject);
  23. procedure GbrGammaChange(Sender: TObject);
  24. procedure GbrThicknessChange(Sender: TObject);
  25. procedure PaintBox32PaintBuffer(Sender: TObject);
  26. end;
  27. var
  28. FrmGammaCorrection: TFrmGammaCorrection;
  29. implementation
  30. uses
  31. Types,
  32. GR32_LowLevel,
  33. GR32_Gamma,
  34. GR32_VectorUtils,
  35. GR32_Polygons;
  36. {$R *.dfm}
  37. procedure TFrmGammaCorrection.FormShow(Sender: TObject);
  38. begin
  39. GbrContrastChange(Sender);
  40. GbrGammaChange(Sender);
  41. GbrThicknessChange(Sender);
  42. end;
  43. procedure TFrmGammaCorrection.GbrContrastChange(Sender: TObject);
  44. begin
  45. LblContrastValue.Caption := IntToStr(GbrContrast.Position);
  46. PaintBox32.Invalidate;
  47. end;
  48. procedure TFrmGammaCorrection.GbrGammaChange(Sender: TObject);
  49. var
  50. GammaValue: Double;
  51. begin
  52. GammaValue := 0.001 * GbrGamma.Position;
  53. LblGammaValue.Caption := FloatToStrF(GammaValue, ffFixed, 4, 3);
  54. SetGamma(GammaValue);
  55. PaintBox32.Invalidate;
  56. end;
  57. procedure TFrmGammaCorrection.GbrThicknessChange(Sender: TObject);
  58. begin
  59. LblThicknessValue.Caption := FloatToStrF(0.01 * GbrThickness.Position,
  60. ffFixed, 3, 3);
  61. PaintBox32.Invalidate;
  62. end;
  63. procedure TFrmGammaCorrection.PaintBox32PaintBuffer(Sender: TObject);
  64. var
  65. Renderer: TPolygonRenderer32VPR;
  66. W, H: Integer;
  67. Thickness: TFloat;
  68. Color: TColor32;
  69. Outline: TArrayOfFloatPoint;
  70. Radius: TFloatPoint;
  71. Index, Contrast, DeltaY: Byte;
  72. StartPnt: TFloatPoint;
  73. begin
  74. W := PaintBox32.Width;
  75. H := PaintBox32.Height;
  76. Thickness := 0.01 * GbrThickness.Position;
  77. Radius := FloatPoint(W / 3, H / 3);
  78. Renderer := TPolygonRenderer32VPR.Create;
  79. try
  80. Renderer.Bitmap := PaintBox32.Buffer;
  81. Contrast := $FF - GbrContrast.Position;
  82. Color := Gray32(Contrast);
  83. PaintBox32.Buffer.FillRect(0, 0, Trunc(W) div 2, Trunc(H), Color);
  84. Color := Gray32($FF - Contrast);
  85. PaintBox32.Buffer.FillRect(Trunc(W) div 2, 0, Trunc(W), Trunc(H),
  86. Color);
  87. Color := Color32($FF, Contrast, Contrast);
  88. PaintBox32.Buffer.FillRect(0, 0, Trunc(W), Trunc(H) div 2, Color);
  89. Renderer.Color := Color32($50, $7F, $50);
  90. StartPnt := FloatPoint((W - 256) * 0.5, 50);
  91. SetLength(Outline, 256);
  92. for Index := 0 to High(Byte) do
  93. begin
  94. DeltaY := GAMMA_ENCODING_TABLE[Index];
  95. Outline[Index] := FloatPoint(StartPnt.X + Index, StartPnt.Y + 255 - DeltaY)
  96. end;
  97. Renderer.PolygonFS(BuildPolyline(Outline, Thickness));
  98. Renderer.Color := Color32($FF, 0, 0);
  99. Outline := Ellipse(FloatPoint(W * 0.5, H * 0.5), Radius, 150);
  100. Renderer.PolyPolygonFS(BuildPolyPolyLine(PolyPolygon(Outline), True,
  101. Thickness));
  102. Renderer.Color := Color32(0, $FF, 0);
  103. Outline := Ellipse(FloatPoint(W * 0.5, H * 0.5),
  104. FloatPoint(Radius.X - 5, Radius.Y - 5), 150);
  105. Renderer.PolyPolygonFS(BuildPolyPolyLine(PolyPolygon(Outline), True,
  106. Thickness));
  107. Renderer.Color := Color32(0, 0, $FF);
  108. Outline := Ellipse(FloatPoint(W * 0.5, H * 0.5),
  109. FloatPoint(Radius.X - 10, Radius.Y - 10), 150);
  110. Renderer.PolyPolygonFS(BuildPolyPolyLine(PolyPolygon(Outline), True,
  111. Thickness));
  112. Renderer.Color := clBlack32;
  113. Outline := Ellipse(FloatPoint(W * 0.5, H * 0.5),
  114. FloatPoint(Radius.X - 15, Radius.Y - 15), 150);
  115. Renderer.PolyPolygonFS(BuildPolyPolyLine(PolyPolygon(Outline), True,
  116. Thickness));
  117. Renderer.Color := clWhite32;
  118. Outline := Ellipse(FloatPoint(W * 0.5, H * 0.5),
  119. FloatPoint(Radius.X - 20, Radius.Y - 20), 150);
  120. Renderer.PolyPolygonFS(BuildPolyPolyLine(PolyPolygon(Outline), True,
  121. Thickness));
  122. finally
  123. Renderer.Free;
  124. end;
  125. end;
  126. end.