Examples: Adapt comments and code in the "scanline" sample project. Issue #41003.

This commit is contained in:
wp_xyz 2024-06-27 19:45:57 +02:00
parent e636177387
commit 52fc791feb
3 changed files with 44 additions and 41 deletions

View File

@ -1,26 +1,26 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="5"/>
<Version Value="12"/>
<General>
<Flags>
<LRSInOutputDirectory Value="False"/>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=""/>
<Title Value="project1"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
<FormatVersion Value="2"/>
<Modes Count="1">
<Mode0 Name="default"/>
</Modes>
</RunParams>
<RequiredPackages Count="1">
<Item1>
@ -35,30 +35,30 @@
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/>
<ResourceFilename Value="unit1.lrs"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<SearchPaths>
</SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Version Value="11"/>
<Parsing>
<SyntaxOptions>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</CONFIG>

View File

@ -8,14 +8,15 @@ object Form1: TForm1
Caption = 'Form1'
ClientHeight = 144
ClientWidth = 623
LCLVersion = '3.99.0.0'
OnCreate = FormCreate
OnDestroy = FormDestroy
OnPaint = FormPaint
object Label1: TLabel
Left = 156
Height = 43
Height = 15
Top = 42
Width = 348
Width = 380
Caption = 'You should see a small rectangle filled with black and a diagonal red line'
ParentColor = False
WordWrap = True

View File

@ -55,7 +55,7 @@ type
private
public
MyBitmap: TBitmap;
procedure PaintToRGB32bitScanLine(Row, ImgWidth: integer; LineStart: Pointer);
procedure PaintToRGBScanLine(Row, ImgWidth: integer; LineStart: Pointer);
end;
var
@ -76,22 +76,22 @@ var
begin
MyBitmap:=TBitmap.Create;
// create an image with a format similar to Delphi's pf32bit
// keep in mind that you access it in bytes, not words or dwords
// Create an image with a format similar to Delphi's pf24bit.
// Keep in mind that you access it in bytes, not words nor dwords
// For example PowerPC uses another byte order (endian big)
ScanLineImage:=TLazIntfImage.Create(0,0);
ImgFormatDescription.Init_BPP32_B8G8R8_BIO_TTB(30,20);
ImgFormatDescription.Init_BPP24_B8G8R8_BIO_TTB(30,20);
ScanLineImage.DataDescription:=ImgFormatDescription;
// call the pf24bit specific drawing function
for y:=0 to ScanLineImage.Height-1 do
PaintToRGB32bitScanLine(y,ScanLineImage.Width,
ScanLineImage.GetDataLineStart(y));
PaintToRGBScanLine(y, ScanLineImage.Width, ScanLineImage.GetDataLineStart(y));
// create IntfImage with the format of the current LCL interface
MyBitmap.Width:=ScanLineImage.Width;
MyBitmap.Height:=ScanLineImage.Height;
IntfImage:=MyBitmap.CreateIntfImage;
// convert the content from the very specific to the current format
IntfImage.CopyPixels(ScanLineImage);
MyBitmap.LoadFromIntfImage(IntfImage);
@ -110,19 +110,21 @@ begin
Canvas.Draw(10,10,MyBitmap);
end;
procedure TForm1.PaintToRGB32bitScanLine(Row, ImgWidth: integer;
procedure TForm1.PaintToRGBScanLine(Row, ImgWidth: integer;
LineStart: Pointer);
// LineStart is pointer to the start of a scanline with the following format:
// 4 bytes per pixel. First byte is blue, second green, third is red.
// LineStart is a pointer to the start of a scanline with the following format:
// - 3 bytes per pixel.
// - First byte is blue, second green, third is red.
// Black is 0,0,0, white is 255,255,255
var
i: Integer;
begin
// fill line with gray
for i:=0 to (ImgWidth*4)-1 do
PByte(LineStart)[i]:=0; // set red, green and blue to 0 (i.e. black)
// set one pixel to red (this creates a red line)
PByte(LineStart)[(Row mod ImgWidth)*4+2]:=255;
// Fill line with background color
for i := 0 to ImgWidth * 3 - 1 do
PByte(LineStart)[i] := 0; // Set red, green and blue to 0 (i.e. black)
// Set one pixel to red (this creates a red line)
PByte(LineStart)[(Row mod ImgWidth) * 3 + 2] := 255; // We add 2 to address the "red" byte
end;
end.