请问怎样让eboot能支持浮点运算?我想加入jpg格式的logo,功能完成后发布代码

韦东山
深圳百问网科技有限公司企业官方账号
2010-06-08 02:33:49
使用jpg格式的LOGO文件会极大地减少程序空间,这在实现类似动画的LOGO显示时极为有用。

我找了个jpg2bmp的文件,正在移植到eboot上,

平台是:S3C2440,WINCE 5.0。

现在需要加入浮点运算,请问怎么做呢?

我完成后会把这部分代码贴出来,大家快来帮忙啊
...全文
233 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
韦东山 2010-06-09
  • 打赏
  • 举报
回复
gzip解压做完了,
正在试试gif解码,找到一个C代码的解码库,我在VC上试了一下,GIF转成16bpp的BMP时会严重偏色。
不知道是什么原因。

我修改了提取GIF颜色的代码,也没有解决:


#if 0 // 这是原库里的提取代码
nColor = default_col;
nColor |= ((unsigned short)(ptPalette[cColorIndex].cRed) << 8) & 0xF000;
nColor |= ((ptPalette[cColorIndex].cGreen)<<4) & 0x0F00;
nColor |= (ptPalette[cColorIndex].cBlue) & 0x00F0;
#else // 这是我写的,BMP文件的RGB三色各占5个位
blue = ptPalette[cColorIndex].cBlue; //B
green = ptPalette[cColorIndex].cGreen; //G
red = ptPalette[cColorIndex].cRed; // R
nColor = ((green & 0x38) << 2) | (blue >> 3); //I555
nColor = ((red & 0xf1)>>1) | (green >> 6); //I555

#endif
leo_dengzx 2010-06-09
  • 打赏
  • 举报
回复
jpg解压算法也可以去掉浮点数的。我没有直接搞过jpg的,但搞过mpeg2软解码,应该差不多。

找到源码中的浮点运算,用长整型替代。

比如原来是float A*B/C,那就弄成长整型的(A<<10)*(B<<10)/(C<<10),这样的计算结果会是原来的计算结果1024倍。

到你要返回的时候,再把这个1024除掉即可。精度不够的话,可以放大更多倍数。
jxxx2967 2010-06-09
  • 打赏
  • 举报
回复
可以考虑GIF或PNG,它哥俩儿使用的都是无损压缩算法(LZW),不需要浮点运算。
韦东山 2010-06-09
  • 打赏
  • 举报
回复
我并不是要实现非常流畅的动画,只要能在几个阶段分别显示几个图片就可以了;
正在考虑解压的方法,它不用浮点运算。
InsaneCode 2010-06-09
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 guohaidao 的回复:]
进来关注一下,现在还在实现静态的呢,楼主能否发一个bmp图片转成c代码的程序呀,我找了几个都不好用。
[/Quote]
embeded助手,貌似可以的。
guohaidao 2010-06-09
  • 打赏
  • 举报
回复
进来关注一下,现在还在实现静态的呢,楼主能否发一个bmp图片转成c代码的程序呀,我找了几个都不好用。
韦东山 2010-06-09
  • 打赏
  • 举报
回复
这段代码是原来的:
nColor = default_col;
nColor |= ((unsigned short)(ptPalette[cColorIndex].cRed) << 8) & 0xF000;
nColor |= ((ptPalette[cColorIndex].cGreen)<<4) & 0x0F00;
nColor |= (ptPalette[cColorIndex].cBlue) & 0x00F0;

由于我想转成16BPP的格式,我没用它,用的是我自己的代码:
blue = ptPalette[cColorIndex].cBlue; //B
green = ptPalette[cColorIndex].cGreen; //G
red = ptPalette[cColorIndex].cRed; // R
nColor = ((green & 0x38) << 2) | (blue >> 3); //I555
nColor = ((red & 0xf1)>>1) | (green >> 6); //I555


seu_dust 2010-06-09
  • 打赏
  • 举报
回复
这个要关注,学习。
jxxx2967 2010-06-09
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 thisway_diy 的回复:]
nColor = ((green & 0x38) << 2) | (blue >> 3); //I555
nColor = ((red & 0xf1)>>1) | (green >> 6); //I555
[/Quote]

你的颜色组合算法怎么看着那么奇怪了,上面的算出一半,下面又没有使用。

nColor = (((unsigned short)red & 0xf8 )<< 10) 
| (((unsigned short)green & 0xf8 ) << 5)
| ((unsigned short)blue >> 3);
博说医械研发 2010-06-09
  • 打赏
  • 举报
回复
可以把几张BMP图片放在固定的FLASH位置,不同的时候读取不同的数据就可以了,没必要做JPG
domworldjohn 2010-06-08
  • 打赏
  • 举报
回复
呵呵,以时间换空间,我觉得未必是好,未必能实现流畅的动画。建议在压缩bmp图片上面下功夫,但是还是要赞一个,关注ing...
韦东山 2010-06-08
  • 打赏
  • 举报
回复
void exitmessage(char *message)
{
printf("%s\n",message);exit(0);
}

void write_buf_to_BMP(BYTE *im_buffer, WORD X_bitmap, WORD Y_bitmap, char *BMPname)
{
SWORD x,y;
RGB *pixel;
BM_header BH;
FILE *fp_bitmap;
DWORD im_loc_bytes;
BYTE nr_fillingbytes, i;
BYTE zero_byte=0;

fp_bitmap=fopen(BMPname,"wb");
if (fp_bitmap==NULL) exitmessage("File cannot be created");

if (X_bitmap%4!=0) nr_fillingbytes=4-((X_bitmap*2L)%4);
else nr_fillingbytes=0;

BH.BMP_id = 'M'*256+'B'; fwrite(&BH.BMP_id,2,1,fp_bitmap);
BH.size=54+Y_bitmap*(X_bitmap*2+nr_fillingbytes);fwrite(&BH.size,4,1,fp_bitmap);
BH.zero_res = 0; fwrite(&BH.zero_res,4,1,fp_bitmap);
BH.offbits = 54; fwrite(&BH.offbits,4,1,fp_bitmap);
BH.biSize = 0x28; fwrite(&BH.biSize,4,1,fp_bitmap);
BH.Width = X_bitmap; fwrite(&BH.Width,4,1,fp_bitmap);
BH.Height = Y_bitmap; fwrite(&BH.Height,4,1,fp_bitmap);
BH.biPlanes = 1; fwrite(&BH.biPlanes,2,1,fp_bitmap);
BH.biBitCount = 16; fwrite(&BH.biBitCount,2,1,fp_bitmap);
BH.biCompression = 0; fwrite(&BH.biCompression,4,1,fp_bitmap);
BH.biSizeImage = 0; fwrite(&BH.biSizeImage,4,1,fp_bitmap);
BH.biXPelsPerMeter = 0xB40; fwrite(&BH.biXPelsPerMeter,4,1,fp_bitmap);
BH.biYPelsPerMeter = 0xB40; fwrite(&BH.biYPelsPerMeter,4,1,fp_bitmap);
BH.biClrUsed = 0; fwrite(&BH.biClrUsed,4,1,fp_bitmap);
BH.biClrImportant = 0; fwrite(&BH.biClrImportant,4,1,fp_bitmap);

printf("Writing bitmap ...\n");
im_loc_bytes=(DWORD)im_buffer+((DWORD)Y_bitmap-1)*X_bitmap*2;

for (y=0;y<Y_bitmap;y++)
{
for (x=0;x<X_bitmap;x++)
{
pixel=(RGB *)im_loc_bytes;
fwrite(pixel, 2, 1, fp_bitmap);
im_loc_bytes+=2;
}
for (i=0;i<nr_fillingbytes;i++)
fwrite(&zero_byte,1,1,fp_bitmap);
im_loc_bytes-=2L*X_bitmap*2;
}
printf("Done.\n");
fclose(fp_bitmap);
}



// Used markers:
#define SOI 0xD8
#define EOI 0xD9
#define APP0 0xE0
#define SOF 0xC0
#define DQT 0xDB
#define DHT 0xC4
#define SOS 0xDA
#define DRI 0xDD
#define COM 0xFE

char error_string[90];
#define exit_func(err) { strcpy(error_string, err); return 0;}

static BYTE *buf; // the buffer we use for storing the entire JPG file

static BYTE bp; //current byte
static WORD wp; //current word

static DWORD byte_pos; // current byte position
#define BYTE_p(i) bp=buf[(i)++]
#define WORD_p(i) wp=(((WORD)(buf[(i)]))<<8) + buf[(i)+1]; (i)+=2

// WORD X_image_size,Y_image_size; // X,Y sizes of the image
static WORD X_round,Y_round; // The dimensions rounded to multiple of Hmax*8 (X_round)
// and Ymax*8 (Y_round)

static BYTE *im_buffer; // RGBA image buffer
static DWORD X_image_bytes; // size in bytes of 1 line of the image = X_round * 4
static DWORD y_inc_value ; // 32*X_round; // used by decode_MCU_1x2,2x1,2x2

BYTE YH,YV,CbH,CbV,CrH,CrV; // sampling factors (horizontal and vertical) for Y,Cb,Cr
static WORD Hmax,Vmax;


static BYTE zigzag[64]={ 0, 1, 5, 6,14,15,27,28,
2, 4, 7,13,16,26,29,42,
3, 8,12,17,25,30,41,43,
9,11,18,24,31,40,44,53,
10,19,23,32,39,45,52,54,
20,22,33,38,46,51,55,60,
21,34,37,47,50,56,59,61,
35,36,48,49,57,58,62,63 };
typedef struct {
BYTE Length[17]; // k =1-16 ; L[k] indicates the number of Huffman codes of length k
WORD minor_code[17]; // indicates the value of the smallest Huffman code of length k
WORD major_code[17]; // similar, but the highest code
BYTE V[65536]; // V[k][j] = Value associated to the j-th Huffman code of length k
// High nibble = nr of previous 0 coefficients
// Low nibble = size (in bits) of the coefficient which will be taken from the data stream
} Huffman_table;

static float *QT[4]; // quantization tables, no more than 4 quantization tables (QT[0..3])
static Huffman_table HTDC[4]; //DC huffman tables , no more than 4 (0..3)
static Huffman_table HTAC[4]; //AC huffman tables (0..3)

static BYTE YQ_nr,CbQ_nr,CrQ_nr; // quantization table number for Y, Cb, Cr
static BYTE YDC_nr,CbDC_nr,CrDC_nr; // DC Huffman table number for Y,Cb, Cr
static BYTE YAC_nr,CbAC_nr,CrAC_nr; // AC Huffman table number for Y,Cb, Cr

static BYTE Restart_markers; // if 1 => Restart markers on , 0 => no restart markers
static WORD MCU_restart; //Restart markers appears every MCU_restart MCU blocks
typedef void (*decode_MCU_func)(DWORD);


static SWORD DCY, DCCb, DCCr; // Coeficientii DC pentru Y,Cb,Cr
static SWORD DCT_coeff[64]; // Current DCT_coefficients
static BYTE Y[64],Cb[64],Cr[64]; // Y, Cb, Cr of the current 8x8 block for the 1x1 case
static BYTE Y_1[64],Y_2[64],Y_3[64],Y_4[64];
static BYTE tab_1[64],tab_2[64],tab_3[64],tab_4[64]; // tabelele de supraesantionare pt cele 4 blocuri

static SWORD Cr_tab[256],Cb_tab[256]; // Precalculated Cr, Cb tables
static SWORD Cr_Cb_green_tab[65536];

// Initial conditions:
// byte_pos = start position in the Huffman coded segment
// WORD_get(w1); WORD_get(w2);wordval=w1;

static BYTE d_k=0; // Bit displacement in memory, relative to the offset of w1
// it's always <16
static WORD w1,w2; // w1 = First word in memory; w2 = Second word
static DWORD wordval ; // the actual used value in Huffman decoding.
static DWORD mask[17];
static SWORD neg_pow2[17]={0,-1,-3,-7,-15,-31,-63,-127,-255,-511,-1023,-2047,-4095,-8191,-16383,-32767};
static DWORD start_neg_pow2=(DWORD)neg_pow2;

static int shift_temp;
#define RIGHT_SHIFT(x,shft) \
((shift_temp = (x)) < 0 ? \
(shift_temp >> (shft)) | ((~(0L)) << (32-(shft))) : \
(shift_temp >> (shft)))
#define DESCALE(x,n) RIGHT_SHIFT((x) + (1L << ((n)-1)), n)
#define RANGE_MASK 1023L
static BYTE *rlimit_table;

char rlimit_table_buf[5 * 256L + 128];
void prepare_range_limit_table()
/* Allocate and fill in the sample_range_limit table */
{
int j;
rlimit_table = (BYTE *)rlimit_table_buf; //malloc(5 * 256L + 128) ;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
memset((void *)rlimit_table,0,256);
rlimit_table += 256; /* allow negative subscripts of simple table */
/* Main part of "simple" table: limit[x] = x */
for (j = 0; j < 256; j++) rlimit_table[j] = j;
/* End of simple table, rest of first half of post-IDCT table */
for (j = 256; j < 640; j++) rlimit_table[j] = 255;
/* Second half of post-IDCT table */
memset((void *)(rlimit_table + 640),0,384);
for (j = 0; j < 128 ; j++) rlimit_table[j+1024] = j;
}
韦东山 2010-06-08
  • 打赏
  • 举报
回复
老是说回复内容过长,不知怎么贴代码了,干脆一段段地贴:
// jpg2bmp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#ifndef __JPEGDEC_H__
#define __JPEGDEC_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "logo.c"


#define BYTE unsigned char
#define WORD unsigned short int

#define DWORD unsigned int
#define SDWORD signed int

#define SBYTE signed char
#define SWORD signed short int

int load_JPEG_header(FILE *fp, DWORD *X_image, DWORD *Y_image);
void decode_JPEG_image();
int get_JPEG_buffer(WORD X_image,WORD Y_image, BYTE **address_dest_buffer);

#endif


#include <conio.h>
#include <time.h>
char *FileName="e:\\a.jpg";
extern char error_string[90];

typedef struct s_BM_header {
WORD BMP_id ; // 'B''M'
DWORD size; // size in bytes of the BMP file
DWORD zero_res; // 0
DWORD offbits; // 54
DWORD biSize; // 0x28
DWORD Width; // X
DWORD Height; // Y
WORD biPlanes; // 1
WORD biBitCount ; // 24
DWORD biCompression; // 0 = BI_RGB
DWORD biSizeImage; // 0
DWORD biXPelsPerMeter; // 0xB40
DWORD biYPelsPerMeter; // 0xB40
DWORD biClrUsed; //0
DWORD biClrImportant; //0
} BM_header;
typedef struct s_RGB {
BYTE B;
BYTE G;
BYTE R;
} RGB;
韦东山 2010-06-08
  • 打赏
  • 举报
回复
我把jpg做成一个char数组;
jpg转bmp的代码在下面,可以在VC里编译运行,我把malloc等都做成全局数组了。
如果想编进eboot里的话,可以直接转为rgb(代码里是jpg=>rgb=>bmp).
logo.c:
const unsigned char jpegData[] = {
……
};

const int jpegDataLen = 14089;


rushonin 2010-06-08
  • 打赏
  • 举报
回复
以时间换空间的做法。 到时候你会觉得启动慢的。
你用gif不很好吗?
eboot加浮点运算,还没整过,有个vfp的库,你看看能不能用在eboot中。

19,521

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧