/**************************************************************************************/
/* */
/**************************************************************************************/
#include <gpstdio.h>
#include <gpstdlib.h>
#include <gpgraphic16.h>
// convert a 24 bits color into a 16 bits color
#define GP_RGB24(r,g,b) ((((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|((((b>>3))&0x1f)<<1))|0x0001)
// All informations in BMP header
typedef struct
{
char magic1, magic2;
long fileSize;
long reserved;
long pixelOffset;
long bmiSize;
long cols, rows;
short nPlanes;
short bitsPerPixel;
long compression, cmpSize;
long xScale, yScale;
long colors, impColors;
}
BMP_HEADER;
// An RGB pixel
typedef struct
{
unsigned char r;
unsigned char g;
unsigned char b;
}
RGB;
// A BMP type for use convenience
typedef struct
{
char fileName[256];
F_HANDLE file;
BMP_HEADER header;
}
BMP_FILE;
// Open a .BMP
int OpenBitmap(char *fileName, BMP_FILE * dest)
{
unsigned long i;
// On essaie d'ouvrir le fichier
if (GpFileOpen(fileName, OPEN_R, &(dest->file)) != SM_OK)
return 0;
gm_strcpy(dest->fileName, fileName);
// On lit l'en-tête
GpFileSeek(dest->file, FROM_BEGIN, 0, &i);
GpFileRead(dest->file, &dest->header.magic1, 1, &i);
GpFileRead(dest->file, &dest->header.magic2, 1, &i);
GpFileRead(dest->file, &dest->header.fileSize, 4, &i);
GpFileRead(dest->file, &dest->header.reserved, 4, &i);
GpFileRead(dest->file, &dest->header.pixelOffset, 4, &i);
GpFileRead(dest->file, &dest->header.bmiSize, 4, &i);
GpFileRead(dest->file, &dest->header.cols, 4, &i);
GpFileRead(dest->file, &dest->header.rows, 4, &i);
GpFileRead(dest->file, &dest->header.nPlanes, 2, &i);
GpFileRead(dest->file, &dest->header.bitsPerPixel, 2, &i);
GpFileRead(dest->file, &dest->header.compression, 4, &i);
GpFileRead(dest->file, &dest->header.cmpSize, 4, &i);
GpFileRead(dest->file, &dest->header.xScale, 4, &i);
GpFileRead(dest->file, &dest->header.yScale, 4, &i);
GpFileRead(dest->file, &dest->header.colors, 4, &i);
GpFileRead(dest->file, &dest->header.impColors, 4, &i);
// On vérifie la validité du fichier
if (dest->header.magic1 != 'B' || dest->header.magic2 != 'M' || dest->header.reserved != 0)
{
GpFileClose(dest->file);
dest->file = NULL;
dest->fileName[0] = 0;
}
return 1;
}
// Close a .BMP
void CloseBitmap(BMP_FILE * file)
{
GpFileClose(file->file);
file->file = NULL;
file->fileName[0] = 0;
}
// get a pixel at (x,y) in an unsigned long
unsigned long GetPixel(BMP_FILE * src, long x, long y)
{
long ret;
unsigned long i;
long offset = src->header.pixelOffset + src->header.bitsPerPixel / 8 * (src->header.rows - 1 - y) * src->header.cols + src->header.bitsPerPixel / 8 * x;
// On vérifie que l'on peut lire
if (x < 0 || x >= src->header.cols || y < 0 || y >= src->header.rows)
return -1;
// On se place au bon endroite pour lire
GpFileSeek(src->file, FROM_BEGIN, offset, &i);
GpFileRead(src->file, &ret, (src->header.bitsPerPixel / 8), &i);
return ret;
}
// Get the pixel at (x,y) into a RGB struct
int GetRGBPixel(BMP_FILE * src, long x, long y, RGB * dest)
{
unsigned long tmp = GetPixel(src, x, y);
if (tmp == -1)
return -1;
dest->r = (char) ((tmp >> 16) & 0x000000ff);
dest->g = (char) ((tmp >> 8) & 0x000000ff);
dest->b = (char) ((tmp) & 0x000000ff);
return tmp;
}
void GpMain(void *argv)
{
int k, i, j;
BMP_FILE origine;
RGB col;
unsigned short *conv = NULL;
GPDRAWSURFACE screen[1];
// Init 16 bit mode
GpGraphicModeSet(16, NULL);
GpLcdSurfaceGet(&screen[0], 0);
// Int SMC
GpFatInit();
gm_strcpy(origine.fileName, "gp:\CAR1.BMP");
// On ouvre l'image à convertir
if (!OpenBitmap(origine.fileName, &origine))
{
GpAppExit();
}
// Allocate memory for the converted picture
if (!(conv = gm_malloc(origine.header.cols * origine.header.rows * 2)))
GpAppExit();
for (j = 0; j < origine.header.cols; j++)
{
for (k = origine.header.rows - 1; k >= 0; k--)
{
GetRGBPixel(&origine, j, k, &col);
conv[(origine.header.cols - (origine.header.cols - j - 1)) * (origine.header.rows) - k - 1] = GP_RGB24(col.r, col.g, col.b);
}
}
// Close the openede bmp
CloseBitmap(&origine);
// Disp converted picture
GpBitBlt16(NULL, &screen[0], (GPC_LCD_WIDTH - origine.header.cols) / 2, (GPC_LCD_HEIGHT - origine.header.rows) / 2, origine.header.cols, origine.header.rows, (unsigned char*)conv, 0, 0, origine.header.cols, origine.header.rows);
while(1);
GpAppExit();
}
grincheux
: heu ben alors sdt trouve po f_handle chez moi :/
/**************************************************************************************/
/* */
/**************************************************************************************/
#include <gpstdio.h>
#include <gpstdlib.h>
#include <gpgraphic16.h>
// convert a 24 bits color into a 16 bits color
#define GP_RGB24(r,g,b) ((((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|((((b>>3))&0x1f)<<1))|0x0001)
// All informations in BMP header
typedef struct
{
char magic1, magic2;
long fileSize;
long reserved;
long pixelOffset;
long bmiSize;
long cols, rows;
short nPlanes;
short bitsPerPixel;
long compression, cmpSize;
long xScale, yScale;
long colors, impColors;
}
BMP_HEADER;
// An RGB pixel
typedef struct
{
unsigned char r;
unsigned char g;
unsigned char b;
}
RGB;
// A BMP type for use convenience
typedef struct
{
char fileName[256];
F_HANDLE file;
BMP_HEADER header;
}
BMP_FILE;
// Open a .BMP
int OpenBitmap(char *fileName, BMP_FILE * dest)
{
unsigned long i;
// On essaie d'ouvrir le fichier
if (GpFileOpen(fileName, OPEN_R, &(dest->file)) != SM_OK)
return 0;
gm_strcpy(dest->fileName, fileName);
// On lit l'en-tête
GpFileSeek(dest->file, FROM_BEGIN, 0, &i);
GpFileRead(dest->file, &dest->header.magic1, 1, &i);
GpFileRead(dest->file, &dest->header.magic2, 1, &i);
GpFileRead(dest->file, &dest->header.fileSize, 4, &i);
GpFileRead(dest->file, &dest->header.reserved, 4, &i);
GpFileRead(dest->file, &dest->header.pixelOffset, 4, &i);
GpFileRead(dest->file, &dest->header.bmiSize, 4, &i);
GpFileRead(dest->file, &dest->header.cols, 4, &i);
GpFileRead(dest->file, &dest->header.rows, 4, &i);
GpFileRead(dest->file, &dest->header.nPlanes, 2, &i);
GpFileRead(dest->file, &dest->header.bitsPerPixel, 2, &i);
GpFileRead(dest->file, &dest->header.compression, 4, &i);
GpFileRead(dest->file, &dest->header.cmpSize, 4, &i);
GpFileRead(dest->file, &dest->header.xScale, 4, &i);
GpFileRead(dest->file, &dest->header.yScale, 4, &i);
GpFileRead(dest->file, &dest->header.colors, 4, &i);
GpFileRead(dest->file, &dest->header.impColors, 4, &i);
// On vérifie la validité du fichier
if (dest->header.magic1 != 'B' || dest->header.magic2 != 'M' || dest->header.reserved != 0)
{
GpFileClose(dest->file);
dest->file = NULL;
dest->fileName[0] = 0;
}
return 1;
}
// Close a .BMP
void CloseBitmap(BMP_FILE * file)
{
GpFileClose(file->file);
file->file = NULL;
file->fileName[0] = 0;
}
// get a pixel at (x,y) in an unsigned long
unsigned long GetPixel(BMP_FILE * src, long x, long y)
{
long ret;
unsigned long i;
long offset = src->header.pixelOffset + src->header.bitsPerPixel / 8 * (src->header.rows - 1 - y) * src->header.cols + src->header.bitsPerPixel / 8 * x;
// On vérifie que l'on peut lire
if (x < 0 || x >= src->header.cols || y < 0 || y >= src->header.rows)
return -1;
// On se place au bon endroite pour lire
GpFileSeek(src->file, FROM_BEGIN, offset, &i);
GpFileRead(src->file, &ret, (src->header.bitsPerPixel / 8), &i);
return ret;
}
// Get the pixel at (x,y) into a RGB struct
int GetRGBPixel(BMP_FILE * src, long x, long y, RGB * dest)
{
unsigned long tmp = GetPixel(src, x, y);
if (tmp == -1)
return -1;
dest->r = (char) ((tmp >> 16) & 0x000000ff);
dest->g = (char) ((tmp >> 8) & 0x000000ff);
dest->b = (char) ((tmp) & 0x000000ff);
return tmp;
}
void GpMain(void *argv)
{
int k, i, j;
BMP_FILE origine;
RGB col;
unsigned short *conv = NULL;
GPDRAWSURFACE screen[1];
// Init 16 bit mode
GpGraphicModeSet(16, NULL);
GpLcdSurfaceGet(&screen[0], 0);
// Int SMC
GpFatInit();
gm_strcpy(origine.fileName, "gp:\CAR1.BMP");
// On ouvre l'image à convertir
if (!OpenBitmap(origine.fileName, &origine))
{
GpAppExit();
}
// Allocate memory for the converted picture
if (!(conv = gm_malloc(origine.header.cols * origine.header.rows * 2)))
GpAppExit();
for (j = 0; j < origine.header.cols; j++)
{
for (k = origine.header.rows - 1; k >= 0; k--)
{
GetRGBPixel(&origine, j, k, &col);
conv[(origine.header.cols - (origine.header.cols - j - 1)) * (origine.header.rows) - k - 1] = GP_RGB24(col.r, col.g, col.b);
}
}
// Close the openede bmp
CloseBitmap(&origine);
// Disp converted picture
GpBitBlt16(NULL, &screen[0], (GPC_LCD_WIDTH - origine.header.cols) / 2, (GPC_LCD_HEIGHT - origine.header.rows) / 2, origine.header.cols, origine.header.rows, (unsigned char*)conv, 0, 0, origine.header.cols, origine.header.rows);
while(1);
GpAppExit();
}
// Open a .BMP
int OpenBitmap(char *fileName, BMP_FILE * dest)
{
unsigned long i;
long ii;
// On essaie d'ouvrir le fichier
if (GpFileOpen(fileName, OPEN_R, &(dest->file)) != SM_OK)
return 0;
gm_strcpy(dest->fileName, fileName);
// On lit l'en-tête
GpFileSeek(dest->file, FROM_BEGIN, 0, &ii); GpFileRead(dest->file, &dest->header.magic1, 1, &i);
unsigned long GetPixel(BMP_FILE * src, long x, long y)
{
long ret;
long ii;
unsigned long i;
long offset = src->header.pixelOffset + src->header.bitsPerPixel / 8 * (src->header.rows - 1 - y) * src->header.cols + src->header.bitsPerPixel / 8 * x;
// On vérifie que l'on peut lire
if (x < 0 || x >= src->header.cols || y < 0 || y >= src->header.rows)
return -1;
// On se place au bon endroite pour lire
GpFileSeek(src->file, FROM_BEGIN, offset, &ii); GpFileRead(src->file, &ret, (src->header.bitsPerPixel / 8), &i);
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"
#include "gpfont.h"
#include "gpmm.h"
#include "gpstream.h"
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"
#include "gpfont.h"
#include "gpmm.h"
#include "gpmodplay.h"
#include "gpstream.h"
// convert a 24 bits color into a 16 bits color
#define GP_RGB24(r,g,b) ((((((r>>3))&0x1f)<<11)|((((g>>3))&0x1f)<<6)|((((b>>3))&0x1f)<<1))|0x0001)
// All informations in BMP header
typedef struct
{
char magic1, magic2;
long fileSize;
long reserved;
long pixelOffset;
long bmiSize;
long cols, rows;
short nPlanes;
short bitsPerPixel;
long compression, cmpSize;
long xScale, yScale;
long colors, impColors;
}
BMP_HEADER;
// An RGB pixel
typedef struct
{
unsigned char r;
unsigned char g;
unsigned char b;
}
RGB;
// A BMP type for use convenience
typedef struct
{
char fileName[256];
F_HANDLE file;
BMP_HEADER header;
}
BMP_FILE;
// Open a .BMP
int OpenBitmap(char *fileName, BMP_FILE * dest)
{
unsigned long i;
long ii;
// On essaie d'ouvrir le fichier
if (GpFileOpen(fileName, OPEN_R, &(dest->file)) != SM_OK)
return 0;
gm_strcpy(dest->fileName, fileName);
// On lit l'en-tête
GpFileSeek(dest->file, FROM_BEGIN, 0, &ii);
GpFileRead(dest->file, &dest->header.magic1, 1, &i);
GpFileRead(dest->file, &dest->header.magic2, 1, &i);
GpFileRead(dest->file, &dest->header.fileSize, 4, &i);
GpFileRead(dest->file, &dest->header.reserved, 4, &i);
GpFileRead(dest->file, &dest->header.pixelOffset, 4, &i);
GpFileRead(dest->file, &dest->header.bmiSize, 4, &i);
GpFileRead(dest->file, &dest->header.cols, 4, &i);
GpFileRead(dest->file, &dest->header.rows, 4, &i);
GpFileRead(dest->file, &dest->header.nPlanes, 2, &i);
GpFileRead(dest->file, &dest->header.bitsPerPixel, 2, &i);
GpFileRead(dest->file, &dest->header.compression, 4, &i);
GpFileRead(dest->file, &dest->header.cmpSize, 4, &i);
GpFileRead(dest->file, &dest->header.xScale, 4, &i);
GpFileRead(dest->file, &dest->header.yScale, 4, &i);
GpFileRead(dest->file, &dest->header.colors, 4, &i);
GpFileRead(dest->file, &dest->header.impColors, 4, &i);
// On vérifie la validité du fichier
if (dest->header.magic1 != 'B' || dest->header.magic2 != 'M' || dest->header.reserved != 0)
{
GpFileClose(dest->file);
dest->file = NULL;
dest->fileName[0] = 0;
}
return 1;
}
// Close a .BMP
void CloseBitmap(BMP_FILE * file)
{
GpFileClose(file->file);
file->file = NULL;
file->fileName[0] = 0;
}
// get a pixel at (x,y) in an unsigned long
unsigned long GetPixel(BMP_FILE * src, long x, long y)
{
long ret;
long ii;
unsigned long i;
long offset = src->header.pixelOffset + src->header.bitsPerPixel / 8 * (src->header.rows - 1 - y) * src->header.cols + src->header.bitsPerPixel / 8 * x;
// On vérifie que l'on peut lire
if (x < 0 || x >= src->header.cols || y < 0 || y >= src->header.rows)
return -1;
// On se place au bon endroite pour lire
GpFileSeek(src->file, FROM_BEGIN, offset, &ii);
GpFileRead(src->file, &ret, (src->header.bitsPerPixel / 8), &i);
return ret;
}
// Get the pixel at (x,y) into a RGB struct
int GetRGBPixel(BMP_FILE * src, long x, long y, RGB * dest)
{
unsigned long tmp = GetPixel(src, x, y);
if (tmp == -1)
return -1;
dest->r = (char) ((tmp >> 16) & 0x000000ff);
dest->g = (char) ((tmp >> 8) & 0x000000ff);
dest->b = (char) ((tmp) & 0x000000ff);
return tmp;
}
void GpMain(void *argv)
{
int k, j;
BMP_FILE origine;
RGB col;
unsigned short *conv = NULL;
GPDRAWSURFACE screen[1];
// Init 16 bit mode
GpGraphicModeSet(16, NULL);
GpLcdSurfaceGet(&screen[0], 0);
// Int SMC
GpFatInit();
gm_strcpy(origine.fileName, "gp:\image.bmp");
// On ouvre l'image à convertir
if (!OpenBitmap(origine.fileName, &origine))
{
GpAppExit();
}
// Allocate memory for the converted picture
if (!(conv = gm_malloc(origine.header.cols * origine.header.rows * 2)))
GpAppExit();
for (j = 0; j < origine.header.cols; j++)
{
for (k = origine.header.rows - 1; k >= 0; k--)
{
GetRGBPixel(&origine, j, k, &col);
conv[(origine.header.cols - (origine.header.cols - j - 1)) * (origine.header.rows) - k - 1] = GP_RGB24(col.r, col.g, col.b);
}
}
// Close the openede bmp
CloseBitmap(&origine);
// Disp converted picture
GpBitBlt16(NULL, &screen[0], (GPC_LCD_WIDTH - origine.header.cols) / 2, (GPC_LCD_HEIGHT - origine.header.rows) / 2, origine.header.cols, origine.header.rows, (unsigned char*)conv, 0, 0, origine.header.cols, origine.header.rows);
while(1);
GpAppExit();
}
if (!(gm_malloc(origine.header.cols * origine.header.rows * 2)))
GpAppExit(); else conv = gm_malloc(origine.header.cols * origine.header.rows * 2);
falken80 :
j'ai toujours le warning avec ta ligne rov.
Avseth m'a donné ce bout de code ce qui enléve ce warning :
if (!(gm_malloc(origine.header.cols * origine.header.rows * 2)))
GpAppExit(); else conv = gm_malloc(origine.header.cols * origine.header.rows * 2);
conv=gm_malloc(origine.header.cols * origine.header.rows * 2);
if (!conv)
GpAppExit();
int rvb(unsigned char r, unsigned char v, unsigned char b, unsigned char it)
/* r, v, b : 0..31; it : intensité : 0 ou 1; 1 de préférence */
{
return ( ( (r) <<11) | ( (v) <<6) | ( (b) <<1) | it );
}
unsigned char bmp[320*240*3];
F_HANDLE fi;
if (GpFileOpen("gp:\gpmm\image.bmp", OPEN_R, &fi) == SM_OK)
{
GpFileSeek(fi, FROM_BEGIN, 54, NULL);
GpFileRead(fi, &bmp, 76800*3, NULL);
GpFileClose(fi);
for (x = 0; x < 320; x++)
{
for (y = 0; y < 240; y++)
{
GpPointSet16(&gpDraw[nflip], x, 240 - y, rvb((bmp[(x+(y*320))*3 + 2]/8), (bmp[(x+(y*320))*3 + 1]/8), (bmp[(x+(y*320))*3]/8), 1));
}
}
flip_screen(); }
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"
#include "gpfont.h"
#include "gpmm.h"
#include "gpmodplay.h"
#include "gpstream.h"
#include "key.h"
//######################################
//# BMP READER
//######################################
int rvb(unsigned char r, unsigned char v, unsigned char b, unsigned char it)
/* r, v, b : 0..31; it : intensité : 0 ou 1; 1 de préférence */
{
return ( ( (r) <<11) | ( (v) <<6) | ( (b) <<1) | it );
}
int nflip=0;
GPDRAWSURFACE gpDraw[1];
void flip_screen(void)
{
GpSurfaceFlip( &gpDraw[nflip]);
nflip ^= 1;
}
//###################################
//# GPMAIN
//###################################
unsigned char bmp[320*240*3];
F_HANDLE fi;
void GpMain(void *argv)
{
int x,y;
GpFatInit();
// Init 16 bit mode
GpGraphicModeSet(16, NULL);
//GDL POWA
GpLcdSurfaceGet(&gpDraw[0],0) ;
GpLcdSurfaceGet(&gpDraw[1],1) ;
GpSurfaceFlip(&gpDraw[0]);
if (GpFileOpen("gp:\gpmm\image.bmp", OPEN_R, &fi) == SM_OK)
{
GpFileSeek(fi, FROM_BEGIN, 54, NULL);
GpFileRead(fi, &bmp, 76800*3, NULL);
GpFileClose(fi);
for (x = 0; x < 320; x++)
{
for (y = 0; y < 240; y++)
{
GpPointSet16(&gpDraw[nflip], x, 240 - y, rvb((bmp[(x+(y*320))*3 + 2]/8), (bmp[(x+(y*320))*3 + 1]/8), (bmp[(x+(y*320))*3]/8), 1));
}
}
}
GpLcdEnable() ;
flip_screen();
for(;;)
{
refresh_key();
}
GpAppExit();
}