Nowe posty

xx Problem ze sterownikami. (5)
2024-04-13, 21:25:16
xx Instalacja xfce4 (2)
2024-04-13, 16:20:17
xx Serie kompilacji bez instalacji dla “emerge” w Gentoo (2)
2024-04-08, 18:40:04
xx Plasma 6 w Neonie ssie trochę mniej ... (17)
2024-04-05, 10:03:46
xx Problem z Linux Lite po instalacji (3)
2024-04-03, 14:23:40
xx Jak właczyć num locka przy starcie systemu debian 12? (12)
2024-04-02, 17:43:54
xx Brak dźwieku w systemie. (5)
2024-04-02, 16:13:41
xx Dystrybucja pod HP Omen (7)
2024-03-29, 11:33:05
xx [Poradnik] Wyszukiwanie Sterowników (2)
2024-03-27, 21:08:23
xx Ile pingwinów? (1)
2024-03-27, 08:59:24

Autor Wątek: BMP niepoprawny odczyt wartości pikseli  (Przeczytany 3354 razy)

  • Gość
BMP niepoprawny odczyt wartości pikseli
« dnia: 2010-11-11, 16:22:00 »
Gdy spróbowałem odczytać bitmapę, przekonwertować ją do macierzy i spowrotem zapisać ją do BMP, to przy sprawdzeniu pliku zauważyłem, że cały obraz wyjściowy jest czarny. Sprawdziłem wszystkie wartości  w macierzy obrazu były 0. Co zrobiłem, źle?

Cytuj
int **imageBMPtoStandard (BITMAP *imageBMP){

int i = 0;

int *imageBMPdata = NULL, **imageBMPtable = NULL;

    imageBMPdata = imageBMP + imageBMP->bfOffBits;

    imageBMPtable = CreateStandard(imageBMP->biWidth, imageBMP->biHeight);


    for (i = 0; ibiSize; i++)
        imageBMPtable[imageBMP->biHeight-i/imageBMP->biWidth-1][i%imageBMP->biWidth] = imageBMPdata;

    return imageBMPtable;
}
Cytuj
int SaveBMP (int **imageTable, BITMAP *imageBMPheaders, char *filename){
char *data = NULL;
int i = 0, result = 0;
int data_length = 0;
// file header - 14, info header - 40 , pallete 0,
imageBMPheaders->biSize = 40;
data_length = 14 + imageBMPheaders->biSize + 0 + imageBMPheaders->biWidth*imageBMPheaders->biHeight*4;
data = (char *)malloc(sizeof(char)*data_length);
if (data == NULL) return -1;
memcpy (imageBMPheaders->bfType, "BM", 2);
imageBMPheaders->bfSize = data_length;
imageBMPheaders->bfReserved1 = 0;
imageBMPheaders->bfReserved2 = 0;
imageBMPheaders->bfOffBits = 14 + imageBMPheaders->biSize + 0;
imageBMPheaders->biPlanes = 1;
imageBMPheaders->biBitCount = 24;
imageBMPheaders->biCompression = 0;
imageBMPheaders->biSizeImage = imageBMPheaders->biWidth*imageBMPheaders->biHeight*4;

memcpy (data, imageBMPheaders, 14+imageBMPheaders->biSize);

for (i = imageBMPheaders->biHeight-1; i>=0; i--)
    memcpy (data+imageBMPheaders->bfOffBits+i*imageBMPheaders->biWidth*4, imageTable, imageBMPheaders->biWidth);

FILE *fileBMP= fopen (filename, "wb");

if (fileBMP == NULL) return -1;

result = fwrite (data, 1, data_length, fileBMP);

if (result == -1) return -1;

fclose (fileBMP);

free (data);

}
Cytuj
typedef struct tagBITMAP {

char           bfType[2];
int            bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
int            bfOffBits;
int            biSize;
int            biWidth;
int            biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
int            biCompression;
int            biSizeImage;
int            biXPelsPerMeter;
int            biYPelsPerMeter;
int            biClrUsed;
char           biClrImportant;
char           biClrRotation;
unsigned short biReserved;

} BITMAP;