Changeset 14 for trunk/UGraphic.pas
- Timestamp:
- Sep 22, 2014, 5:40:17 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGraphic.pas
r13 r14 15 15 TGBitmap = class; 16 16 17 TGColorFormatChannel = record 18 BitWidth: Integer; 19 Position: Integer; 20 end; 21 17 22 { TGColorFormat } 18 23 19 24 TGColorFormat = class 20 function GetBitDepth: Integer; virtual; 21 function GetPixelSize: Integer; virtual; 22 function GetName: string; virtual; 23 function GetChannelBitPos(Channel: TGColorChannel): Integer; virtual; 24 function GetChannelBitWidth(Channel: TGColorChannel): Integer; virtual; 25 BitDepth: Integer; 26 Name: string; 27 Channels: array[TGColorChannel] of TGColorFormatChannel; 28 constructor Create; virtual; 25 29 function GetChannelStateCount(Channel: TGColorChannel): Integer; virtual; 26 30 function ChannelUsed(Channel: TGColorChannel): Boolean; … … 233 237 { TGColorFormat } 234 238 235 function TGColorFormat.GetBitDepth: Integer; 236 begin 237 Result := 0; 238 end; 239 240 function TGColorFormat.GetPixelSize: Integer; 241 begin 242 Result := 0; 243 end; 244 245 function TGColorFormat.GetName: string; 246 begin 247 Result := ''; 248 end; 249 250 function TGColorFormat.GetChannelBitPos(Channel: TGColorChannel): Integer; 251 begin 252 253 end; 254 255 function TGColorFormat.GetChannelBitWidth(Channel: TGColorChannel): Integer; 256 begin 257 Result := 0; 239 constructor TGColorFormat.Create; 240 var 241 Channel: TGColorChannel; 242 begin 243 Name := ''; 244 BitDepth := 0; 245 for Channel := Low(TGColorChannel) to High(TGColorChannel) do begin 246 Channels[Channel].BitWidth := 0; 247 Channels[Channel].Position := 0; 248 end; 258 249 end; 259 250 260 251 function TGColorFormat.GetChannelStateCount(Channel: TGColorChannel): Integer; 261 252 begin 262 Result := 1 shl GetChannelBitWidth(Channel);253 Result := 1 shl Channels[Channel].BitWidth; 263 254 end; 264 255 265 256 function TGColorFormat.ChannelUsed(Channel: TGColorChannel): Boolean; 266 257 begin 267 Result := GetChannelBitWidth(Channel)> 0;258 Result := Channels[Channel].BitWidth > 0; 268 259 end; 269 260 … … 275 266 Channel := TBitMemory.Create; 276 267 277 if GetChannelBitWidth(ccRed)> 0 then begin278 Channel.Size := GetChannelBitWidth(ccRed);279 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccRed));268 if Channels[ccRed].BitWidth > 0 then begin 269 Channel.Size := Channels[ccRed].BitWidth; 270 Color.Data.ReadBlock(Channel, Channels[ccRed].Position); 280 271 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccRed) - 1)) shl 0); 281 272 end; 282 273 283 if GetChannelBitWidth(ccGreen)> 0 then begin284 Channel.Size := GetChannelBitWidth(ccGreen);285 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccGreen));274 if Channels[ccGreen].BitWidth > 0 then begin 275 Channel.Size := Channels[ccGreen].BitWidth; 276 Color.Data.ReadBlock(Channel, Channels[ccGreen].Position); 286 277 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccGreen) - 1)) shl 8); 287 278 end; 288 279 289 if GetChannelBitWidth(ccBlue)> 0 then begin290 Channel.Size := GetChannelBitWidth(ccBlue);291 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccBlue));280 if Channels[ccBlue].BitWidth > 0 then begin 281 Channel.Size := Channels[ccBlue].BitWidth; 282 Color.Data.ReadBlock(Channel, Channels[ccBlue].Position); 292 283 Result := Result or (Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccBlue) - 1)) shl 16); 293 284 end; 294 285 295 if GetChannelBitWidth(ccGray)> 0 then begin296 Channel.Size := GetChannelBitWidth(ccGray);297 Color.Data.ReadBlock(Channel, GetChannelBitPos(ccGray));286 if Channels[ccGray].BitWidth > 0 then begin 287 Channel.Size := Channels[ccGray].BitWidth; 288 Color.Data.ReadBlock(Channel, Channels[ccGray].Position); 298 289 Result := $010101 * Trunc(Channel.GetInteger * 255 / (GetChannelStateCount(ccGray) - 1)); 299 290 end; … … 309 300 Channel := TBitMemory.Create; 310 301 311 if GetChannelBitWidth(ccRed)> 0 then begin312 Channel.Size := GetChannelBitWidth(ccRed);302 if Channels[ccRed].BitWidth > 0 then begin 303 Channel.Size := Channels[ccRed].BitWidth; 313 304 Channel.SetInteger(((Color shr 0) and $ff) * GetChannelStateCount(ccRed) div 256); 314 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccRed));315 end; 316 317 if GetChannelBitWidth(ccGreen)> 0 then begin318 Channel.Size := GetChannelBitWidth(ccGreen);305 GColor.Data.WriteBlock(Channel, Channels[ccRed].Position); 306 end; 307 308 if Channels[ccGreen].BitWidth > 0 then begin 309 Channel.Size := Channels[ccGreen].BitWidth; 319 310 Channel.SetInteger(((Color shr 8) and $ff) * GetChannelStateCount(ccGreen) div 256); 320 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccGreen));321 end; 322 323 if GetChannelBitWidth(ccBlue)> 0 then begin324 Channel.Size := GetChannelBitWidth(ccBlue);311 GColor.Data.WriteBlock(Channel, Channels[ccGreen].Position); 312 end; 313 314 if Channels[ccBlue].BitWidth > 0 then begin 315 Channel.Size := Channels[ccBlue].BitWidth; 325 316 Channel.SetInteger(((Color shr 16) and $ff) * GetChannelStateCount(ccBlue) div 256); 326 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccBlue));327 end; 328 329 if GetChannelBitWidth(ccGray)> 0 then begin330 Channel.Size := GetChannelBitWidth(ccGray);317 GColor.Data.WriteBlock(Channel, Channels[ccBlue].Position); 318 end; 319 320 if Channels[ccGray].BitWidth > 0 then begin 321 Channel.Size := Channels[ccGray].BitWidth; 331 322 Channel.SetInteger((((Color shr 16) and $ff) + ((Color shr 8) and $ff) + ((Color shr 0) and $ff)) 332 323 * GetChannelStateCount(ccGray) div (3 * 256)); 333 GColor.Data.WriteBlock(Channel, GetChannelBitPos(ccGray));324 GColor.Data.WriteBlock(Channel, Channels[ccGray].Position); 334 325 end; 335 326 … … 348 339 if FColorFormat = AValue then Exit; 349 340 FColorFormat := AValue; 350 FData.Size := FColorFormat. GetPixelSize;341 FData.Size := FColorFormat.BitDepth; 351 342 end; 352 343 … … 377 368 Channel := TBitMemory.Create; 378 369 379 if Format. GetChannelBitWidth(ccRed)> 0 then begin380 Channel.Size := Format. GetChannelBitWidth(ccRed);381 Data.ReadBlock(Channel, Format. GetChannelBitPos(ccRed));370 if Format.Channels[ccRed].BitWidth > 0 then begin 371 Channel.Size := Format.Channels[ccRed].BitWidth; 372 Data.ReadBlock(Channel, Format.Channels[ccRed].Position); 382 373 Channel.Invert; 383 Data.WriteBlock(Channel, Format. GetChannelBitPos(ccRed));384 end; 385 386 if Format. GetChannelBitWidth(ccGreen)> 0 then begin387 Channel.Size := Format. GetChannelBitWidth(ccGreen);388 Data.ReadBlock(Channel, Format. GetChannelBitPos(ccGreen));374 Data.WriteBlock(Channel, Format.Channels[ccRed].Position); 375 end; 376 377 if Format.Channels[ccGreen].BitWidth > 0 then begin 378 Channel.Size := Format.Channels[ccGreen].BitWidth; 379 Data.ReadBlock(Channel, Format.Channels[ccGreen].Position); 389 380 Channel.Invert; 390 Data.WriteBlock(Channel, Format. GetChannelBitPos(ccGreen));391 end; 392 393 if Format. GetChannelBitWidth(ccBlue)> 0 then begin394 Channel.Size := Format. GetChannelBitWidth(ccBlue);395 Data.ReadBlock(Channel, Format. GetChannelBitPos(ccBlue));381 Data.WriteBlock(Channel, Format.Channels[ccGreen].Position); 382 end; 383 384 if Format.Channels[ccBlue].BitWidth > 0 then begin 385 Channel.Size := Format.Channels[ccBlue].BitWidth; 386 Data.ReadBlock(Channel, Format.Channels[ccBlue].Position); 396 387 Channel.Invert; 397 Data.WriteBlock(Channel, Format. GetChannelBitPos(ccBlue));398 end; 399 400 if Format. GetChannelBitWidth(ccGray)> 0 then begin401 Channel.Size := Format. GetChannelBitWidth(ccGray);402 Data.ReadBlock(Channel, Format. GetChannelBitPos(ccGray));388 Data.WriteBlock(Channel, Format.Channels[ccBlue].Position); 389 end; 390 391 if Format.Channels[ccGray].BitWidth > 0 then begin 392 Channel.Size := Format.Channels[ccGray].BitWidth; 393 Data.ReadBlock(Channel, Format.Channels[ccGray].Position); 403 394 Channel.Invert; 404 Data.WriteBlock(Channel, Format. GetChannelBitPos(ccGray));395 Data.WriteBlock(Channel, Format.Channels[ccGray].Position); 405 396 end; 406 397 … … 462 453 function TGBitmap.GetPixelDataPos(X, Y: Integer): Integer; 463 454 begin 464 Result := X * FColorFormat. GetPixelSize + Y * FColorFormat.GetPixelSize* FSize.X;455 Result := X * FColorFormat.BitDepth + Y * FColorFormat.BitDepth * FSize.X; 465 456 end; 466 457 … … 496 487 function TGBitmap.GetDataSize: Integer; 497 488 begin 498 Result := Size.X * Size.Y * FColorFormat. GetPixelSize;489 Result := Size.X * Size.Y * FColorFormat.BitDepth; 499 490 end; 500 491
Note:
See TracChangeset
for help on using the changeset viewer.