Цитата(Hermes @ Dec 14 2008, 16:54)

и ни с кем делиться не буду :lol:
а прога-то универсальная! =)
Это, конечно, очень правильная позиция. Попробуйте кому-нибудь продать.
CODE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef unsigned char u_char;
typedef unsigned short int u_short;
typedef unsigned int u_int;
#pragma pack(1)
struct
{
char bfType[2];
u_int bfSize;
u_short bfReserved1;
u_short bfReserved2;
u_int bfOffBits;
u_int biSize;
u_int biWidth;
u_int biHeight;
u_short biPlanes;
u_short biBitCount;
u_int biCompression;
} bmp_header;
u_char *line_buffer;
int main(int argc, char *argv[])
{
char *s;
FILE *infile, *outfile;
int res = EXIT_SUCCESS;
if(argc != 3)
{
printf("Usage: bmp2hex infile outfile\n");
return EXIT_FAILURE;
}
if((s = argv[1], (infile = fopen(s, "rb")) == NULL) ||
(s = argv[2], (outfile = fopen(s, "wb")) == NULL))
{
printf("??? %s\n", s);
return EXIT_FAILURE;
}
if(fread((char*)&bmp_header, 1, sizeof(bmp_header), infile) == sizeof(bmp_header))
{
if((bmp_header.bfType[0] == 'B') && (bmp_header.bfType[1] == 'M') &&
(bmp_header.biCompression == 0) && (bmp_header.biBitCount == 24))
{
u_int rx, ry, stride, dcount = 0;
char hex_buff[16];
u_char *img;
stride = bmp_header.biWidth * 3 + (((bmp_header.biWidth * 3 - 1) ^ 3) & 3);
if((line_buffer = malloc(stride)) != NULL)
{
fseek(infile, bmp_header.bfOffBits, SEEK_SET);
for(ry = 0; ry < bmp_header.biHeight; ry++)
{
fread(line_buffer, 1, stride, infile);
img = line_buffer;
for(rx = 0; rx < bmp_header.biWidth; rx++)
{
u_char r, g, b;
r = img[2];
g = img[1];
b = img[0];
snprintf(hex_buff, sizeof(hex_buff), "0x%08x, ", (r << 16) | (g << 8) | b);
fwrite(hex_buff, 1, strlen(hex_buff), outfile);
if(++dcount == 8)
{
dcount = 0;
hex_buff[0] = 0x0d;
hex_buff[1] = 0x0a;
fwrite(hex_buff, 1, 2, outfile);
}
img += 3;
}
}
}
else
{
printf("Memory allocation failed!\n");
res = EXIT_FAILURE;
}
}
else
{
printf("Input file format error!\n");
res = EXIT_FAILURE;
}
}
fclose(infile);
fclose(outfile);
return res;
}
bmp2hex.rar ( 28.71 килобайт )
Кол-во скачиваний: 139