PA_Draw_Sim.c
资源名称:lread.rar [点击查看]
上传用户:holyzs
上传日期:2022-06-29
资源大小:2335k
文件大小:2k
源码类别:
编辑器/阅读器
开发平台:
C/C++
- #include <reader_core.h>
- void PA_LoadBmpToBuffer(u16 *Buffer, s16 x, s16 y, void *bmp, s16 SWidth){
- u8 *temp = (u8*)bmp;
- BMPHeader0 *Bmpinfo0 = (BMPHeader0 *) (temp);
- BMP_Headers *Bmpinfo = (BMP_Headers*)(temp+14);
- // u8 *gfx = temp+54;
- u32 start = Bmpinfo0->ImageStart1 + ((Bmpinfo0->ImageStart2)<<16);
- u8 *gfx = temp+start;
- u16 *gfx2 = (u16*)(temp+start);
- // u16 *gfx2 = (u16*)(temp+54); // Pour le mode 16 bit...
- s32 r, g, b; s16 tempx, tempy;
- s16 lx = Bmpinfo->Width; s16 ly = Bmpinfo->Height;
- u16 Bits = Bmpinfo->BitsperPixel;
- //Buffer = (u16*)(Buffer + ((x + (y*SWidth)) << 1)); // Position de d閜art
- s32 i = 0;
- if (Bits > 16){ // Pour 24 et 32 bits
- for (tempy = ly-1; tempy > -1; tempy--){
- for (tempx = 0; tempx < lx; tempx++){
- b = (gfx[i] >> 3)&31; i++;
- g = (gfx[i] >> 3)&31; i++;
- r = (gfx[i] >> 3)&31; i++;
- if (Bits == 32) i++; // On passe le bit alpha
- //PA_Put16bitPixel(screen, x + tempx, y + tempy, PA_RGB(r, g, b));
- Buffer[x + tempx + ((y + tempy) * SWidth)] = PA_RGB(r, g, b);
- }
- while(i&3) i++; // Padding....
- }
- }
- else if (Bits == 16){
- s32 temp;
- for (tempy = ly-1; tempy > -1; tempy--){
- for (tempx = 0; tempx < lx; tempx++){
- b = *gfx2&31;
- g = (*gfx2>>5)&31;
- r = (*gfx2>>10)&31;
- //PA_Put16bitPixel(screen, x + tempx, y + tempy, PA_RGB(r, g, b));
- Buffer[x + tempx + ((y + tempy) * SWidth)] = PA_RGB(r, g, b);
- gfx2++; // On passe au pixel suivant
- }
- temp = (s32)gfx2;
- while(temp&3) temp++; // Padding....
- gfx2 = (u16*)temp;
- }
- }
- if (Bits == 8) {
- // look for palette data if present //
- u8 *colormap = temp+14+Bmpinfo->SizeofHeader;
- u16 palette[256];
- s32 colors;
- if (Bmpinfo->NColors != 0) {
- colors = Bmpinfo->NColors & 0xff;
- } else {
- colors = 256;
- }
- for(i = 0; i < colors; i++) {
- b = ((colormap[(i<<2)+0])>>3)&31;
- g = ((colormap[(i<<2)+1])>>3)&31;
- r = ((colormap[(i<<2)+2])>>3)&31;
- palette[i] = PA_RGB(r, g, b);
- }
- i = 0;
- for (tempy = ly-1; tempy > -1; tempy--){
- for (tempx = 0; tempx < lx; tempx++){
- Buffer[x + tempx + ((y + tempy) * SWidth)] = palette[gfx[i]];
- i++;
- }
- }
- }
- }