News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Graying bitmaps

Started by lamer, September 07, 2005, 10:25:42 AM

Previous topic - Next topic

lamer

Hi all!
I have written procedure for drawing gray scale images. Somebody may find it usefull. The procedure uses GDI+ and is much faster than known GDI way (with SetPixel etc).

[attachment deleted by admin]

QvasiModo

Cool :U

Did you compare it against a GDI equivalent that uses raw bitmap access, instead of GetPixel/SetPixel?

P1

Thanks !!!   :clap:

Regards,  P1  :8)

lamer

QvasiModo,
What is "raw bitmap access"?
Once I saw a code snippet written in C++, that used DIB section by changing bytes in byte array in 2-dimensional loop (Width x Height). It is of course faster, than  GetPixel/SetPixel, but I even did not try to apply the code to asm - frankly speaking, I had no time and no need then.

QvasiModo

It's exactly that - accessing the bitmap data directly as an array. Tipically you do this with a DIB bitmap, because you can control it's format. There's lots of code to do this in ASM, I'll search the board a while and see what I can find...

EDIT: Some links...

At MSDN:
http://msdn.microsoft.com/library/en-us/gdi/bitmaps_233i.asp

At the board:
http://www.masmforum.com/simple/index.php?topic=1114.0
http://www.masmforum.com/simple/index.php?topic=2047.0

lamer

I'll try to write something with DIB and then compare results of two methods on any large image. If the job tasks will allow  :bg

QvasiModo

Donkey already wrote a lib to do that :thumbu you can find it here:
http://donkey.visualassembler.com/


lamer

The code of Donkey does not want to work - sure I do something wrong, but it does not compile when I open it as GoAsm, and when trying to translate the GrayScale.asm to MASM - it compiles but then crushes on attempt to "gray" the bitmap. :green
A bit of statistics: graying bitmap of size 3456 x 864 (3 desktops of 17'' monitors) takes at an average 600 ms. with GDI+. Not bad... :green2

QvasiModo

Maybe this could be the problem?

QuoteGraphics.lib
This library only functions with 32bit DIB sections

I don't know about the problems compiling the code, but just to test out the library you could simply include the precompiled static library in a project.

lamer

QuoteThis library only functions with 32bit DIB sections
Definitely!
Everything is working now (at least with LIB). Thanks!
But the difference is that you MUST convert any bitmap to 32bit, while GDI+ does not asks it (till now). I just have no such big bitmap at home - there is one monitor only :bdg :bdg - so I'll run the test on Monday.

By the way, here the more accurate initialization for ColorMatrix structure from GDI+ example:
clrmx  ColorMatrix  <0.299,0.299,0.299,0.0,0.0,0.587,0.587,0.587,0.0,0.0,0.114,0.114,0.114,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0>

QvasiModo

Quote from: lamer on September 08, 2005, 04:48:04 PM
But the difference is that you MUST convert any bitmap to 32bit, while GDI+ does not asks it (till now)

Yes, I'm still curious about the speed, but the GDI+ version is definitely more versatile. :clap:

lamer

Hi!
I guessed that GDI was faster, but so much!!! :eek
GDI+ for 3456 x 864 bitmap is still about 600 ms.
Donkey's procedures for the same bitmap - 70 ms :clap:
Bravo!

Vortex

lamer,

Very impressive work, congrats :U

donkey

#13
Hi,

Just to update the link for my lib in this thread...

http://www.quickersoft.com/donkey/index.html

Note that the descision to use only 32 bit DIB sections was for TBPaint and I never bothered with other color depths because of the speed advantages involved which are impressive when compared with more general purpose algorithms. At any rate I don't use anything but 32 bit internally in my applications but they can easily be modified to other depths however with significant loss of speed as the address and/or colour calculations are more complex.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable