Nowe posty

xx Dystrybucja pod HP Omen (7)
Dzisiaj o 11:33:05
xx [Poradnik] Wyszukiwanie Sterowników (2)
2024-03-27, 21:08:23
lamp Problem z Linux Lite po instalacji (0)
2024-03-27, 19:50:30
xx Ile pingwinów? (1)
2024-03-27, 08:59:24
xx konfiguracja pale moon (0)
2024-03-24, 21:53:42
xx Plasma 6 w Neonie ssie trochę mniej ... (10)
2024-03-23, 02:38:11
xx problem z instalacja sterowników do karty sieciowej (3)
2024-03-18, 18:10:16
xx Plik abc.001 (1)
2024-03-17, 17:48:27
xx Zlecę dopracowanie programu w MatLab (0)
2024-03-13, 15:28:40
xx Linux Mint 21.3 XFCE brak dźwieku po paru minutach (karta muzyczna zintegrowana) (5)
2024-03-12, 23:07:01

Autor Wątek: Struktura bitmapy, no member 'bmfh', chociaż jest  (Przeczytany 3765 razy)

  • Gość
Struktura bitmapy, no member 'bmfh', chociaż jest
« dnia: 2010-03-27, 09:09:08 »
Napisałem sobie strukturkę bitmapy i zamierzam jeszcze napisać do niej funkcje do obsługi. A zatem mam coś takiego:

Jednak kompilator na to narzeka nie wiem czemu ;-(
bmp.h
struct BITMAP* LoadBitmap (char *file);
//bool DumpBitmap (struct BITMAP *file);
//bool FreeBitmap (struct BITMAP *file);

struct BITMAP {

BITMAPFILEHEADER bmfh;

BITMAPINFOHEADER bmih;

RGBQUAD          *aColors;

char             *aBitmapBitss;

};

struct BITMAPFILEHEADER {

    unsigned int    bfType;

    int             bfSize;

    unsigned int    bfReserved1;

    unsigned int    bfReserved2;

    int             bfOffBits;

};

struct BITMAPINFOHEADER {

    int          biSize;

    long int     biWidth;

    long int     biHeight;

    short int    biPlanes;

    short int    biBitCount;

    int          biCompression;

    int          biSizeImage;

    long int     biXPelsPerMeter;

    long int     biYPelsPerMeter;

    int          biClrUsed;

    int          biClrImportant;

};

struct RGBQUAD {    

    char    rgbBlue;

    char    rgbGreen;

    char    rgbRed;

    char    rgbReserved;

};
bmp.c

#include 
#include
#include "bmp.h"

struct BITMAP* LoadBitmap (char *file){

FILE *file_desc = fopen (file, "rb");
int result, size;
struct BITMAP *bm;
char *buffer;

if (file_desc == NULL) return NULL;

result = fseek (file_desc, 0, SEEK_END);

if (result == -1) {
fclose (file_desc);
return NULL;
}

size = ftell (file_desc);

if (size == -1) {
fclose (file_desc);
return NULL;
}

result = fseek (file_desc, 0, SEEK_SET);

if (result == -1) {
fclose (file_desc);
return NULL;
}

buffer = (char*)malloc(size*sizeof(char));

result = fread (buffer, 1, size, file_desc);

fclose (file_desc);

if (result == -1) {
free (buffer);
return NULL;
}

if (memcmp (buffer, "BM", 2) != 0) {
free (buffer);
return NULL;
}

bm = (struct BITMAP*)malloc(sizeof(struct BITMAP));

memcpy ((char*)bm, buffer, 14);
bm->bmfh.biSize = *(int*)(bm+14);

memcpy ((char*)(bm+14), buffer+14, bm->bmfh.biSize);



free (buffer);

return bm;

}
p.c

#include 
#include "bmp.h"

int main (int argc, char *argv[]){

struct BITMAP *bm;

if (argc == 2) {

bm = LoadBitmap (argv[1]);

if (bm == NULL) printf ("BŁąd");

}

return 0;
}
tomasz@tomasz-laptop:~$ gcc -o p p.c bmp.c
In file included from p.c:2:
bmp.h:7: error: expected specifier-qualifier-list before ‘BITMAPFILEHEADER’
In file included from bmp.c:3:
bmp.h:7: error: expected specifier-qualifier-list before ‘BITMAPFILEHEADER’
bmp.c: In function ‘LoadBitmap’:
bmp.c:53: warning: incompatible implicit declaration of built-in function ‘memcpy’
bmp.c:54: error: ‘struct BITMAP’ has no member named ‘bmfh’
bmp.c:56: error: ‘struct BITMAP’ has no member named ‘bmfh’

ZipoKing

  • Gość
Struktura bitmapy, no member 'bmfh', chociaż jest
« Odpowiedź #1 dnia: 2010-03-27, 09:57:35 »
W całkowicie nieprawidłowy sposób definiujesz struktury.
Wyjście 1:
Kod: c [Zaznacz]

struct BITMAP {
struct BITMAPFILEHEADER bmfh;
/* Dla pozostałych struktur tak samo */
};


Wyjście 2:
Kod: c [Zaznacz]

typedef struct {
  /* ... */
} BITMAPFILEHEADER;

// Tak samo pozostałe struktury wchodzące w skład BITMAP

  • Gość
Struktura bitmapy, no member 'bmfh', chociaż jest
« Odpowiedź #2 dnia: 2010-03-27, 10:28:28 »
Fakt, wersja 2. była w specyfikacji, a ja to usunęłem myśląc że to błąd ;-)