sorry if the question is confusing, but i completed the whodunit problem in pset3 and my doubt was that in the following code:
// iterate over pixels in scanline
for (int j = 0; j < bi.biWidth; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
if (triple.rgbtBlue < 0xff && triple.rgbtGreen < 0xff && triple.rgbtRed > 0xfd)
{
triple.rgbtBlue = 0xff;
triple.rgbtGreen = 0xff;
triple.rgbtRed = 0xff;
}
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
I understand that the line fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
reads 3 bytes (or a pixel) of data from inputr and stores it in triple
, which is defined as:
typedef struct
{
BYTE rgbtBlue;
BYTE rgbtGreen;
BYTE rgbtRed;
} __attribute__((__packed__))
RGBTRIPLE;
But how does triple
assign 1 byte each, from the 3 bytes, to rgbtBlue
, rgbtGreen
, and rgbtRed
automatically when we are only providing the address to the buffer, &triple
. I still know little about structures but to store data in a struct weren't we supposed to assign the value to each member individually?
Also, while trying to use debug50 to find the answer to my question I found that values of rgbtBlue
, rgbtGreen
and rgbtRed
were stored as:
The first part defines the intensity of the colour, from 0 to 255, but can you please elaborate on the second part in single quotation mark ('\377', 'x')?
Note: The values in the picture are only from one of the iteration of for loop and the some had something like '\307' instead of 'x' for blue
and green
too.
Thank you for your help :)