Ciao a tutti.
Sto provando a creare una classe Bitmap che mi permetta di caricare o di creare file .bmp.
Mi sono letto tutta la pagina di Wikipedia e ho una vaga idea di come procedere.
Però ho un problema. In C++ come faccio a specificare la dimensione di una variabile come numero di bytes?
In pratica ho bisogno di creare vari campi di lunghezza prestabilita.
Ho proceduto in questo modo:
Però la lunghezza degli int o dei char dipende dalla macchina, quindi le variabili che ho creato non hanno una lunghezza fissa, ma sono dipendenti dalla macchina (32, 64, ... bit), giusto? Come faccio a renderle lunghezze fisse?!codice:#ifndef DATATYPE_H #define DATATYPE_H typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef int int32_t; typedef unsigned int uint32_t; typedef struct BITMAPFILETYPE { unsigned char magic[2]; // Magic number (identify BMP file) } bfType; typedef struct BITMAPFILEHEADER { uint32_t bfSize; // Size of BMP file in byte uint16_t bfReserved1; uint16_t bfReserved2; uint32_t bmpOffset; // Offset starting address } BitmapFileHeader; typedef struct BITMAPINFOHEADER { uint32_t biSize; // Size of this header int32_t biWidth; // Bitmap whidt in pixels int32_t biHeight; // Bitmap whidt in pixels uint16_t biPlanes; // Number of color planes being used uint16_t biBitCount; // Number of bits per pixel uint32_t biCompression; // Compression method being used uint32_t biSizeImage; // Image size int32_t biXPixelPerMeter; // Horizontal resolution of the image int32_t biYPixelPerMeter; // Vertical resolutions uint32_t biClrUsed; // Number of colors in the color palette uint32_t biClrImportant; // Number of important color used } BitmapInfoHeader; typedef struct PIXEL { uint8_t B; // Blue color uint8_t G; // Green color uint8_t R; // Red color uint8_t reserved; // Reserved } Pixel; #endif

Rispondi quotando