News:

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

Graphics

Started by Jimg, February 16, 2009, 01:47:52 AM

Previous topic - Next topic

Jimg

Quote from: NightWare on April 18, 2009, 03:09:05 AM
for the copy :
>mov ecx,100         ; size of the dib
no, width or height of the dib, if you want, but not the size
yes, I added some quick comments before posting and blew it.
Quote... plus why do you set this width/height for the Y source start ? should be zero... you copy from 0,0 to 99,99 no ? should be :
inv SetDIBitsToDevice,hdc,prevmcx,prevmcy,prevmw,prevmh,0,0,0,100,dibmc.bits,addr dibmc.bih,DIB_RGB_COLORS
This is exactly what I tried the first time.  It works except at the top and bottom.
Quotedito for the restore code, should be :
inv SetDIBitsToDevice,hdc,prevmcx,prevmcy,prevmw,prevmh,0,0,0,100,dibh1.bits,addr dibh1.bih,DIB_RGB_COLORS
Again, exactly what I did the first time.  This doesn't work at all.  It just always copies the 100 x 100 square from the lower left corner.
Quoteremember that the unique case where you don't have 0,0,0,height, it's when you don't start to copy from 0,0 coords of the source
Yes, again, that's what I do.

I'll try to put together a simple test case later today.

Jimg

Ok, here's a test program.

It's set up to do what I think you said.
Find method and change method and methodx to a 1 for the way I'm doing it now that works.

[attachment deleted by admin]

NightWare

wow... you don't use the functions like it should... ok,

first, you shouldn't store the entire client area (only the 100*100 background, where the cursor will be drawn), it means that you MUST store the background JUST BEFORE drawing the cursor. why ? because the client area could change... here you use RECT.right/RECT.bottom of the client area for the width/height... and in the contrary you should use a RECT structure but with RECT.left/RECT.top for the coords and RECT.right should be RECT.left+width(100) and RECT.bottom should be RECT.top+height(100).

second, when you restore you MUST use the COORDS and SIZE of your backup (it means you must store/use them), coz in your example you restore the entire client area (minored by your position coords)... and of course, in a normal use the coords change, so here you can't restore them in a normal use of the function.

i understand better why it took you some time to obtain a good result, if you would have defined a RECT structure for the client area (the limits), AND a RECT structure for the cursor/background (your work) you would have completed your work considerably faster.

Jimg

Quote from: NightWare on April 19, 2009, 12:41:34 AM
wow... you don't use the functions like it should... ok,

first, you shouldn't store the entire client area (only the 100*100 background, where the cursor will be drawn), it means that you MUST store the background JUST BEFORE drawing the cursor. why ? because the client area could change... here you use RECT.right/RECT.bottom of the client area for the width/height... and in the contrary you should use a RECT structure but with RECT.left/RECT.top for the coords and RECT.right should be RECT.left+width(100) and RECT.bottom should be RECT.top+height(100).
I do all my drawing and such on the full sized hidden buffer dibh1.  I copy it to the screen when needed.  There are no changes to the client area that I am not in control of.  At anytime I need to restore the client area, I can just copy the affected portion from the hidden buffer.  That's the whole purpose.
For the 100*100 cursor buffer, it just a temporary scratch dib to create a blend of the cursor with the background.  I could use a RECT to store coordinates, but since the api didn't call for it, I saw no reason to create the extra complexity.  Perhaps my attempt to make a small test program was confusing.
Quote
second, when you restore you MUST use the COORDS and SIZE of your backup (it means you must store/use them), coz in your example you restore the entire client area (minored by your position coords)... and of course, in a normal use the coords change, so here you can't restore them in a normal use of the function.
Now this is confusing.  What do you mean?  I'm only restoring a 100*100 area that I put the cursor in, not the whole screen.  I'm restoring it from the hidden back buffer, but only the portion needed.
Quote
i understand better why it took you some time to obtain a good result, if you would have defined a RECT structure for the client area (the limits), AND a RECT structure for the cursor/background (your work) you would have completed your work considerably faster.
Clearly I'm not understanding your point.  How could storing the values in a RECT structure make any difference.  They are just coordinates and sizes.  I prefer using using a name that is what is says, the width or height, which is what the api wants, rather than .right and .bottom which is definitely not what the api is asking for.  I only used a RECT at all because that's what GetClientRect required.  I really think all this confusion is because the documentation for SetDIBitsToDevice is so ambiguous, just like I was trying to say above.  I still don't know what they had in mine with all these parameters compared to a simple bitblt, but it certainly is confusing.

dwWidth  Specifies the width, in logical units, of the DIB.   Is this really the width of the dib, or just the number of pixels you want to transfer?

dwHeight Specifies the height, in logical units, of the DIB. Same here.

XSrc  Specifies the x-coordinate, in logical units, of the lower-left corner of the DIB.  This is always zero, unless it means the first pixel across the width to use, in which case, it is very poorly written.

YSrc  Specifies the y-coordinate, in logical units, of the lower-left corner of the DIB.  Why the lower left?

uStartScan  Specifies the starting scan line in the DIB.  Why would you need that?  I just told you the answer in YSrc.

cScanLines  Specifies the number of DIB scan lines contained in the array pointed to by the lpvBits parameter.   Why ask me this?  It that really what it wants?


I've seen some really badly designed and documented apis, but this is near the top of the list.


The bottom line is, it's the only tool available for the job (disregarding directx, etc.), and I'm going to figure out what these parameters really are and how to use them.

NightWare

ok, i'm going to change your test code, for a normal use of the function, i will post it tomorrow  :wink

NightWare

#50
 :wink as promised, the code

in the code, SetDIBitsToDevice is only used once (for the win update), all the others you have included before were totally useless (coz you can't make a copy of the background with this function, it's in the sens Dib To Dc), and that confused me a lot... i've spent an afternoon to understand the logic behind everything... MWAAAAARGGGGG !!!! (i know, it's noisy, but i feel better now... :bg)

i haven't modified the alpha part, (spent enough time... i've just used a hack to simulate an alpha) so you will have to re-work it a bit...

EDIT : oops i've just seen i've forgotten to correct the paths, updated

[attachment deleted by admin]

Jimg

Okay, you are copying every pixel every time.  Certainly I could have done that, but I wanted to update only the portion of the screen that was affected, not the whole screen.

You could see I already knew how to update the whole screen.

The point of my tirade, was that I wanted to know how to update just a portion of the screen as needed, and to do so it was difficult to figure out what the parameters should be.


I just did a time test, and with the 1248*718 area i'm using, it takes over 20000 cycles to update the whole screen but less than 700 to update a 100 x 100 square twice.

NightWare

hmm... it seams it's complicate when you just include a portion, the problem comme from the height when you don't start at the 0 y coord. coz the DC is vertically reversed. this seams to work for the restore part :

mov edx,ClientArea.bottom
sub edx,BackUpPos.y
sub edx,BackUpSizes.y
    inv SetDIBitsToDevice,hDC,BackUpPos.x,BackUpPos.y,BackUpSizes.x,BackUpSizes.y,BackUpPos.x,edx,0,ClientArea.bottom,DibClient.pBits,ADDR DibClient.sBIH,DIB_RGB_COLORS



Farabi

Hai,
Im using Nighware Blending function and Donkey Graphics Library.
Cool is not it?  :green



Im uploading it to my FaceBook account as a video and I want to upload it to youtube but got no time. I created that video to impress my friend, and they are really impressed  :lol .
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

UtillMasm

where's your video? :bg

Farabi

It should be here soon http://www.youtube.com/watch?v=gcdpkwgN7hw I hope youtube able to process it.
Dont listen to the audio or translate it, it just me braging how smart I am  :green .
I forget to say thank you to donkey and nightware for their kindness and hardwork.

This is where facebook store it but I dont know can it be opened. http://www.facebook.com/v/1094820170800
And this video is about my face recognition test http://www.facebook.com/v/1095210940569
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Jimg

Quote from: NightWare on April 21, 2009, 02:42:36 AM
hmm... it seams it's complicate when you just include a portion, the problem comme from the height when you don't start at the 0 y coord. coz the DC is vertically reversed. this seams to work for the restore part :

mov edx,ClientArea.bottom
sub edx,BackUpPos.y
sub edx,BackUpSizes.y
    inv SetDIBitsToDevice,hDC,BackUpPos.x,BackUpPos.y,BackUpSizes.x,BackUpSizes.y,BackUpPos.x,edx,0,ClientArea.bottom,DibClient.pBits,ADDR DibClient.sBIH,DIB_RGB_COLORS


A slightly simpler method:
    mov ecx,y     ; starting scan line wanted
    add ecx,sizey ; number of scan lines from top to last line wanted
    inv SetDIBitsToDevice,hdc,x,y,sizex,sizey,x,y,y,ecx,dibbits,addr dibbih,DIB_RGB_COLORS

NightWare

Quote from: Jimg on April 21, 2009, 04:49:26 PM
A slightly simpler method:
mov ecx,y ; starting scan line wanted
add ecx,sizey ; number of scan lines from top to last line wanted
inv SetDIBitsToDevice,hdc,x,y,sizex,sizey,x,y,y,ecx,dibbits,addr dibbih,DIB_RGB_COLORS

well seen jimg  :U

in fact the documentation of windows is correct, coz in "normal" use the first line is the last one (the -1/neg possibillity for the height is just an option, for a more readable/logical representation...). the problem is there is no warning about the possible use of the option.