Changeset 30 for trunk/Packages
- Timestamp:
- Dec 23, 2016, 10:07:39 AM (8 years ago)
- Location:
- trunk/Packages/FastGraphics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/FastGraphics/ColorFormats/UColorGray1.pas
r26 r30 50 50 procedure PaintToCanvas(Canvas: TCanvas); override; 51 51 procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); override; 52 procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); override; 52 53 procedure LoadFromCanvas(Canvas: TCanvas); override; 54 procedure LoadFromBitmap(Bitmap: TBitmap); override; 53 55 function GetDataSize: Integer; override; 54 56 constructor Create; override; … … 158 160 end; 159 161 162 procedure TBPixmapGray1.PaintToBitmap(Bitmap: TBitmap; Rect: TRect); 163 begin 164 Pixmap.PaintToBitmap(Bitmap, Rect, Pixmap.Gray1ToColor); 165 end; 166 160 167 procedure TBPixmapGray1.LoadFromCanvas(Canvas: TCanvas); 161 168 begin 162 169 Pixmap.LoadFromCanvas(Canvas, Pixmap.ColorToGray1); 170 end; 171 172 procedure TBPixmapGray1.LoadFromBitmap(Bitmap: TBitmap); 173 begin 174 Pixmap.LoadFromBitmap(Bitmap, Pixmap.ColorToGray1); 163 175 end; 164 176 -
trunk/Packages/FastGraphics/ColorFormats/UColorGray2.pas
r26 r30 50 50 procedure PaintToCanvas(Canvas: TCanvas); override; 51 51 procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); override; 52 procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); override; 52 53 procedure LoadFromCanvas(Canvas: TCanvas); override; 54 procedure LoadFromBitmap(Bitmap: TBitmap); override; 53 55 function GetDataSize: Integer; override; 54 56 constructor Create; override; … … 148 150 end; 149 151 152 procedure TBPixmapGray2.PaintToBitmap(Bitmap: TBitmap; Rect: TRect); 153 begin 154 Pixmap.PaintToBitmap(Bitmap, Rect, Pixmap.Gray2ToColor); 155 end; 156 150 157 procedure TBPixmapGray2.LoadFromCanvas(Canvas: TCanvas); 151 158 begin 152 159 Pixmap.LoadFromCanvas(Canvas, Pixmap.ColorToGray2); 160 end; 161 162 procedure TBPixmapGray2.LoadFromBitmap(Bitmap: TBitmap); 163 begin 164 Pixmap.LoadFromBitmap(Bitmap, Pixmap.ColorToGray2); 153 165 end; 154 166 -
trunk/Packages/FastGraphics/ColorFormats/UColorGray4.pas
r26 r30 17 17 TColorGray4 = Byte; 18 18 19 { TPixmapGray4 } 20 19 21 TPixmapGray4 = class(TGPixmapBit<TColorGray4>) 20 22 function Gray4ToColor(Value: TColorGray4): TColor; 23 function ColorToGray4(Value: TColor): TColorGray4; 24 end; 25 26 { TBColorGray4 } 27 28 TBColorGray4 = class(TBColor) 29 Value: TColorGray4; 30 constructor Create(Color: TColorGray4); 31 procedure SetColorName(ColorName: TColorName); override; 32 procedure SetRandom; override; 33 end; 34 35 { TBPixmapGray4 } 36 37 TBPixmapGray4 = class(TBImage) 38 private 39 FillCallBack: TGetColorPos; 40 function FillGetColor(Position: TPoint): TColorGray4; 41 protected 42 procedure SetSize(AValue: TPoint); override; 43 function GetPixel(X, Y: Integer): IBColor; override; 44 procedure SetPixel(X, Y: Integer; AValue: IBColor); override; 45 public 46 Pixmap: TPixmapGray4; 47 procedure Fill(Color: IBColor); override; 48 procedure Fill(Func: TGetColorPos); override; 49 procedure Line(P1, P2: TPoint; Color: IBColor); override; 50 procedure PaintToCanvas(Canvas: TCanvas); override; 51 procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); override; 52 procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); override; 53 procedure LoadFromCanvas(Canvas: TCanvas); override; 54 procedure LoadFromBitmap(Bitmap: TBitmap); override; 55 function GetDataSize: Integer; override; 56 constructor Create; override; 57 destructor Destroy; override; 21 58 end; 22 59 … … 32 69 Name := 'Gray 4-bit'; 33 70 BitDepth := 4; 71 BackendColorClass := TBColorGray4; 72 BackendImageClass := TBPixmapGray4; 34 73 AddChannel('Gray', 0, 4); 35 74 end; … … 43 82 end; 44 83 84 function TPixmapGray4.ColorToGray4(Value: TColor): TColorGray4; 85 begin 86 Result := Trunc((((Value shr 16) and $ff) + ((Value shr 8) and $ff) + ((Value shr 0) and $ff)) / $300 * 16); 87 end; 88 89 { TBColorGray2 } 90 91 constructor TBColorGray4.Create(Color: TColorGray4); 92 begin 93 Value := Color; 94 end; 95 96 procedure TBColorGray4.SetColorName(ColorName: TColorName); 97 begin 98 case ColorName of 99 cnBlack: Value := 0; 100 cnGray: Value := 6; 101 cnSilver: Value := 10; 102 cnWhite: Value := 15; 103 else Value := 0; 104 end; 105 end; 106 107 procedure TBColorGray4.SetRandom; 108 begin 109 Value := Random(16); 110 end; 111 112 { TBPixmapGray2 } 113 114 function TBPixmapGray4.FillGetColor(Position: TPoint): TColorGray4; 115 begin 116 Result := (FillCallBack(Position) as TBColorGray4).Value; 117 end; 118 119 procedure TBPixmapGray4.SetSize(AValue: TPoint); 120 begin 121 inherited; 122 Pixmap.Size := AValue; 123 end; 124 125 function TBPixmapGray4.GetPixel(X, Y: Integer): IBColor; 126 begin 127 Result := TBColorGray4.Create(Pixmap.Pixels[X, Y]); 128 end; 129 130 procedure TBPixmapGray4.SetPixel(X, Y: Integer; AValue: IBColor); 131 begin 132 Pixmap.Pixels[X, Y] := (AValue as TBColorGray4).Value; 133 end; 134 135 procedure TBPixmapGray4.Fill(Color: IBColor); 136 begin 137 if Color is TBColorGray4 then 138 Pixmap.Fill((Color as TBColorGray4).Value); 139 end; 140 141 procedure TBPixmapGray4.Fill(Func: TGetColorPos); 142 begin 143 FillCallBack := Func; 144 Pixmap.Fill(FillGetColor); 145 end; 146 147 procedure TBPixmapGray4.Line(P1, P2: TPoint; Color: IBColor); 148 begin 149 Pixmap.Canvas.Pen.Color := (Color as TBColorGray4).Value; 150 Pixmap.Canvas.Pen.MoveTo(P1); 151 Pixmap.Canvas.Pen.LineTo(P2); 152 end; 153 154 procedure TBPixmapGray4.PaintToCanvas(Canvas: TCanvas); 155 begin 156 Pixmap.PaintToCanvas(Canvas, Pixmap.Gray4ToColor); 157 end; 158 159 procedure TBPixmapGray4.PaintToCanvas(Canvas: TCanvas; Rect: TRect); 160 begin 161 Pixmap.PaintToCanvas(Canvas, Rect, Pixmap.Gray4ToColor); 162 end; 163 164 procedure TBPixmapGray4.PaintToBitmap(Bitmap: TBitmap; Rect: TRect); 165 begin 166 Pixmap.PaintToBitmap(Bitmap, Rect, Pixmap.Gray4ToColor); 167 end; 168 169 procedure TBPixmapGray4.LoadFromCanvas(Canvas: TCanvas); 170 begin 171 Pixmap.LoadFromCanvas(Canvas, Pixmap.ColorToGray4); 172 end; 173 174 procedure TBPixmapGray4.LoadFromBitmap(Bitmap: TBitmap); 175 begin 176 Pixmap.LoadFromBitmap(Bitmap, Pixmap.ColorToGray4); 177 end; 178 179 function TBPixmapGray4.GetDataSize: Integer; 180 begin 181 Result := Pixmap.GetDataSize; 182 end; 183 184 constructor TBPixmapGray4.Create; 185 begin 186 Pixmap := TPixmapGray4.Create; 187 Pixmap.BitsPerPixel := 4; 188 end; 189 190 destructor TBPixmapGray4.Destroy; 191 begin 192 FreeAndNil(Pixmap); 193 inherited; 194 end; 195 196 45 197 end. 46 198 -
trunk/Packages/FastGraphics/UGGraphics.pas
r29 r30 199 199 PixelPtr: PInteger; 200 200 PixelPtrMax: PInteger; 201 PixelPtrMin: PInteger; 201 202 PixelRowPtr: PInteger; 202 203 P: TPixelFormat; … … 209 210 PixelRowPtr := PInteger(RawImage.Data); 210 211 BytePerPixel := RawImage.Description.BitsPerPixel div 8; 212 PixelPtrMin := PixelRowPtr; 211 213 PixelPtrMax := PixelRowPtr + RawImage.Description.Width * RawImage.Description.Height * BytePerPixel; 212 214 for Y := Rect.Top to Rect.Bottom - 1 do begin 213 215 PixelPtr := PixelRowPtr; 214 216 for X := Rect.Left to Rect.Right - 1 do begin 215 if (X >= 0) and (X < FSize.X) and (Y >= 0) and (Y < FSize.Y) and (PixelPtr < PixelPtrMax) then 217 if (X >= 0) and (X < FSize.X) and (Y >= 0) and (Y < FSize.Y) and 218 (PixelPtr < PixelPtrMax) and (PixelPtr > PixelPtrMin) then 216 219 PixelPtr^ := ColorConvertFunc(Pixels[X, Y]); 217 220 Inc(PByte(PixelPtr), BytePerPixel);
Note:
See TracChangeset
for help on using the changeset viewer.