Hi Im using ASP.net / C#
My english is not very good, but i will try my best to explain what i need.
There are 2 questions:
Question 1) I want to be able to know the colour index of a pixel from a GIF format file.
With that I mean, as you know, a gif image file contains a colour palete, which is an array of length 256. Each array item from 0 to 255 contains a colour, and in GIF files, colours can be repeated in different positions. For example, I can have a grayscale palette, which will look something like this [#000000, #010101, #020202, ..., #FEFEFE, #FFFFFF], but in my case, all the colours are the same, lets say red:
[#FF0000,#FF0000,#FF000, ..., #FF0000]. That is perfectly valid in a GIF File, since each pixel is not tied to a colour, instead, it is tied to an index in the colour table. So even if the whole image is red (looks red), the actual bitmap data could be something like this:
(this code is conceptual, not actual C# code)
palete = redPalete; // [#ff0000,..., #ff0000] all red colours
pixelData = [[1,2,3,4,5,6,7,8,9,10 ... 256],
[1,2,3,4,5,6,7,8,9,10 ... 256],
[1,2,3,4,5,6,7,8,9,0 ... 256]]; //supose the pixel data is a matrix of colour indexes.
In this example, my image has all possible colours from the palette, but since the palette is all red, the image will look red.
Ok, that is ok, but now my problem, is...
How can I open that external GIF File, and iterate through pixels, retrieving its associated colour index in the palette table instead of the actual colour?? According to the previous example:
int colourIndex = miImage.getPixelColourIndex(0,0);
and i dont want to retrieve the value #ff0000, instead, i want to obtain the value 1.
and if i say:
int colourIndex = miImage.getPixelColourIndex(1,0); //colourIndex should be 2, since [[1,2,3 ....]
¿anyone got the idea of what i need? I need to know the colour index associated with a pixel, instead of the actual colour of that pixel (since several colour indexes can point to the same colour value, in this case red).
Question 2) Question 2 is exactly the opposite case. I want to write an indexed image (and then save it to GIF), according to the colour indexes values, instead of the colour.
That means, i want to do:
myImage.setPixel(0,0,1); //being setPixel(x, y, colourIndex);
i want that instead of saying the actual colour, which could look like:
myImage.setPixel(0,0,#ff0000); // I dont want this, i want to use the index value, not the colour, since my palette will contain all red values.
Please!!! I will sincerely appreciate help with this, I guess there is not a native function to do that, but probably there is a way around it, isnt it??
Thank you for reading and for your help in advance