Bitmap: yellow, fuchsia, green channels instead of RGB: why?

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

Bitmap: yellow, fuchsia, green channels instead of RGB: why?

Postby mark_c » Sun Jan 14, 2018 2:03 am

Hello,
why in this experiment the three bytes represented by pixelPtr1[0], pixelPtr1[1], pixelPtr1[2] do not represent the three RGB channels but instead yellow, fuchsia and green?

Thank you

Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        Image1->Width = Image1->Picture->Bitmap->Width;
        Image1->Height = Image1->Picture->Bitmap->Height;

        Image2->Picture->Bitmap->Width = Image1->Picture->Bitmap->Width;
        Image2->Picture->Bitmap->Height = Image1->Picture->Bitmap->Height;
        Image2->Width = Image1->Picture->Bitmap->Width;
        Image2->Height = Image1->Picture->Bitmap->Heigt;
       
        Image1->Picture->Bitmap->PixelFormat=pf24bit;
        Image2->Picture->Bitmap->PixelFormat=pf24bit;
       
        for (int y=0;y<Image1->Height;y++)
        {
                BYTE* yPtr1 = (BYTE*)Image1->Picture->Bitmap->ScanLine[y];
                BYTE* yPtr2 = (BYTE*)Image2->Picture->Bitmap->ScanLine[y];
                int numero=StrToInt(Edit1->Text);

                for (int x=0;x<Image1->Width;x++)
                {                       
                        BYTE* pixelPtr1 = yPtr1 + x*3;
                        BYTE* pixelPtr2 = yPtr2 + x*3;
                        pixelPtr2[0] = pixelPtr1[0]; // yellow
                        pixelPtr2[1] = pixelPtr1[1]; // fuchsia
                        pixelPtr2[2] = pixelPtr1[2]; // green
                }
        }
        Image2->Refresh();
}
mark_c
BCBJ Guru
BCBJ Guru
 
Posts: 111
Joined: Thu Jun 21, 2012 1:13 am

Re: Bitmap: yellow, fuchsia, green channels instead of RGB:

Postby HsiaLin » Sun Jan 14, 2018 5:19 am

I ran your code, it seems to work fine.

Update: it doesnt seem to work on all pictures
Last edited by HsiaLin on Sun Jan 14, 2018 5:49 am, edited 1 time in total.
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 297
Joined: Sun Jul 08, 2007 6:29 pm

Re: Bitmap: yellow, fuchsia, green channels instead of RGB:

Postby mark_c » Sun Jan 14, 2018 5:42 am

try to disable lines of code with // (see below) and you'll see that what you get are not the RGB channels but other channels: why?
Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        Image1->Width = Image1->Picture->Bitmap->Width;
        Image1->Height = Image1->Picture->Bitmap->Height;

        Image2->Picture->Bitmap->Width = Image1->Picture->Bitmap->Width;
        Image2->Picture->Bitmap->Height = Image1->Picture->Bitmap->Height;
        Image2->Width = Image1->Picture->Bitmap->Width;
        Image2->Height = Image1->Picture->Bitmap->Heigt;
       
        Image1->Picture->Bitmap->PixelFormat=pf24bit;
        Image2->Picture->Bitmap->PixelFormat=pf24bit;
       
        for (int y=0;y<Image1->Height;y++)
        {
                BYTE* yPtr1 = (BYTE*)Image1->Picture->Bitmap->ScanLine[y];
                BYTE* yPtr2 = (BYTE*)Image2->Picture->Bitmap->ScanLine[y];
                int numero=StrToInt(Edit1->Text);

                for (int x=0;x<Image1->Width;x++)
                {                       
                        BYTE* pixelPtr1 = yPtr1 + x*3;
                        BYTE* pixelPtr2 = yPtr2 + x*3;
                        pixelPtr2[0] = pixelPtr1[0]; // yellow
                        //pixelPtr2[1] = pixelPtr1[1]; // fuchsia
                        //pixelPtr2[2] = pixelPtr1[2]; // green
                }
        }
        Image2->Refresh();
}
mark_c
BCBJ Guru
BCBJ Guru
 
Posts: 111
Joined: Thu Jun 21, 2012 1:13 am

Re: Bitmap: yellow, fuchsia, green channels instead of RGB:

Postby HsiaLin » Sun Jan 14, 2018 5:55 am

Maybe Damon will see your post in the AM, he is a graphics professional.
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 297
Joined: Sun Jul 08, 2007 6:29 pm

Re: Bitmap: yellow, fuchsia, green channels instead of RGB:

Postby HsiaLin » Sun Jan 14, 2018 6:51 am

Here is a bit of code from an old project i did that copied one bmp to another,
i`m not sure what your final objective is but maybe you can use this in some way.

you would just call it like this

CopyBmp(Image2->Picture->Bitmap, Image1->Picture->Bitmap);


Code: Select all
//---------------------------------------------------------------------------

void __fastcall TForm1::CopyBmp(Graphics::TBitmap *Dest, Graphics::TBitmap *Source)
{
  int x,y,wid, hit;
  TRGBTriple *SrcByte, *DstByte;

  Source->PixelFormat = pf24bit;
  Dest->PixelFormat   = pf24bit;

  Dest->Height = Source->Height;
  Dest->Width  = Source->Width;

  hit = Source->Height;
  wid = Source->Width;

  for (int y=0; y < hit; y++)
  {
    SrcByte = reinterpret_cast<TRGBTriple*>(Source->ScanLine[y]);
    DstByte = reinterpret_cast<TRGBTriple*>(Dest->ScanLine[y]);
    for(x=0; x < wid; x++)
    {
        DstByte[x] = SrcByte[x];
    }

  }

}
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 297
Joined: Sun Jul 08, 2007 6:29 pm

Re: Bitmap: yellow, fuchsia, green channels instead of RGB:

Postby mark_c » Mon Jan 15, 2018 8:49 am

thanks, I've seen your code: suppose you want to copy only the red or yellow or green channel to the destination
mark_c
BCBJ Guru
BCBJ Guru
 
Posts: 111
Joined: Thu Jun 21, 2012 1:13 am

Re: Bitmap: yellow, fuchsia, green channels instead of RGB:

Postby HsiaLin » Mon Jan 15, 2018 6:58 pm

I`m not a graphics specialist so im just assuming here:

Code: Select all
  for (int y=0; y < hit; y++)
  {
    SrcByte = reinterpret_cast<TRGBTriple*>(Source->ScanLine[y]);
    DstByte = reinterpret_cast<TRGBTriple*>(Dest->ScanLine[y]);
    for(x=0; x < wid; x++)
    {
         DstByte[x] = SrcByte[x];
         DstByte->rgbtRed     = Some Value;
         DstByte->rgbtGreen   = Some Value;
         DstByte->rgbtBlue    = Some Value;
    }

  }
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 297
Joined: Sun Jul 08, 2007 6:29 pm


Return to Technical

Who is online

Users browsing this forum: Bing [Bot] and 9 guests