Why unsigned char for RGB pixel data?

I am approaching C ++ with some basic computer graphics.

pixel data is usually represented as:

unsigned char *pixels

and unsigned char is good because it is a value from 0 to 255 (256 = 2 ^ 8, because char is 2 bytes and 1 byte is 8 bits?). and this is good, because the RGB color is represented by a number from 0 to 255.

but .. I understand this as a monochrome image, in the normal image I have RGB, I will have 3 uniged char arrays, one for red, one for green, one for blue. sort of:

unsigned char *pixels[3]

but I never found something similar for RGB pixel data.

+5
source share
4 answers

RGB (R1, G1, B1, R2, G2, B2,...), ( R1).

: N pixels[3*N+0], pixels[3*N+1] pixels[3*N+2] red[N], green[N], blue[N].

, : , ; .

+9
unsigned char *pixels[3];

char. , .

. - :

struct Pixel
{
    unsigned char red;
    unsigned char green;
    unsigned char blue;
};

( ) . - uint32_t. , , .

+4

* [3] , . , fread()/fwrite() ,

+3

, , , unsigned char* - , unsigned char C- (.. , , ), X ( , ... ). , . , , , .., , unsigned char, structto easily access pixel information. In other cases, you may have to index into the buffer, as the anatogue mentions. But in the end, the pixel buffer is just a data buffer, and a shared data byte buffer should be available in C / C ++ using a type unsigned char*.

+3
source

All Articles