Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / dbMakeMemblock and dbMakeImageFromMemblock issue.

Author
Message
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 9th Oct 2008 16:19
Hello.
I have this code:


Is fairly simple,it just creates a memblock,fill it with a RGBA color (red in this case) and then make an image with that memblock...
The issue is that its not working,it doesnt fill the entire image only the half or less.

Do you guys can find were i messing the code ?

Thank guys.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 9th Oct 2008 17:05
Quote: "dbWriteMemblockByte(iMemblockNumber,0,iImageWidth);
dbWriteMemblockByte(iMemblockNumber,4,iImageHeight);
dbWriteMemblockByte(iMemblockNumber,8,iImageDepth);"


These should be DWords.

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 9th Oct 2008 17:09
Thanks for the suggestion
Ive changed every dbWriteMemblockByte to dbWriteMemblockDword and the issue persist.
FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 9th Oct 2008 17:33
Thanks guys i just found my error, here is the correct version:
Quote: "
void CreateImage()
{
int iImageWidth = 32;
int iImageHeight = 32;
int iImageDepth = 32;
int iMemblockNumber = 1;
int iImageNumber = 1;

dbMakeMemblock(iMemblockNumber,12 + ((iImageWidth*iImageHeight)*4));
dbWriteMemblockByte(iMemblockNumber,0,iImageWidth);
dbWriteMemblockByte(iMemblockNumber,4,iImageHeight);
dbWriteMemblockByte(iMemblockNumber,8,iImageDepth);

for(int i=1;i<= (iImageWidth*iImageHeight)-1;i++)
{
dbWriteMemblockByte(iMemblockNumber,12 + (i-1)*4,0); //B
dbWriteMemblockByte(iMemblockNumber,13 + (i-1)*4,0); //G
dbWriteMemblockByte(iMemblockNumber,14 + (i-1)*4,255);//R
dbWriteMemblockByte(iMemblockNumber,15 + (i-1)*4,255);//A
}

dbMakeImageFromMemblock(iImageNumber,iMemblockNumber);
dbPasteImage(iImageNumber,10,10);

}
"


My mistake was that i was making the memblock too small.
Cheers guys.
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 10th Oct 2008 11:33 Edited at: 10th Oct 2008 11:35
With this line
Quote: "for(int i=1;i <= (iImageWidth*iImageHeight)-1;i++)"

You will be going through the loop one time less than the number of pixels in the picture.

Either the first or the last pixel will not be processed.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 10th Oct 2008 12:47
Quote: "Ive changed every dbWriteMemblockByte to dbWriteMemblockDword and the issue persist."


Yeah, I must have been a bit tired to make a stupid mistake like that!

Quote: "You will be going through the loop one time less than the number of pixels in the picture."


He uses <= so he won't, though personally I'd loop from 0 to < pixel count as it requires far less pointless -1s you have everywhere.

FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 10th Oct 2008 15:15 Edited at: 10th Oct 2008 15:15
Thanks for all the sugestions.

Another question tough, is there any function like dbWriteMemblockByte() ,but to write 'chunks' of memory ?
or should i use memcpy() or something like that?

Again, thanks.
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 10th Oct 2008 16:14 Edited at: 10th Oct 2008 16:16
Quote: "He uses <= so he won't, though personally I'd loop from 0 to < pixel count as it requires far less pointless -1s you have everywhere."


In the code:
Quote: "for(int i=1;i<= (iImageWidth*iImageHeight)-1;i++)"


start condition is "i=1"
Loop termination is "i<= (iImageWidth*iImageHeight)-1;"

I think you may have not noticed the "-1" in the termination condition.

If he has an image of 1 Pixel, then the termination condition will be "i <= 0" and the "for loop" will never run the required one time.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 10th Oct 2008 16:25 Edited at: 10th Oct 2008 16:33
I agree that just < should be used so that -1 isn't necessary. And start at 0.



FERSIS
18
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 10th Oct 2008 18:28
I forgot to tell you guys that the missing pixel is my intention.

Login to post a reply

Server time is: 2024-09-30 07:30:36
Your offset time is: 2024-09-30 07:30:36