yupina-chan
Member level 2
- Joined
- Nov 27, 2013
- Messages
- 51
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 8
- Activity points
- 397
hi. i want to read a bitmap image from my sdcard. i was able to write to sdcard as in the tutorial. my source code for reading is as follows:
it builds without errors and the sd card was accessed successfully but the returned bitmap size was wrong. my image is 20.3 kb while the returned size was 14kb. please guide me in correcting my code especially in the reading part. im not familiar with c. thanks in advance!
my
Code:
#include <stdio.h>
#include <system.h>
#include <altera_up_sd_card_avalon_interface.h>
#pragma pack(2)
typedef struct{
unsigned short int type; /* Magic identifier */
unsigned int size; /* File size in bytes */
unsigned short int reserved1, reserved2;
unsigned int offset; /* Offset to image data, bytes */
} BMPFileHeader;
typedef struct{
unsigned int size; /* Header size in bytes */
int width,height; /* Width and height of image */
unsigned short int planes; /* Number of colour planes */
unsigned short int bits; /* Bits per pixel */
unsigned int compression; /* Compression type */
unsigned int imagesize; /* Image size in bytes */
int xresolution,yresolution; /* Pixels per meter */
unsigned int ncolours; /* Number of colours */
unsigned int importantcolours; /* Important colours */
} BMPInfoHeader;
short int sd_fileh;
short int header;
int x;
int main()
{
printf("SD Card Access Test\n");
alt_up_sd_card_dev *sd_card_dev = alt_up_sd_card_open_dev(SD_CARD_NAME);
if(sd_card_dev != 0)
{
if(alt_up_sd_card_is_Present())
{
if(alt_up_sd_card_is_FAT16())
printf("Card is FAT16\n");
else
printf("Card is not FAT16\n");
sd_fileh = alt_up_sd_card_fopen("pic.bmp", false);
if (sd_fileh < 0)
printf("Problem creating file. Error %i", sd_fileh);
else
{
printf("SD Accessed Successfully, reading BMP image...");
for(x=0;x<54;x++)
{
header = (unsigned char)(alt_up_sd_card_read(sd_fileh));
}
printf("Size: %ld\n", sizeof(BMPFileHeader));
}
printf("Done!\n");
printf("Closing File...");
alt_up_sd_card_fclose(sd_fileh);
printf("Done!\n");
}
}
return 0;
}
it builds without errors and the sd card was accessed successfully but the returned bitmap size was wrong. my image is 20.3 kb while the returned size was 14kb. please guide me in correcting my code especially in the reading part. im not familiar with c. thanks in advance!
my
Last edited: