Changeset 506 for trunk/Packages/Common/PixelPointer.pas
- Timestamp:
- Dec 25, 2023, 11:35:51 AM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/PixelPointer.pas
r487 r506 4 4 5 5 uses 6 Classes, SysUtils, Graphics;6 Math, Classes, SysUtils, Graphics; 7 7 8 8 type 9 9 TColor32 = type Cardinal; 10 10 TColor32Component = (ccBlue, ccGreen, ccRed, ccAlpha); 11 TColor32Planes = array[0..3] of Byte; 11 12 12 13 { TPixel32 } … … 14 15 TPixel32 = packed record 15 16 private 16 procedure SetRGB(AValue: Cardinal); 17 function GetRGB: Cardinal; 17 procedure SetRGB(AValue: Cardinal); inline; 18 function GetRGB: Cardinal; inline; 18 19 public 19 20 property RGB: Cardinal read GetRGB write SetRGB; … … 21 22 0: (B, G, R, A: Byte); 22 23 1: (ARGB: TColor32); 23 2: (Planes: array[0..3] of Byte);24 2: (Planes: TColor32Planes); 24 25 3: (Components: array[TColor32Component] of Byte); 25 26 end; … … 29 30 30 31 TPixelPointer = record 32 private 33 function GetPixelARGB: TColor32; inline; 34 function GetPixelB: Byte; inline; 35 function GetPixelG: Byte; inline; 36 function GetPixelPlane(Index: Byte): Byte; 37 function GetPixelR: Byte; inline; 38 function GetPixelA: Byte; inline; 39 function GetPixelPlanes: TColor32Planes; 40 function GetPixelRGB: Cardinal; 41 procedure SetPixelARGB(Value: TColor32); inline; 42 procedure SetPixelB(Value: Byte); inline; 43 procedure SetPixelG(Value: Byte); inline; 44 procedure SetPixelPlane(Index: Byte; AValue: Byte); 45 procedure SetPixelR(Value: Byte); inline; 46 procedure SetPixelA(Value: Byte); inline; 47 procedure SetPixelRGB(Value: Cardinal); 48 public 31 49 Base: PPixel32; 32 50 Pixel: PPixel32; … … 46 64 procedure CheckRange; inline; // Check if current pixel position is not out of range 47 65 class function Create(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0): TPixelPointer; static; 66 property PixelARGB: TColor32 read GetPixelARGB write SetPixelARGB; 67 property PixelRGB: Cardinal read GetPixelRGB write SetPixelRGB; 68 property PixelB: Byte read GetPixelB write SetPixelB; 69 property PixelG: Byte read GetPixelG write SetPixelG; 70 property PixelR: Byte read GetPixelR write SetPixelR; 71 property PixelA: Byte read GetPixelA write SetPixelA; 72 property PixelPlane[Index: Byte]: Byte read GetPixelPlane write SetPixelPlane; 48 73 end; 49 74 PPixelPointer = ^TPixelPointer; … … 68 93 69 94 resourcestring 70 SOutOfRange = 'Pixel pointer out of range ';95 SOutOfRange = 'Pixel pointer out of range [X: %d. Y: %d]'; 71 96 SWrongBitmapSize = 'Wrong bitmap size [width: %d, height: %d]'; 72 97 … … 121 146 122 147 procedure TPixelPointer.CheckRange; 148 {$IFOPT R+} 149 var 150 X: Integer; 151 Y: Integer; 152 {$ENDIF} 123 153 begin 124 154 {$IFOPT R+} 125 155 if (PByte(Pixel) < PByte(Data)) or 126 (PByte(Pixel) >= PByte(Data) + (Width + Height * BytesPerLine) * BytesPerPixel) then 127 raise Exception.Create(SOutOfRange); 156 (PByte(Pixel) >= PByte(Data) + Height * BytesPerLine) then begin 157 X := PByte(Pixel) - PByte(Data); 158 Y := Floor(X / BytesPerLine); 159 X := X - Y * BytesPerLine; 160 X := Floor(X / BytesPerPixel); 161 raise Exception.Create(Format(SOutOfRange, [X, Y])); 162 end; 128 163 {$ENDIF} 164 end; 165 166 function TPixelPointer.GetPixelPlanes: TColor32Planes; 167 begin 168 CheckRange; 169 Result := Pixel^.Planes; 170 end; 171 172 function TPixelPointer.GetPixelRGB: Cardinal; 173 begin 174 CheckRange; 175 Result := Pixel^.RGB; 176 end; 177 178 procedure TPixelPointer.SetPixelARGB(Value: TColor32); 179 begin 180 CheckRange; 181 Pixel^.ARGB := Value; 182 end; 183 184 procedure TPixelPointer.SetPixelB(Value: Byte); 185 begin 186 CheckRange; 187 Pixel^.B := Value; 188 end; 189 190 procedure TPixelPointer.SetPixelG(Value: Byte); 191 begin 192 CheckRange; 193 Pixel^.G := Value; 194 end; 195 196 procedure TPixelPointer.SetPixelPlane(Index: Byte; AValue: Byte); 197 begin 198 CheckRange; 199 Pixel^.Planes[Index] := AValue; 200 end; 201 202 procedure TPixelPointer.SetPixelR(Value: Byte); 203 begin 204 CheckRange; 205 Pixel^.R := Value; 206 end; 207 208 procedure TPixelPointer.SetPixelA(Value: Byte); 209 begin 210 CheckRange; 211 Pixel^.A := Value; 212 end; 213 214 function TPixelPointer.GetPixelARGB: TColor32; 215 begin 216 CheckRange; 217 Result := Pixel^.ARGB; 218 end; 219 220 function TPixelPointer.GetPixelB: Byte; 221 begin 222 CheckRange; 223 Result := Pixel^.B; 224 end; 225 226 function TPixelPointer.GetPixelG: Byte; 227 begin 228 CheckRange; 229 Result := Pixel^.G; 230 end; 231 232 function TPixelPointer.GetPixelPlane(Index: Byte): Byte; 233 begin 234 CheckRange; 235 Result := Pixel^.Planes[Index]; 236 end; 237 238 function TPixelPointer.GetPixelR: Byte; 239 begin 240 CheckRange; 241 Result := Pixel^.R; 242 end; 243 244 function TPixelPointer.GetPixelA: Byte; 245 begin 246 CheckRange; 247 Result := Pixel^.A; 248 end; 249 250 procedure TPixelPointer.SetPixelRGB(Value: Cardinal); 251 begin 252 CheckRange; 253 Pixel^.RGB := Value; 129 254 end; 130 255 … … 141 266 for Y := 0 to DstRect.Height - 1 do begin 142 267 for X := 0 to DstRect.Width - 1 do begin 143 DstPtr.Pixel ^.ARGB := SrcPtr.Pixel^.ARGB;268 DstPtr.PixelARGB := SrcPtr.PixelARGB; 144 269 SrcPtr.NextPixel; 145 270 DstPtr.NextPixel; … … 177 302 DstPtr.SetXY(X, Y); 178 303 SrcPtr.SetXY(R.Left, R.Top); 179 C := SrcPtr.Pixel ^.ARGB;180 DstPtr.Pixel ^.ARGB := C;304 C := SrcPtr.PixelARGB; 305 DstPtr.PixelARGB := C; 181 306 for YY := 0 to R.Height - 1 do begin 182 307 for XX := 0 to R.Width - 1 do begin 183 DstPtr.Pixel ^.ARGB := C;308 DstPtr.PixelARGB := C; 184 309 DstPtr.NextPixel; 185 310 end; … … 201 326 for Y := 0 to Bitmap.Height - 1 do begin 202 327 for X := 0 to Bitmap.Width - 1 do begin 203 Ptr.Pixel ^.ARGB := Color;328 Ptr.PixelARGB := Color; 204 329 Ptr.NextPixel; 205 330 end; … … 218 343 for Y := 0 to Rect.Height - 1 do begin 219 344 for X := 0 to Rect.Width - 1 do begin 220 Ptr.Pixel ^.ARGB := Color;345 Ptr.PixelARGB := Color; 221 346 Ptr.NextPixel; 222 347 end; … … 235 360 for Y := 0 to Bitmap.Height - 1 do begin 236 361 for X := 0 to Bitmap.Width - 1 do begin 237 Ptr.Pixel ^.ARGB := SwapRedBlue(Ptr.Pixel^.ARGB);362 Ptr.PixelARGB := SwapRedBlue(Ptr.PixelARGB); 238 363 Ptr.NextPixel; 239 364 end; … … 252 377 for Y := 0 to Bitmap.Height - 1 do begin 253 378 for X := 0 to Bitmap.Width - 1 do begin 254 Ptr.Pixel ^.ARGB := Ptr.Pixel^.ARGB xor $ffffff;379 Ptr.PixelARGB := Ptr.PixelARGB xor $ffffff; 255 380 Ptr.NextPixel; 256 381 end; … … 272 397 for Y := 0 to Bitmap.Height - 1 do begin 273 398 for X := 0 to Bitmap.Width - 1 do begin 274 A := Ptr.Pixel ^.A; //(Ptr.Pixel^.A + Pixel.A) shr 1;275 R := (Ptr.Pixel ^.R + Pixel.R) shr 1;276 G := (Ptr.Pixel ^.G + Pixel.G) shr 1;277 B := (Ptr.Pixel ^.B + Pixel.B) shr 1;278 Ptr.Pixel ^.ARGB := Color32(A, R, G, B);399 A := Ptr.PixelA; //(Ptr.PixelA + Pixel.A) shr 1; 400 R := (Ptr.PixelR + Pixel.R) shr 1; 401 G := (Ptr.PixelG + Pixel.G) shr 1; 402 B := (Ptr.PixelB + Pixel.B) shr 1; 403 Ptr.PixelARGB := Color32(A, R, G, B); 279 404 Ptr.NextPixel; 280 405 end;
Note:
See TracChangeset
for help on using the changeset viewer.