реклама на сайте
подробности

 
 
> bmp в массив, массив вида 0х00xxxxxx
Hermes
сообщение Dec 13 2008, 14:27
Сообщение #1


Участник
*

Группа: Участник
Сообщений: 27
Регистрация: 17-11-08
Пользователь №: 41 692



нужна программка которая преобразует картинку в масси вида:
0x00ffffff, 0x00ffffff, 0x0012ffcc и т.д.
т.е. преобразовать 24 битную картинку в hex формат, где на пиксель приходиться 32 бита, из которых значащих только 24
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
Hermes
сообщение Dec 14 2008, 13:54
Сообщение #2


Участник
*

Группа: Участник
Сообщений: 27
Регистрация: 17-11-08
Пользователь №: 41 692



уже не надо... сделал сам... отлично подходит для LPC-2478STK от олимекс biggrin.gif
и ни с кем делиться не буду lol.gif
а прога-то универсальная! =)

ЗЫ: тему можно закрыть
ЗЫЫ: если кому надо - пишите в личку
Go to the top of the page
 
+Quote Post
aaarrr
сообщение Dec 14 2008, 14:27
Сообщение #3


Гуру
******

Группа: Свой
Сообщений: 10 713
Регистрация: 11-12-04
Пользователь №: 1 448



Цитата(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
Go to the top of the page
 
+Quote Post



Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 29th July 2025 - 07:33
Рейтинг@Mail.ru


Страница сгенерированна за 0.01407 секунд с 7
ELECTRONIX ©2004-2016