imgファイルを読み取るプログラムを取得したため、構造体へのいくつかのポイントを保持する構造体を作成しようとしています。このファイルが16、24、または32ビットであるかどうかに応じて、そのように扱いたいです。この問題は、pixelpointer が他の構造体の 1 つを指すようにしようとすると発生します (「型 'Pixel24' から型 'Pixel' に割り当てるときに互換性のない型」)。これを機能させる方法が本当にわからないので、本当に助けが必要です。
また、ファイルを開くときに特定のファイル拡張子を確認したいのですが、それが正しいファイル拡張子である場合にのみ処理したいのですが、その方法についての手がかりがありません。
typedef struct pixel16 {
uint8_t R, G, B;
}__attribute__((packed)) Pixel16;
typedef struct pixel24 {
uint8_t R, G, B;
}__attribute__((packed)) Pixel24;
typedef struct pixel32 {
uint8_t R, G, B, A;
}__attribute__((packed)) Pixel32;
typedef struct pixel{
Pixel16 pixel16;
Pixel24 pixel24;
Pixel32 pixel32;
}__attribute__((packed)) Pixel;
typedef struct file{
Header *imageHeader;
Pixel *imageData;
}File
void something(File file){
Pixel *pixelptr;
if(file->imageHeader.pixelDepth == 16)
*pixelptr = file->imageData->pixel16;
else if(file->imageHeader.pixelDepth == 24)
*pixelptr = file->imageData->pixel24;
else
*pixelptr = file->imageData->pixel32;
}