Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Help with Painting !!
Help with Painting !! [message #454207] Tue, 19 April 2005 05:01 Go to next message
Eclipse UserFriend
Originally posted by: aaa.domain.invalid

Hello,

Please help me overcome this issue with painting a image before placing
it on the composite.


Region (a) is white and transparent.
Region (b) is black.
The image has 2 colors and is depth is I bit per pixel.

|-------------------|
| (a) |
| |
| |---------| |
| | | |
| | | |
| | (b) | |
| | | |
| |---------| |
| |
| |
|-------------------|
When I place this image on a composite region (a) correctly get the
color of the composite it lies on.
Now I want to change region (b) to have the foreground color of the
composite.

Problem 1.
==========
I cannot chage the color of region (b) to the forground color of the
composite it is on.
Problem 2
==========
If the fore ground color of the composite is white, changing the color
of region (b) to white will make it transparent too as the transparent
color is white.


Code
====
Here is what I do , if I find a black pixel I change it to white which
makes the complete image transparent.
If I use any value other than FFFFFF region (b)becomes black.

I am clueless... HELP!!!

for(int i=0; i<img_data.width; i++) {
for(int j=0; j<img_data.height; j++) {
RGB rgb = img_data.palette.getRGB(img_data.getPixel(i, j));
int threshold = 0;

if(rgb.red == threshold && rgb.green == threshold && rgb.blue ==
threshold)
img_data.setPixel(i, j, 0xFFFFFF);

}
}



-Chhil
p.s. I have posted a similar post earlier.
Re: Help with Painting !! [message #454212 is a reply to message #454207] Tue, 19 April 2005 07:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: doug-list.threepenny.net

I'm not that familiar with SWT's graphic code but assuming that SWT is
using the native Windows (or OS) bitmaps I can tell you that:

A 1-bit per pixel image is by definition a black and white image, so
you're only going to get those two colors no matter which values you set
for the pixels.

If you want more colors you either need to use a full color image (e.g.
16-bit image) where the pixel value will then indicate the color of the
pixel or if size is a big issue you could create an 8-bit palette based
image, where the pixel value indicates an index into a color palette
table and then you change the color by setting the value in that table.

Doug

Chhil wrote:

>
> Hello,
>
> Please help me overcome this issue with painting a image before placing
> it on the composite.
>
>
> Region (a) is white and transparent.
> Region (b) is black.
> The image has 2 colors and is depth is I bit per pixel.
>
> |-------------------|
> | (a) |
> | |
> | |---------| |
> | | | |
> | | | |
> | | (b) | |
> | | | |
> | |---------| |
> | |
> | |
> |-------------------|
> When I place this image on a composite region (a) correctly get the
> color of the composite it lies on.
> Now I want to change region (b) to have the foreground color of the
> composite.
>
> Problem 1.
> ==========
> I cannot chage the color of region (b) to the forground color of the
> composite it is on.
> Problem 2
> ==========
> If the fore ground color of the composite is white, changing the color
> of region (b) to white will make it transparent too as the transparent
> color is white.
>
>
> Code
> ====
> Here is what I do , if I find a black pixel I change it to white which
> makes the complete image transparent.
> If I use any value other than FFFFFF region (b)becomes black.
>
> I am clueless... HELP!!!
>
> for(int i=0; i<img_data.width; i++) {
> for(int j=0; j<img_data.height; j++) {
> RGB rgb = img_data.palette.getRGB(img_data.getPixel(i, j));
> int threshold = 0;
>
> if(rgb.red == threshold && rgb.green == threshold && rgb.blue ==
> threshold)
> img_data.setPixel(i, j, 0xFFFFFF);
>
> }
> }
>
>
>
> -Chhil
> p.s. I have posted a similar post earlier.
Re: Help with Painting !! [message #454223 is a reply to message #454212] Tue, 19 April 2005 12:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aaa.domain.invalid

Hello Doug,

Appreciate your feedback....

Using a graphic editor I changed the gif to have 8 bits per pixel. But
I still could not get the coloring to work.

When you say create a 8 bit palette based image, do you mean create one
using code instead of the using my image?
Some images that I have are pretty complex so drawing them using code
would be very difficult.

Is it possible to change the palette of an existing image via code?

-Chhil

Doug Pearson wrote:
> I'm not that familiar with SWT's graphic code but assuming that SWT is
> using the native Windows (or OS) bitmaps I can tell you that:
>
> A 1-bit per pixel image is by definition a black and white image, so
> you're only going to get those two colors no matter which values you set
> for the pixels.
>
> If you want more colors you either need to use a full color image (e.g.
> 16-bit image) where the pixel value will then indicate the color of the
> pixel or if size is a big issue you could create an 8-bit palette based
> image, where the pixel value indicates an index into a color palette
> table and then you change the color by setting the value in that table.
>
> Doug
>
> Chhil wrote:
>
>>
>> Hello,
>>
>> Please help me overcome this issue with painting a image before
>> placing it on the composite.
>>
>>
>> Region (a) is white and transparent.
>> Region (b) is black.
>> The image has 2 colors and is depth is I bit per pixel.
>>
>> |-------------------|
>> | (a) |
>> | |
>> | |---------| |
>> | | | |
>> | | | |
>> | | (b) | |
>> | | | |
>> | |---------| |
>> | |
>> | |
>> |-------------------|
>> When I place this image on a composite region (a) correctly get the
>> color of the composite it lies on.
>> Now I want to change region (b) to have the foreground color of the
>> composite.
>>
>> Problem 1.
>> ==========
>> I cannot chage the color of region (b) to the forground color of the
>> composite it is on.
>> Problem 2
>> ==========
>> If the fore ground color of the composite is white, changing the color
>> of region (b) to white will make it transparent too as the transparent
>> color is white.
>>
>>
>> Code
>> ====
>> Here is what I do , if I find a black pixel I change it to white which
>> makes the complete image transparent.
>> If I use any value other than FFFFFF region (b)becomes black.
>>
>> I am clueless... HELP!!!
>>
>> for(int i=0; i<img_data.width; i++) {
>> for(int j=0; j<img_data.height; j++) {
>> RGB rgb = img_data.palette.getRGB(img_data.getPixel(i, j));
>> int threshold = 0;
>>
>> if(rgb.red == threshold && rgb.green == threshold && rgb.blue ==
>> threshold)
>> img_data.setPixel(i, j, 0xFFFFFF);
>>
>> }
>> }
>>
>>
>>
>> -Chhil
>> p.s. I have posted a similar post earlier.
>
>
Re: Help with Painting !! [message #454297 is a reply to message #454223] Tue, 19 April 2005 20:45 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: doug-list.threepenny.net

Hi Chhil,

It's certainly possible on Windows to adjust the palette of an image
once it's in memory. The color table is located above the pixel data,
something like this:

<image-header>
image width
image height
bits per pixel
palette information
color 0 = 0xffeecc
color 1 = 0xaa0099
<image-data>
pixel 0 = color 1 (i.e. 0xaa0099)
pixel 1 = color 0 (i.e. 0xffeecc)
pixel 2 = color 0 (i.e. 0xffeecc)
etc.

But the real question is whether SWT supports working with palette based
images and adjusting this sort of thing. Unfortunately, as I
mentioned, I'm just not that familiar with SWT yet (only started with it
a month ago) so I don't know if it has to hooks to change the color
table rather than just the pixel data.

I'd suggest searching for either "palette" or "color table" in the SWT
docs/newsgroups for further insight into that.

Sorry I can't be more directly helpful,

Doug

Chhil wrote:

> Hello Doug,
>
> Appreciate your feedback....
>
> Using a graphic editor I changed the gif to have 8 bits per pixel. But
> I still could not get the coloring to work.
>
> When you say create a 8 bit palette based image, do you mean create one
> using code instead of the using my image?
> Some images that I have are pretty complex so drawing them using code
> would be very difficult.
>
> Is it possible to change the palette of an existing image via code?
>
> -Chhil
>
> Doug Pearson wrote:
>
>> I'm not that familiar with SWT's graphic code but assuming that SWT is
>> using the native Windows (or OS) bitmaps I can tell you that:
>>
>> A 1-bit per pixel image is by definition a black and white image, so
>> you're only going to get those two colors no matter which values you
>> set for the pixels.
>>
>> If you want more colors you either need to use a full color image
>> (e.g. 16-bit image) where the pixel value will then indicate the color
>> of the pixel or if size is a big issue you could create an 8-bit
>> palette based image, where the pixel value indicates an index into a
>> color palette table and then you change the color by setting the value
>> in that table.
>>
>> Doug
>>
>> Chhil wrote:
>>
>>>
>>> Hello,
>>>
>>> Please help me overcome this issue with painting a image before
>>> placing it on the composite.
>>>
>>>
>>> Region (a) is white and transparent.
>>> Region (b) is black.
>>> The image has 2 colors and is depth is I bit per pixel.
>>>
>>> |-------------------|
>>> | (a) |
>>> | |
>>> | |---------| |
>>> | | | |
>>> | | | |
>>> | | (b) | |
>>> | | | |
>>> | |---------| |
>>> | |
>>> | |
>>> |-------------------|
>>> When I place this image on a composite region (a) correctly get the
>>> color of the composite it lies on.
>>> Now I want to change region (b) to have the foreground color of the
>>> composite.
>>>
>>> Problem 1.
>>> ==========
>>> I cannot chage the color of region (b) to the forground color of the
>>> composite it is on.
>>> Problem 2
>>> ==========
>>> If the fore ground color of the composite is white, changing the
>>> color of region (b) to white will make it transparent too as the
>>> transparent color is white.
>>>
>>>
>>> Code
>>> ====
>>> Here is what I do , if I find a black pixel I change it to white
>>> which makes the complete image transparent.
>>> If I use any value other than FFFFFF region (b)becomes black.
>>>
>>> I am clueless... HELP!!!
>>>
>>> for(int i=0; i<img_data.width; i++) {
>>> for(int j=0; j<img_data.height; j++) {
>>> RGB rgb = img_data.palette.getRGB(img_data.getPixel(i, j));
>>> int threshold = 0;
>>>
>>> if(rgb.red == threshold && rgb.green == threshold && rgb.blue ==
>>> threshold)
>>> img_data.setPixel(i, j, 0xFFFFFF);
>>>
>>> }
>>> }
>>>
>>>
>>>
>>> -Chhil
>>> p.s. I have posted a similar post earlier.
>>
>>
>>
Re: Help with Painting !! [message #454306 is a reply to message #454297] Tue, 19 April 2005 23:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aaa.domain.invalid

Hello Doug,

Thanks again for the image detail feedback....
I am going to dig into SWT docs for ImageData and see if I can do some
of the things you suggested like manipulatng the imagedata of a image.
Once done I will post my findings here...

Thanks again..

Regards Chhil


Doug Pearson wrote:
> Hi Chhil,
>
> It's certainly possible on Windows to adjust the palette of an image
> once it's in memory. The color table is located above the pixel data,
> something like this:
>
> <image-header>
> image width
> image height
> bits per pixel
> palette information
> color 0 = 0xffeecc
> color 1 = 0xaa0099
> <image-data>
> pixel 0 = color 1 (i.e. 0xaa0099)
> pixel 1 = color 0 (i.e. 0xffeecc)
> pixel 2 = color 0 (i.e. 0xffeecc)
> etc.
>
> But the real question is whether SWT supports working with palette based
> images and adjusting this sort of thing. Unfortunately, as I
> mentioned, I'm just not that familiar with SWT yet (only started with it
> a month ago) so I don't know if it has to hooks to change the color
> table rather than just the pixel data.
>
> I'd suggest searching for either "palette" or "color table" in the SWT
> docs/newsgroups for further insight into that.
>
> Sorry I can't be more directly helpful,
>
> Doug
>
> Chhil wrote:
>
>> Hello Doug,
>>
>> Appreciate your feedback....
>>
>> Using a graphic editor I changed the gif to have 8 bits per pixel.
>> But I still could not get the coloring to work.
>>
>> When you say create a 8 bit palette based image, do you mean create
>> one using code instead of the using my image?
>> Some images that I have are pretty complex so drawing them using code
>> would be very difficult.
>>
>> Is it possible to change the palette of an existing image via code?
>>
>> -Chhil
>>
>> Doug Pearson wrote:
>>
>>> I'm not that familiar with SWT's graphic code but assuming that SWT
>>> is using the native Windows (or OS) bitmaps I can tell you that:
>>>
>>> A 1-bit per pixel image is by definition a black and white image, so
>>> you're only going to get those two colors no matter which values you
>>> set for the pixels.
>>>
>>> If you want more colors you either need to use a full color image
>>> (e.g. 16-bit image) where the pixel value will then indicate the
>>> color of the pixel or if size is a big issue you could create an
>>> 8-bit palette based image, where the pixel value indicates an index
>>> into a color palette table and then you change the color by setting
>>> the value in that table.
>>>
>>> Doug
>>>
>>> Chhil wrote:
>>>
>>>>
>>>> Hello,
>>>>
>>>> Please help me overcome this issue with painting a image before
>>>> placing it on the composite.
>>>>
>>>>
>>>> Region (a) is white and transparent.
>>>> Region (b) is black.
>>>> The image has 2 colors and is depth is I bit per pixel.
>>>>
>>>> |-------------------|
>>>> | (a) |
>>>> | |
>>>> | |---------| |
>>>> | | | |
>>>> | | | |
>>>> | | (b) | |
>>>> | | | |
>>>> | |---------| |
>>>> | |
>>>> | |
>>>> |-------------------|
>>>> When I place this image on a composite region (a) correctly get the
>>>> color of the composite it lies on.
>>>> Now I want to change region (b) to have the foreground color of the
>>>> composite.
>>>>
>>>> Problem 1.
>>>> ==========
>>>> I cannot chage the color of region (b) to the forground color of
>>>> the composite it is on.
>>>> Problem 2
>>>> ==========
>>>> If the fore ground color of the composite is white, changing the
>>>> color of region (b) to white will make it transparent too as the
>>>> transparent color is white.
>>>>
>>>>
>>>> Code
>>>> ====
>>>> Here is what I do , if I find a black pixel I change it to white
>>>> which makes the complete image transparent.
>>>> If I use any value other than FFFFFF region (b)becomes black.
>>>>
>>>> I am clueless... HELP!!!
>>>>
>>>> for(int i=0; i<img_data.width; i++) {
>>>> for(int j=0; j<img_data.height; j++) {
>>>> RGB rgb = img_data.palette.getRGB(img_data.getPixel(i, j));
>>>> int threshold = 0;
>>>>
>>>> if(rgb.red == threshold && rgb.green == threshold && rgb.blue
>>>> == threshold)
>>>> img_data.setPixel(i, j, 0xFFFFFF);
>>>>
>>>> }
>>>> }
>>>>
>>>>
>>>>
>>>> -Chhil
>>>> p.s. I have posted a similar post earlier.
>>>
>>>
>>>
>>>
>
Re: Help with Painting !! [message #454311 is a reply to message #454306] Wed, 20 April 2005 07:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: doug-list.threepenny.net

Hi Chhil,

I just took a quick scan through the SWT interfaces. The key class to
focus on for an 8-bit image is PaletteData. This is the class that
stores the mapping from an index value to a particular color.

To change the colors of the image you should try to build a new
PaletteData object. You could call "getRGBs()" for the existing image
and then modify that array of color values and create a new
PaletteData(RBG[]).

Now the problem is how to attach that new palette back to the image (so
that its pixels produce different colors).

I see there's a palette member, so it's possible you could simply say
imageData.palette = new PaletteData(myRGBarray) ;
but I'm not sure if that's valid.

If it's not you'd seem to have to create a new ImageData() object using
the new palette and copying some existing values from the old image data
object.

Hope that helps,

Doug


Chhil wrote:
> Hello Doug,
>
> Thanks again for the image detail feedback....
> I am going to dig into SWT docs for ImageData and see if I can do some
> of the things you suggested like manipulatng the imagedata of a image.
> Once done I will post my findings here...
>
> Thanks again..
>
> Regards Chhil
>
>
> Doug Pearson wrote:
>
>> Hi Chhil,
>>
>> It's certainly possible on Windows to adjust the palette of an image
>> once it's in memory. The color table is located above the pixel data,
>> something like this:
>>
>> <image-header>
>> image width
>> image height
>> bits per pixel
>> palette information
>> color 0 = 0xffeecc
>> color 1 = 0xaa0099
>> <image-data>
>> pixel 0 = color 1 (i.e. 0xaa0099)
>> pixel 1 = color 0 (i.e. 0xffeecc)
>> pixel 2 = color 0 (i.e. 0xffeecc)
>> etc.
>>
>> But the real question is whether SWT supports working with palette
>> based images and adjusting this sort of thing. Unfortunately, as I
>> mentioned, I'm just not that familiar with SWT yet (only started with
>> it a month ago) so I don't know if it has to hooks to change the color
>> table rather than just the pixel data.
>>
>> I'd suggest searching for either "palette" or "color table" in the SWT
>> docs/newsgroups for further insight into that.
>>
>> Sorry I can't be more directly helpful,
>>
>> Doug
>>
>> Chhil wrote:
>>
>>> Hello Doug,
>>>
>>> Appreciate your feedback....
>>>
>>> Using a graphic editor I changed the gif to have 8 bits per pixel.
>>> But I still could not get the coloring to work.
>>>
>>> When you say create a 8 bit palette based image, do you mean create
>>> one using code instead of the using my image?
>>> Some images that I have are pretty complex so drawing them using code
>>> would be very difficult.
>>>
>>> Is it possible to change the palette of an existing image via code?
>>>
>>> -Chhil
>>>
>>> Doug Pearson wrote:
>>>
>>>> I'm not that familiar with SWT's graphic code but assuming that SWT
>>>> is using the native Windows (or OS) bitmaps I can tell you that:
>>>>
>>>> A 1-bit per pixel image is by definition a black and white image, so
>>>> you're only going to get those two colors no matter which values you
>>>> set for the pixels.
>>>>
>>>> If you want more colors you either need to use a full color image
>>>> (e.g. 16-bit image) where the pixel value will then indicate the
>>>> color of the pixel or if size is a big issue you could create an
>>>> 8-bit palette based image, where the pixel value indicates an index
>>>> into a color palette table and then you change the color by setting
>>>> the value in that table.
>>>>
>>>> Doug
>>>>
>>>> Chhil wrote:
>>>>
>>>>>
>>>>> Hello,
>>>>>
>>>>> Please help me overcome this issue with painting a image before
>>>>> placing it on the composite.
>>>>>
>>>>>
>>>>> Region (a) is white and transparent.
>>>>> Region (b) is black.
>>>>> The image has 2 colors and is depth is I bit per pixel.
>>>>>
>>>>> |-------------------|
>>>>> | (a) |
>>>>> | |
>>>>> | |---------| |
>>>>> | | | |
>>>>> | | | |
>>>>> | | (b) | |
>>>>> | | | |
>>>>> | |---------| |
>>>>> | |
>>>>> | |
>>>>> |-------------------|
>>>>> When I place this image on a composite region (a) correctly get the
>>>>> color of the composite it lies on.
>>>>> Now I want to change region (b) to have the foreground color of the
>>>>> composite.
>>>>>
>>>>> Problem 1.
>>>>> ==========
>>>>> I cannot chage the color of region (b) to the forground color of
>>>>> the composite it is on.
>>>>> Problem 2
>>>>> ==========
>>>>> If the fore ground color of the composite is white, changing the
>>>>> color of region (b) to white will make it transparent too as the
>>>>> transparent color is white.
>>>>>
>>>>>
>>>>> Code
>>>>> ====
>>>>> Here is what I do , if I find a black pixel I change it to white
>>>>> which makes the complete image transparent.
>>>>> If I use any value other than FFFFFF region (b)becomes black.
>>>>>
>>>>> I am clueless... HELP!!!
>>>>>
>>>>> for(int i=0; i<img_data.width; i++) {
>>>>> for(int j=0; j<img_data.height; j++) {
>>>>> RGB rgb = img_data.palette.getRGB(img_data.getPixel(i, j));
>>>>> int threshold = 0;
>>>>>
>>>>> if(rgb.red == threshold && rgb.green == threshold && rgb.blue
>>>>> == threshold)
>>>>> img_data.setPixel(i, j, 0xFFFFFF);
>>>>>
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>> -Chhil
>>>>> p.s. I have posted a similar post earlier.
>>>>
>>>>
>>>>
>>>>
>>>>
>>
Re: Help with Painting !! [message #454324 is a reply to message #454311] Wed, 20 April 2005 12:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aaa.domain.invalid

Hi Doug,

Thank again...

I already tried to attach a Plaettedata with random colors to the
palette member variable and that did not seem to work (but I could be
doing something wrong ;-)...
I will try the second approach that you have listed and see if that
works out..

Regards Chhil
Doug Pearson wrote:
> Hi Chhil,
>
> I just took a quick scan through the SWT interfaces. The key class to
> focus on for an 8-bit image is PaletteData. This is the class that
> stores the mapping from an index value to a particular color.
>
> To change the colors of the image you should try to build a new
> PaletteData object. You could call "getRGBs()" for the existing image
> and then modify that array of color values and create a new
> PaletteData(RBG[]).
>
> Now the problem is how to attach that new palette back to the image (so
> that its pixels produce different colors).
>
> I see there's a palette member, so it's possible you could simply say
> imageData.palette = new PaletteData(myRGBarray) ;
> but I'm not sure if that's valid.
>
> If it's not you'd seem to have to create a new ImageData() object using
> the new palette and copying some existing values from the old image data
> object.
>
> Hope that helps,
>
> Doug
>
>
> Chhil wrote:
>
>> Hello Doug,
>>
>> Thanks again for the image detail feedback....
>> I am going to dig into SWT docs for ImageData and see if I can do some
>> of the things you suggested like manipulatng the imagedata of a image.
>> Once done I will post my findings here...
>>
>> Thanks again..
>>
>> Regards Chhil
>>
>>
>> Doug Pearson wrote:
>>
>>> Hi Chhil,
>>>
>>> It's certainly possible on Windows to adjust the palette of an image
>>> once it's in memory. The color table is located above the pixel
>>> data, something like this:
>>>
>>> <image-header>
>>> image width
>>> image height
>>> bits per pixel
>>> palette information
>>> color 0 = 0xffeecc
>>> color 1 = 0xaa0099
>>> <image-data>
>>> pixel 0 = color 1 (i.e. 0xaa0099)
>>> pixel 1 = color 0 (i.e. 0xffeecc)
>>> pixel 2 = color 0 (i.e. 0xffeecc)
>>> etc.
>>>
>>> But the real question is whether SWT supports working with palette
>>> based images and adjusting this sort of thing. Unfortunately, as I
>>> mentioned, I'm just not that familiar with SWT yet (only started with
>>> it a month ago) so I don't know if it has to hooks to change the
>>> color table rather than just the pixel data.
>>>
>>> I'd suggest searching for either "palette" or "color table" in the
>>> SWT docs/newsgroups for further insight into that.
>>>
>>> Sorry I can't be more directly helpful,
>>>
>>> Doug
>>>
>>> Chhil wrote:
>>>
>>>> Hello Doug,
>>>>
>>>> Appreciate your feedback....
>>>>
>>>> Using a graphic editor I changed the gif to have 8 bits per pixel.
>>>> But I still could not get the coloring to work.
>>>>
>>>> When you say create a 8 bit palette based image, do you mean create
>>>> one using code instead of the using my image?
>>>> Some images that I have are pretty complex so drawing them using
>>>> code would be very difficult.
>>>>
>>>> Is it possible to change the palette of an existing image via code?
>>>>
>>>> -Chhil
>>>>
>>>> Doug Pearson wrote:
>>>>
>>>>> I'm not that familiar with SWT's graphic code but assuming that SWT
>>>>> is using the native Windows (or OS) bitmaps I can tell you that:
>>>>>
>>>>> A 1-bit per pixel image is by definition a black and white image,
>>>>> so you're only going to get those two colors no matter which values
>>>>> you set for the pixels.
>>>>>
>>>>> If you want more colors you either need to use a full color image
>>>>> (e.g. 16-bit image) where the pixel value will then indicate the
>>>>> color of the pixel or if size is a big issue you could create an
>>>>> 8-bit palette based image, where the pixel value indicates an index
>>>>> into a color palette table and then you change the color by setting
>>>>> the value in that table.
>>>>>
>>>>> Doug
>>>>>
>>>>> Chhil wrote:
>>>>>
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> Please help me overcome this issue with painting a image before
>>>>>> placing it on the composite.
>>>>>>
>>>>>>
>>>>>> Region (a) is white and transparent.
>>>>>> Region (b) is black.
>>>>>> The image has 2 colors and is depth is I bit per pixel.
>>>>>>
>>>>>> |-------------------|
>>>>>> | (a) |
>>>>>> | |
>>>>>> | |---------| |
>>>>>> | | | |
>>>>>> | | | |
>>>>>> | | (b) | |
>>>>>> | | | |
>>>>>> | |---------| |
>>>>>> | |
>>>>>> | |
>>>>>> |-------------------|
>>>>>> When I place this image on a composite region (a) correctly get
>>>>>> the color of the composite it lies on.
>>>>>> Now I want to change region (b) to have the foreground color of
>>>>>> the composite.
>>>>>>
>>>>>> Problem 1.
>>>>>> ==========
>>>>>> I cannot chage the color of region (b) to the forground color of
>>>>>> the composite it is on.
>>>>>> Problem 2
>>>>>> ==========
>>>>>> If the fore ground color of the composite is white, changing the
>>>>>> color of region (b) to white will make it transparent too as the
>>>>>> transparent color is white.
>>>>>>
>>>>>>
>>>>>> Code
>>>>>> ====
>>>>>> Here is what I do , if I find a black pixel I change it to white
>>>>>> which makes the complete image transparent.
>>>>>> If I use any value other than FFFFFF region (b)becomes black.
>>>>>>
>>>>>> I am clueless... HELP!!!
>>>>>>
>>>>>> for(int i=0; i<img_data.width; i++) {
>>>>>> for(int j=0; j<img_data.height; j++) {
>>>>>> RGB rgb = img_data.palette.getRGB(img_data.getPixel(i, j));
>>>>>> int threshold = 0;
>>>>>>
>>>>>> if(rgb.red == threshold && rgb.green == threshold && rgb.blue
>>>>>> == threshold)
>>>>>> img_data.setPixel(i, j, 0xFFFFFF);
>>>>>>
>>>>>> }
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> -Chhil
>>>>>> p.s. I have posted a similar post earlier.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>
Re: Help with Painting !! [message #454451 is a reply to message #454311] Thu, 21 April 2005 04:22 Go to previous message
Eclipse UserFriend
Originally posted by: aaa.domain.invalid

Hi,

I could not ge it to work when th edepth was 8bpp.
When I increased the depth to 24 (i.e. I had to use a BMP format), I
managed to achieve what I wanted.

Sinc my initial image was 1 bit deep so 0 = black and 1 = white.
I managed to set the colors accordingly.




for (int i = 0; i < img_data.width; i++)
{
for (int j = 0; j < img_data.height; j++)
{
RGB rgb = img_data.palette.getRGB(img_data.getPixel(i,j));
if (rgb.red == 0&& rgb.green == 0&& rgb.blue == 0)

img_data.setPixel(i,j,img_data.palette.getPixel(Display.getC urrent().getSystemColor(fore_ground_color).getRGB()));
else
img_data.setPixel(i,j,img_data.palette.getPixel(Display.getC urrent().getSystemColor(back_ground_color).getRGB()));
}
}

I think partly the problem is that the back_ground and fore_ground are
swt colors that return RGB's for 24 bit colors. hence it was failing for
the 8 bit depth.

I will try to use a 8 bit gif and see if I can achive a similar thing.

But thanks again for all your help.

-chhil

Doug Pearson wrote:
> Hi Chhil,
>
> I just took a quick scan through the SWT interfaces. The key class to
> focus on for an 8-bit image is PaletteData. This is the class that
> stores the mapping from an index value to a particular color.
>
> To change the colors of the image you should try to build a new
> PaletteData object. You could call "getRGBs()" for the existing image
> and then modify that array of color values and create a new
> PaletteData(RBG[]).
>
> Now the problem is how to attach that new palette back to the image (so
> that its pixels produce different colors).
>
> I see there's a palette member, so it's possible you could simply say
> imageData.palette = new PaletteData(myRGBarray) ;
> but I'm not sure if that's valid.
>
> If it's not you'd seem to have to create a new ImageData() object using
> the new palette and copying some existing values from the old image data
> object.
>
> Hope that helps,
>
> Doug
>
>
> Chhil wrote:
>
>> Hello Doug,
>>
>> Thanks again for the image detail feedback....
>> I am going to dig into SWT docs for ImageData and see if I can do some
>> of the things you suggested like manipulatng the imagedata of a image.
>> Once done I will post my findings here...
>>
>> Thanks again..
>>
>> Regards Chhil
>>
>>
>> Doug Pearson wrote:
>>
>>> Hi Chhil,
>>>
>>> It's certainly possible on Windows to adjust the palette of an image
>>> once it's in memory. The color table is located above the pixel
>>> data, something like this:
>>>
>>> <image-header>
>>> image width
>>> image height
>>> bits per pixel
>>> palette information
>>> color 0 = 0xffeecc
>>> color 1 = 0xaa0099
>>> <image-data>
>>> pixel 0 = color 1 (i.e. 0xaa0099)
>>> pixel 1 = color 0 (i.e. 0xffeecc)
>>> pixel 2 = color 0 (i.e. 0xffeecc)
>>> etc.
>>>
>>> But the real question is whether SWT supports working with palette
>>> based images and adjusting this sort of thing. Unfortunately, as I
>>> mentioned, I'm just not that familiar with SWT yet (only started with
>>> it a month ago) so I don't know if it has to hooks to change the
>>> color table rather than just the pixel data.
>>>
>>> I'd suggest searching for either "palette" or "color table" in the
>>> SWT docs/newsgroups for further insight into that.
>>>
>>> Sorry I can't be more directly helpful,
>>>
>>> Doug
>>>
>>> Chhil wrote:
>>>
>>>> Hello Doug,
>>>>
>>>> Appreciate your feedback....
>>>>
>>>> Using a graphic editor I changed the gif to have 8 bits per pixel.
>>>> But I still could not get the coloring to work.
>>>>
>>>> When you say create a 8 bit palette based image, do you mean create
>>>> one using code instead of the using my image?
>>>> Some images that I have are pretty complex so drawing them using
>>>> code would be very difficult.
>>>>
>>>> Is it possible to change the palette of an existing image via code?
>>>>
>>>> -Chhil
>>>>
>>>> Doug Pearson wrote:
>>>>
>>>>> I'm not that familiar with SWT's graphic code but assuming that SWT
>>>>> is using the native Windows (or OS) bitmaps I can tell you that:
>>>>>
>>>>> A 1-bit per pixel image is by definition a black and white image,
>>>>> so you're only going to get those two colors no matter which values
>>>>> you set for the pixels.
>>>>>
>>>>> If you want more colors you either need to use a full color image
>>>>> (e.g. 16-bit image) where the pixel value will then indicate the
>>>>> color of the pixel or if size is a big issue you could create an
>>>>> 8-bit palette based image, where the pixel value indicates an index
>>>>> into a color palette table and then you change the color by setting
>>>>> the value in that table.
>>>>>
>>>>> Doug
>>>>>
>>>>> Chhil wrote:
>>>>>
>>>>>>
>>>>>> Hello,
>>>>>>
>>>>>> Please help me overcome this issue with painting a image before
>>>>>> placing it on the composite.
>>>>>>
>>>>>>
>>>>>> Region (a) is white and transparent.
>>>>>> Region (b) is black.
>>>>>> The image has 2 colors and is depth is I bit per pixel.
>>>>>>
>>>>>> |-------------------|
>>>>>> | (a) |
>>>>>> | |
>>>>>> | |---------| |
>>>>>> | | | |
>>>>>> | | | |
>>>>>> | | (b) | |
>>>>>> | | | |
>>>>>> | |---------| |
>>>>>> | |
>>>>>> | |
>>>>>> |-------------------|
>>>>>> When I place this image on a composite region (a) correctly get
>>>>>> the color of the composite it lies on.
>>>>>> Now I want to change region (b) to have the foreground color of
>>>>>> the composite.
>>>>>>
>>>>>> Problem 1.
>>>>>> ==========
>>>>>> I cannot chage the color of region (b) to the forground color of
>>>>>> the composite it is on.
>>>>>> Problem 2
>>>>>> ==========
>>>>>> If the fore ground color of the composite is white, changing the
>>>>>> color of region (b) to white will make it transparent too as the
>>>>>> transparent color is white.
>>>>>>
>>>>>>
>>>>>> Code
>>>>>> ====
>>>>>> Here is what I do , if I find a black pixel I change it to white
>>>>>> which makes the complete image transparent.
>>>>>> If I use any value other than FFFFFF region (b)becomes black.
>>>>>>
>>>>>> I am clueless... HELP!!!
>>>>>>
>>>>>> for(int i=0; i<img_data.width; i++) {
>>>>>> for(int j=0; j<img_data.height; j++) {
>>>>>> RGB rgb = img_data.palette.getRGB(img_data.getPixel(i, j));
>>>>>> int threshold = 0;
>>>>>>
>>>>>> if(rgb.red == threshold && rgb.green == threshold && rgb.blue
>>>>>> == threshold)
>>>>>> img_data.setPixel(i, j, 0xFFFFFF);
>>>>>>
>>>>>> }
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>>> -Chhil
>>>>>> p.s. I have posted a similar post earlier.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>
>
Previous Topic:labels with no borders...
Next Topic:Where can I get the org.eclipse.swt.custom controls?
Goto Forum:
  


Current Time: Fri Mar 05 08:25:13 GMT 2021

Powered by FUDForum. Page generated in 0.02420 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top