Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
(Moderator:
Ask
) »
Fast pixel access
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
FPC Unleashed (inline var...
by
creaothceann
[
Today
at 06:44:18 am]
Sudden errors
by
egsuh
[
Today
at 06:16:42 am]
You can embed Windows Con...
by
Fibonacci
[
Today
at 04:18:40 am]
Conscious Artificial Inte...
by
schuler
[
Today
at 02:42:53 am]
Implementing an Elo ratin...
by
mas steindorff
[
Today
at 02:22:34 am]
[New Component] ExtTabCtr...
by
jianwt
[
Today
at 02:21:39 am]
Can /my/ AI help me with ...
by
microxa
[
Today
at 12:56:29 am]
IndySecOpenSSL is now ava...
by
TheMouseAUS
[
Today
at 12:08:51 am]
RunFormula: math expressi...
by
stormray
[June 17, 2026, 10:32:05 pm]
Codepage issue in console...
by
ASerge
[June 17, 2026, 09:36:27 pm]
Pdf Viewer in Pascal
by
Tomxe
[June 17, 2026, 07:18:20 pm]
Canvas size
by
Thaddy
[June 17, 2026, 07:15:50 pm]
[Reopened] TSaveDialog
by
Thaddy
[June 17, 2026, 05:12:17 pm]
What am I missing here? [...
by
Thaddy
[June 17, 2026, 03:39:02 pm]
Questions about 16 color ...
by
wp
[June 17, 2026, 01:45:07 pm]
TCHATGPT — An Artificial ...
by
Weiss
[June 17, 2026, 07:00:13 am]
RFC: Separation of MCU an...
by
ackarwow
[June 16, 2026, 11:06:14 pm]
Error with last fixes_3.2...
by
patyit
[June 16, 2026, 09:49:02 pm]
Mundo Medieval 3D MMORPG ...
by
Rodrigo Robles
[June 16, 2026, 06:06:17 pm]
Which Control should I us...
by
wp
[June 16, 2026, 05:08:55 pm]
Just Question App paramet...
by
eldonfsr
[June 16, 2026, 04:50:19 pm]
Content is distorting / w...
by
Handoko
[June 16, 2026, 03:53:02 pm]
ZxTune chiptunes player
by
Guva
[June 16, 2026, 12:41:14 pm]
Onscroll event for Tscrol...
by
laz_one_or2
[June 16, 2026, 11:16:39 am]
Fpcupdeluxe
by
CharlyTango
[June 16, 2026, 10:35:33 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Fast pixel access (Read 2752 times)
user5
Sr. Member
Posts: 419
Fast pixel access
«
on:
November 28, 2019, 02:00:15 pm »
In the code below lines 1 and 2 together do the same thing as line 3 except of course line 3 would be much slower if I used it in the code instead of lines 1 and 2. Line 1 uses a raw image fast pixel access method that is similar to BGRABitmap.
Line 5 accesses pixels next to x and y and I was wondering if anyone knows how I could use the fast pixel method to accomplish the same thing but at a faster speed.
Thanks and happy Thanksgiving morning!
Code: Pascal
[Select]
[+]
[-]
for
y
:
=
starty
to
(
mybitmap
.
height
-
1
)
do
begin
PixelPtr
:
=
PixelRowPtr
;
for
x
:
=
startx
to
(
mybitmap
.
width
-
1
)
do
begin
tempcolor
:
=
PixelPtr
^
;
//line 1
tempcolor
:
=
SwapRedBlue
(
tempcolor
)
;
//line 2
tempcolor
:
=
mybitmap
.
canvas
.
pixels
[
x
,
y
]
;
//line 3
newcolor
:
=
mybitmap
.
canvas
.
pixels
[
x
+
1
,
y
+
1
]
;
//line 5
end
;
end
;
Logged
user5
Sr. Member
Posts: 419
Re: Fast pixel access
«
Reply #1 on:
November 28, 2019, 02:04:31 pm »
Oops. Line 5 should have been: newcolor := mybitmap.canvas.pixels[x + 1,y]; //to access the pixel next to x
Logged
winni
Hero Member
Posts: 3197
Re: Fast pixel access
«
Reply #2 on:
November 28, 2019, 03:44:11 pm »
Hi!
There is a page about fast direct pixel access in Lazarus with a lot of examples:
https://wiki.freepascal.org/Fast_direct_pixel_access
No thanksgiving here tomorrow - just another Friday for Future.
Winni
Logged
user5
Sr. Member
Posts: 419
Re: Fast pixel access
«
Reply #3 on:
November 28, 2019, 07:31:32 pm »
I checked out the page you mentioned and it led me to some other sites but it seems like not enough information is provided. For example, I found the following code but I can't get it to work. "colGreen" from what I understand is supposed to be a TFPColor but the compiler wouldn't let me define something like var newcolor:TFPColor. I put in all the correct headers.
Code: Pascal
[Select]
[+]
[-]
procedure
TForm1
.
Button4Click
(
Sender
:
TObject
)
;
var
b
:
TBitmap
;
t
:
TLazIntfImage
;
begin
b
:
=
TBitmap
.
Create
;
try
b
.
LoadFromFile
(
'test.bmp'
)
;
t
:
=
b
.
CreateIntfImage
;
// Read and/or write to the pixels
t
.
Colors
[
10
,
20
]
:
=
colGreen
;
//This won't compile.
b
.
LoadFromIntfImage
(
t
)
;
finally
t
.
Free
;
b
.
Free
;
end
;
end
;
Logged
wp
Hero Member
Posts: 13585
Re: Fast pixel access
«
Reply #4 on:
November 28, 2019, 07:40:32 pm »
Just missing the "uses":
Code: Pascal
[Select]
[+]
[-]
uses
fpImage
,
// colGreen, TFPColor
IntfGraphics
;
// TLazIntfImage
Logged
user5
Sr. Member
Posts: 419
Re: Fast pixel access
«
Reply #5 on:
November 28, 2019, 07:48:58 pm »
You are absolutely correct. I was missing FPImage in the "uses" clause. It's working now. The old slow pixel method took 7 seconds to fill a 1053x655 image with the color red but the TLazIntfImage method did it almost instantaneously. Wow! I wonder if there's anything even faster. Thanks a lot.
Logged
user5
Sr. Member
Posts: 419
Re: Fast pixel access
«
Reply #6 on:
November 28, 2019, 07:52:33 pm »
Does the TFPColor "colRed" equal "clRed" or do I need a conversion of some kind?
Logged
user5
Sr. Member
Posts: 419
Re: Fast pixel access
«
Reply #7 on:
November 28, 2019, 08:08:13 pm »
Okay... I found the conversion function which converts a TColor to a TFPColor so that: newcolor := TColorToFPColor(tempcolor); newcolor is a TFPColor and tempcolor is a TColor. I also found the function which converts a TFPColor to a TColor. Thanks again for taking the time to help me. I really appreciate it. This seems to be what I need.
Logged
Soner
Sr. Member
Posts: 328
Re: Fast pixel access
«
Reply #8 on:
November 28, 2019, 08:52:23 pm »
Don't forget, TBitmap has Scanline property now. As someone the wikipage wrote, then tbitmap has not this property.
NOw, you can manipulate Tbitmap without TLazIntfImage faster.
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
Graphics and Multimedia
»
Graphics
(Moderator:
Ask
) »
Fast pixel access
TinyPortal
© 2005-2018