[Managed C#] masking using a paletted mask-map

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

GIF or PNG are more usual indexed formats. ;)

Are those the exact BMP files you're loading from?
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

yes the exact ones, I tried turning them into PNG, the results didn't change a bit, I can try GIF I guess
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

You're not going to believe how I "solved" it.

Code: Select all

if (SourceMaskArray[i] >= index) SourceImageArray[i-(int)(i/Width)] = 0;
Apparently you have to substact the row number, the images are the exact same size, maybe they marshal.copy is uhm.. bad?
But it only solves the problem for the problem-pictures, the good ones are messed up in same way now (so I'll have to figure out a way to determine whether a picture is good or not)
And there are those that need 2 or 3 times the row-number substracted.

But I guess this narrows down the problem to uhm.. well to what? It defenitly has something to do with not-matching widths.. Even if the pictures have the same size..
Last edited by King Harold on Wed 01 Nov, 2006 8:18 pm, edited 1 time in total.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

it seems that the closer the width and hight are the better the result (the squarer the better)..

edit: no that was just coincidence, maybe its random..?
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

This is really very strange.

Could you possibly zip up a few "good" and "bad" images and email them (or similar) to me? I'll have a look at this more closely, but you'll have to wait until tomorrow I'm afraid. :\
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Ok, many thanks :D
sometimes the outside builds a bit strangely, but when the wooden frame is added under it it looks almost normal, the wood should be build first - then the stone is build over it
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Oh dear.

Take a look at the width of the images that do work, then the width of those that don't.

The ones that do are multiples of 8 pixels wide, so are multiples of 8 bytes wide. The stride (width in bytes) of these images are always multiples of 8 bytes.

I've not thought of this as the images I usually deal with are 32bpp and even widths (and as each pixel is 4 bytes, I just have to make them even widths to let the stride "fit").

I've uploaded a fixed project that works, taking the stride of the image into consideration. :)

Image

The palette order is still rather weird... I'm hoping there's some reference somewhere as to which order the palette should really be.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Wow!
It really works :D I can not thank you enough

If I may ask, how did you find out?
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Lucky guess again, really. I just noticed that the ones that worked were multiples of eight wide, then remembered about the stride. A bit of debugging showed that no, the stride was different to the width for a few of the images.

Do you have any sort of image that lists the colours in the "correct" order? I can't really see any obvious pattern to which is the first and which is the last colour to fill.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

The order appears to be.. strange.. I'll ask the artist, who surely knows why he made the pictures like this..
I'll be glad to let you know :)

Edit: changing the order shouldn't be the hardest thing to do (unless there's a pitfall like this again)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

The artist said it was supposed to be this way, well, allright, we'll see how it will look..
He could have told us about the stride thing though.. :P
Post Reply