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

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Wrong order - so Im just blaming the artist.
Which seems the right thing to do since I checken them with the GIMP and I clicked the colours with teh colour picker and they were quite messed up, sometimes its ok for 20 levels and then it suddenly builds something.. odd..
http://www.freewebs.com/lawcompany/BadPalette.PNG
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

So much for random, this is quite insane:
http://www.freewebs.com/lawcompany/from ... arbled.PNG
a quick check with the GIMP however proved that this picture was completely normal, and then got.. messed up..
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I can't see those images.

I'm not sure if there's an easy way to reorder the palette. I had a similar issue - I wrote a script that generated an image in shades of grey, imported into Photoshop then saved as a GIF so I could use it's nice dithering (I was dropping to 16 colours). Strangely enough, the order of the palette was completely random, not the nice brightest->darkest (or the other way around) as I had been expecting - especially given that Photoshop was displaying the palette in a nice order before exporting.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

strange..strange.. so I have to write a program to sort them..?
(that last picture shows parts of a building, random diagonal parts, its has absolutely no reason whatsoever to do that, the mask picture has the same outlines)
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Ah, the last picture is a good one to show me. :)

Add this line as the first piece of code:

Code: Select all

if (sourceImage.Width != sourceMask.Width || sourceImage.Height != sourceMask.Height) throw new Exception("Mask and image must both be the same size.");
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

It's still doing it (they are the same size afterall)
Even that mangled and random thing, you know whats funny though? exactly that picture is doing it again, in exactly the same way, and an other one did it in an other way, also sometimes it show something that will disapear in the next frame (so with the build level increased by 1)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

If you want to try it out, here are the picture that caused the most trouble:
Image
Image
whats wrong with the [img] tag?
Last edited by King Harold on Tue 31 Oct, 2006 6:48 pm, edited 3 times in total.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

If you remove the for loop (that does the processing), the output should be identical to the input. Is this so, or does that too become garbled?
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Its the same as the imput, is that good?
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

King Harold wrote:Image
I'd need that in an indexed image format. :)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

It is, atleast it sais so for me, "1 layer - indexed - 8bit - 129 * 106"
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

King Harold wrote:Its the same as the imput, is that good?
Yes, as it narrows down what's going wrong. The problem now lies somewhere with the masking bit - either it's the wrong width (which would give you that characteristic "diagonal" pattern) which doesn't seem to be the case (you'd get an exception thrown), there's a bug in the for loop (which, given the simplicity of it, seems unlikely) or there's a bug in the way the pixel data is being read. I don't know which it is.

I'm still going on the assumption that a width is wrong somewhere - set a breakpoint on the "sourceMask.LockBits(...)" line and see if the FrameRectangle is still the same size (or recreate it in the line above, to make sure it's the same size).
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

I can't see the images any more in any case (use tinypic.com instead?) The problem with the image tags is that you're linking to evil upwards-loading Windows Bitmap files (that is, people have a habit of linking to 1024x768 24-bit BMPs, which doesn't please people on slow connections that much).
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

The size is ok, width 129, heigh 106, so that should fit, and yes the loop isn't really complex so it could hardly be the problem.. (shouldn't I get an Index out of Bounds if they arent the same size? its rather unlikely that 2 numbers multiplied are the same as 2 others)
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Post by King Harold »

Image = http://www.freewebs.com/lawcompany/Image00906.bmp
Image = http://www.freewebs.com/lawcompany/Image00908.bmp

links to stupid BMP's because jpg wouldn't be indexed
(if you're wondering what the 2 leading zero's are for.. there are 10884 images)

this should be the palette:
Image
and this is evil:
Image
Post Reply