mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-20 10:19:23 +02:00
Examples: Adapt comments and code in the "scanline" sample project. Issue #41003.
(cherry picked from commit 52fc791feb
)
Co-authored-by: wp_xyz <wp_xxyyzzz@gmx.net>
This commit is contained in:
parent
ea0c4a2b76
commit
7bca626c0a
@ -1,26 +1,26 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="5"/>
|
<Version Value="12"/>
|
||||||
<General>
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<LRSInOutputDirectory Value="False"/>
|
||||||
|
<CompatibilityMode Value="True"/>
|
||||||
|
</Flags>
|
||||||
<SessionStorage Value="InProjectDir"/>
|
<SessionStorage Value="InProjectDir"/>
|
||||||
<MainUnit Value="0"/>
|
|
||||||
<IconPath Value="./"/>
|
|
||||||
<TargetFileExt Value=""/>
|
|
||||||
<Title Value="project1"/>
|
<Title Value="project1"/>
|
||||||
</General>
|
</General>
|
||||||
<VersionInfo>
|
<BuildModes Count="1">
|
||||||
<ProjectVersion Value=""/>
|
<Item1 Name="default" Default="True"/>
|
||||||
</VersionInfo>
|
</BuildModes>
|
||||||
<PublishOptions>
|
<PublishOptions>
|
||||||
<Version Value="2"/>
|
<Version Value="2"/>
|
||||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
|
||||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
|
||||||
</PublishOptions>
|
</PublishOptions>
|
||||||
<RunParams>
|
<RunParams>
|
||||||
<local>
|
<FormatVersion Value="2"/>
|
||||||
<FormatVersion Value="1"/>
|
<Modes Count="1">
|
||||||
</local>
|
<Mode0 Name="default"/>
|
||||||
|
</Modes>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="1">
|
<RequiredPackages Count="1">
|
||||||
<Item1>
|
<Item1>
|
||||||
@ -35,30 +35,30 @@
|
|||||||
</Unit0>
|
</Unit0>
|
||||||
<Unit1>
|
<Unit1>
|
||||||
<Filename Value="unit1.pas"/>
|
<Filename Value="unit1.pas"/>
|
||||||
<ComponentName Value="Form1"/>
|
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<ResourceFilename Value="unit1.lrs"/>
|
<ComponentName Value="Form1"/>
|
||||||
|
<HasResources Value="True"/>
|
||||||
|
<ResourceBaseClass Value="Form"/>
|
||||||
<UnitName Value="Unit1"/>
|
<UnitName Value="Unit1"/>
|
||||||
</Unit1>
|
</Unit1>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="5"/>
|
<Version Value="11"/>
|
||||||
<SearchPaths>
|
<Parsing>
|
||||||
|
<SyntaxOptions>
|
||||||
</SearchPaths>
|
<UseAnsiStrings Value="False"/>
|
||||||
<CodeGeneration>
|
</SyntaxOptions>
|
||||||
<Generate Value="Faster"/>
|
</Parsing>
|
||||||
</CodeGeneration>
|
|
||||||
<Linking>
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<DebugInfoType Value="dsDwarf3"/>
|
||||||
|
</Debugging>
|
||||||
<Options>
|
<Options>
|
||||||
<Win32>
|
<Win32>
|
||||||
<GraphicApplication Value="True"/>
|
<GraphicApplication Value="True"/>
|
||||||
</Win32>
|
</Win32>
|
||||||
</Options>
|
</Options>
|
||||||
</Linking>
|
</Linking>
|
||||||
<Other>
|
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
|
||||||
</Other>
|
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
</CONFIG>
|
</CONFIG>
|
||||||
|
@ -8,14 +8,15 @@ object Form1: TForm1
|
|||||||
Caption = 'Form1'
|
Caption = 'Form1'
|
||||||
ClientHeight = 144
|
ClientHeight = 144
|
||||||
ClientWidth = 623
|
ClientWidth = 623
|
||||||
|
LCLVersion = '3.99.0.0'
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
OnDestroy = FormDestroy
|
OnDestroy = FormDestroy
|
||||||
OnPaint = FormPaint
|
OnPaint = FormPaint
|
||||||
object Label1: TLabel
|
object Label1: TLabel
|
||||||
Left = 156
|
Left = 156
|
||||||
Height = 43
|
Height = 15
|
||||||
Top = 42
|
Top = 42
|
||||||
Width = 348
|
Width = 380
|
||||||
Caption = 'You should see a small rectangle filled with black and a diagonal red line'
|
Caption = 'You should see a small rectangle filled with black and a diagonal red line'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
WordWrap = True
|
WordWrap = True
|
||||||
|
@ -55,7 +55,7 @@ type
|
|||||||
private
|
private
|
||||||
public
|
public
|
||||||
MyBitmap: TBitmap;
|
MyBitmap: TBitmap;
|
||||||
procedure PaintToRGB32bitScanLine(Row, ImgWidth: integer; LineStart: Pointer);
|
procedure PaintToRGBScanLine(Row, ImgWidth: integer; LineStart: Pointer);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -76,22 +76,22 @@ var
|
|||||||
begin
|
begin
|
||||||
MyBitmap:=TBitmap.Create;
|
MyBitmap:=TBitmap.Create;
|
||||||
|
|
||||||
// create an image with a format similar to Delphi's pf32bit
|
// Create an image with a format similar to Delphi's pf24bit.
|
||||||
// keep in mind that you access it in bytes, not words or dwords
|
// Keep in mind that you access it in bytes, not words nor dwords
|
||||||
// For example PowerPC uses another byte order (endian big)
|
// For example PowerPC uses another byte order (endian big)
|
||||||
ScanLineImage:=TLazIntfImage.Create(0,0);
|
ScanLineImage:=TLazIntfImage.Create(0,0);
|
||||||
ImgFormatDescription.Init_BPP32_B8G8R8_BIO_TTB(30,20);
|
ImgFormatDescription.Init_BPP24_B8G8R8_BIO_TTB(30,20);
|
||||||
ScanLineImage.DataDescription:=ImgFormatDescription;
|
ScanLineImage.DataDescription:=ImgFormatDescription;
|
||||||
|
|
||||||
// call the pf24bit specific drawing function
|
// call the pf24bit specific drawing function
|
||||||
for y:=0 to ScanLineImage.Height-1 do
|
for y:=0 to ScanLineImage.Height-1 do
|
||||||
PaintToRGB32bitScanLine(y,ScanLineImage.Width,
|
PaintToRGBScanLine(y, ScanLineImage.Width, ScanLineImage.GetDataLineStart(y));
|
||||||
ScanLineImage.GetDataLineStart(y));
|
|
||||||
|
|
||||||
// create IntfImage with the format of the current LCL interface
|
// create IntfImage with the format of the current LCL interface
|
||||||
MyBitmap.Width:=ScanLineImage.Width;
|
MyBitmap.Width:=ScanLineImage.Width;
|
||||||
MyBitmap.Height:=ScanLineImage.Height;
|
MyBitmap.Height:=ScanLineImage.Height;
|
||||||
IntfImage:=MyBitmap.CreateIntfImage;
|
IntfImage:=MyBitmap.CreateIntfImage;
|
||||||
|
|
||||||
// convert the content from the very specific to the current format
|
// convert the content from the very specific to the current format
|
||||||
IntfImage.CopyPixels(ScanLineImage);
|
IntfImage.CopyPixels(ScanLineImage);
|
||||||
MyBitmap.LoadFromIntfImage(IntfImage);
|
MyBitmap.LoadFromIntfImage(IntfImage);
|
||||||
@ -110,19 +110,21 @@ begin
|
|||||||
Canvas.Draw(10,10,MyBitmap);
|
Canvas.Draw(10,10,MyBitmap);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.PaintToRGB32bitScanLine(Row, ImgWidth: integer;
|
procedure TForm1.PaintToRGBScanLine(Row, ImgWidth: integer;
|
||||||
LineStart: Pointer);
|
LineStart: Pointer);
|
||||||
// LineStart is pointer to the start of a scanline with the following format:
|
// LineStart is a pointer to the start of a scanline with the following format:
|
||||||
// 4 bytes per pixel. First byte is blue, second green, third is red.
|
// - 3 bytes per pixel.
|
||||||
|
// - First byte is blue, second green, third is red.
|
||||||
// Black is 0,0,0, white is 255,255,255
|
// Black is 0,0,0, white is 255,255,255
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
// fill line with gray
|
// Fill line with background color
|
||||||
for i:=0 to (ImgWidth*4)-1 do
|
for i := 0 to ImgWidth * 3 - 1 do
|
||||||
PByte(LineStart)[i]:=0; // set red, green and blue to 0 (i.e. black)
|
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;
|
// 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;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user