#ifndef _BMP_H_
#define _BMP_H_
#define BI_RGB 0L
#define BI_RLE8 1L
#define BI_RLE4 2L
typedef struct {
unsigned short bfType;
unsigned long bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned long bfOffBits;
} BITMAPFILEHEADER;
typedef struct {
unsigned long biSize;
long biWidth;
long biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
} BITMAPINFOHEADER;
typedef struct{
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbReserved;
} RGBQUAD;
typedef struct{
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
} RGBQUAD24;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "bmp.h"
#include "bmp2ci.h"
#define MAX_CHAR 256
#define MAX_PAL 256
#define PAL_16 16
#define PAL_256 256
#define MAX_PIXEL 320*240
typedef struct {
int count;
struct {
long flag;
long pal_no;
}info[MAX_PAL];
}NUKI;
typedef struct {
long count;
struct {
long flag;
long pixel_no;
}info[MAX_PIXEL];
}NUKI16BIT;
#define RGBA16CIP(r,g,b,a) (u16)(((r)<<11)|((g)<<6)|((b)<<1)|((a)&1))
char fileName[MAX_CHAR];
char fileName_OUT[MAX_CHAR];
char fileName_TMF_IMG[MAX_CHAR];
char fileName_TMF[MAX_CHAR];
char fileName_TLF_TLUT[MAX_CHAR];
char fileName_TLF[MAX_CHAR];
char inFileName[MAX_CHAR];
char outFileName[MAX_CHAR];
int main(int argc, char *argv[])
{
FILE *infile, *outfile;
static char* helpTbl[] = {"-h","-?","/h","/?"};
static BITMAPFILEHEADER bmfh;
static BITMAPINFOHEADER bmih;
ulong TableCount;
int i;
switch(argc){
case 1:
DispUsage();
exit(1);
break;
case 2:
for(i=0;i<4;i++){
if(!strcmp(argv[1],helpTbl[i])){
DispUsage();
exit(1);
}
}
DispErr(1);
exit(1);
break;
case 3:
FOPEN(infile, argv[1],RB);
FOPEN(outfile,argv[2],WT);
break;
default:
DispErr(2);
exit(1);
}
getFilename(argv[1],fileName);
getFilename(argv[2],fileName_OUT);
getFilenameAll(argv[1],inFileName);
getFilenameAll(argv[2],outFileName);
getFilename(argv[1],fileName_TMF_IMG);
strcat(fileName_TMF_IMG,"_tmf_img");
getFilename(argv[1],fileName_TMF);
strcat(fileName_TMF,"_tmf");
getFilename(argv[1],fileName_TLF_TLUT);
strcat(fileName_TLF_TLUT,"_tlf_tlut");
getFilename(argv[1],fileName_TLF);
strcat(fileName_TLF,"_tlf");
if( !checkFileHeader(&bmfh,infile) ){
fclose(infile);
fclose(outfile);
DispErr(1);
exit(1);
}
TableCount = checkBmpInfo(&bmfh,&bmih,infile,outfile);
switch(bmih.biBitCount){
case 4:
Bmp4Bit2Ci4Bit(&bmih,TableCount,infile,outfile);
break;
case 8:
Bmp8Bit2Ci8Bit(&bmih,TableCount,infile,outfile);
break;
case 24:
Bmp24Bit2RGBA16Bit(&bmih,infile,outfile);
break;
case 1:
puts("ERR: Sorry, this bitcount is not supported.\n");
break;
default:
puts("ERR: Unknown color format.\n");
break;
}
fclose(infile);
fclose(outfile);
return EXIT_SUCCESS;
}
void Bmp24Bit2RGBA16Bit(BITMAPINFOHEADER *pBmih,FILE* iFile,FILE* oFile)
{
RGBQUAD24 *pPixelHead;
RGBQUAD24 pdat;
long i,j;
uchar elRed,elGreen,elBlue;
ushort *pixTmp,*pixTmp2;
NUKI16BIT nuki16b;
nuki16b.count=0;
for(i=0;i<MAX_PIXEL;i++){
nuki16b.info[i].flag = OFF;
nuki16b.info[i].pixel_no = 0;
}
pPixelHead=(RGBQUAD24 *)malloc(sizeof(RGBQUAD24) * pBmih->biWidth * pBmih->biHeight);
fread(pPixelHead,sizeof(RGBQUAD24),pBmih->biWidth * pBmih->biHeight,iFile);
pixTmp = (ushort *)malloc(sizeof(ushort) * pBmih->biWidth * pBmih->biHeight);
for(i=0;i<pBmih->biHeight;i++){
for(j=0;j<pBmih->biWidth;j++){
pdat = *(pPixelHead+(i*pBmih->biWidth)+(j));
elRed = pdat.rgbRed;
elGreen = pdat.rgbGreen;
elBlue = pdat.rgbBlue;
elRed >>= 3;
elGreen >>= 3;
elBlue >>= 3;
if( 0x0000 == (elRed|elGreen|elBlue) ){
pixTmp[i*pBmih->biWidth + j]=(elRed<<11) | (elGreen<<6) | (elBlue<<1) | 0x0000;
nuki16b.info[nuki16b.count].flag = ON;
nuki16b.info[nuki16b.count].pixel_no = (i*pBmih->biWidth) + (j);
nuki16b.count++;
}else{
pixTmp[i*pBmih->biWidth + j]=(elRed<<11) | (elGreen<<6) | (elBlue<<1) | 0x0001;
}
}
}
pixTmp2 = (ushort *)malloc(sizeof(ushort) * pBmih->biWidth * pBmih->biHeight);
for(i=0;i<pBmih->biHeight * pBmih->biWidth;i++){
pixTmp2[i]=pixTmp[(pBmih->biHeight * pBmih->biWidth)-i-1];
}
for(i=0;i<pBmih->biHeight;i++){
for(j=0;j<pBmih->biWidth;j++){
pixTmp[i*pBmih->biWidth + (pBmih->biWidth-1-j)]=
pixTmp2[i * pBmih->biWidth + j];
}
}
fprintf(oFile,"/*---------------------------------------------------------------------------*\n");
fprintf(oFile," | %s",outFileName);
fprintf(oFile," - BETA/16BIT-RGBA\n",outFileName);
fprintf(oFile," |\n");
fprintf(oFile," | in file = %s \n",inFileName);
fprintf(oFile," | out file = %s \n",outFileName);
fprintf(oFile," |\n");
fprintf(oFile," | image height = %d\n",pBmih->biHeight);
fprintf(oFile," | image width = %d\n",pBmih->biWidth);
fprintf(oFile," | image format = G_IM_FMT_RGBA\n");
fprintf(oFile," | image bit size = G_IM_SIZ_16b\n");
fprintf(oFile," | tlut type = nothing\n");
fprintf(oFile," | tlut size = 0\n");
fprintf(oFile," |\n");
fprintf(oFile," *---------------------------------------------------------------------------*/ \n");
fprintf(oFile,"#ifndef _%s_H_\n",fileName);
fprintf(oFile,"#define _%s_H_\n",fileName);
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | include\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"#include \"sprite.h\"\n");
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | externs\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"extern TMF %s;\n",fileName_TMF);
fprintf(oFile,"extern u16 %s[];\n",fileName_TLF_TLUT);
fprintf(oFile,"extern TLF %s;\n",fileName_TLF);
fprintf(oFile,"extern PICTURE %s;\n",fileName);
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | SPRITE DATA\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TMF_IMG);
fprintf(oFile,"\n");
fprintf(oFile,"static u32 %s[]\n",fileName_TMF_IMG);
fprintf(oFile,"={\n");
for(i=0; i<(pBmih->biWidth * pBmih->biHeight);i++){
if(!i) fprintf(oFile,"\t");
if( !(i&1) ) fprintf(oFile,"0x");
fprintf(oFile,"%04x",pixTmp[i]);
if( !((i+1)&1) ) fprintf(oFile,",");
if( ((i+1)&15) == 0 ){
fprintf(oFile,"\n");
fprintf(oFile,"\t");
}
}
fprintf(oFile,"\n");
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TMF);
fprintf(oFile,"\n");
fprintf(oFile,"static TMF %s\n",fileName_TMF);
fprintf(oFile,"={\n");
fprintf(oFile,"\t%s,\t/* image address\t*/\n",fileName_TMF_IMG);
fprintf(oFile,"\tG_IM_FMT_RGBA,\t/* image format\t\t*/\n");
fprintf(oFile,"\tG_IM_SIZ_16b,\t/* image bit size\t*/\n");
fprintf(oFile,"\t%d,\t\t\t/* image width\t\t*/\n",pBmih->biWidth);
fprintf(oFile,"\t%d,\t\t\t/* image height\t\t*/\n",pBmih->biHeight);
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TLF_TLUT);
fprintf(oFile,"\n");
fprintf(oFile,"static u16 %s[]\n",fileName_TLF_TLUT);
fprintf(oFile,"={0};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TLF);
fprintf(oFile,"\n");
fprintf(oFile,"static TLF %s\n",fileName_TLF);
fprintf(oFile,"={\n");
fprintf(oFile,"\tG_TT_RGBA16,\t\t/* TLUT type\t\t*/\n");
fprintf(oFile,"\t0,\t/* TLUT address\t\t*/\n",fileName_TLF_TLUT);
fprintf(oFile,"\t0,\t\t\t\t\t/* TLUT size\t\t*/\n");
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName);
fprintf(oFile,"\n");
fprintf(oFile,"PICTURE %s\n",fileName);
fprintf(oFile,"={\n");
fprintf(oFile,"\t&%s,\n",fileName_TMF);
fprintf(oFile,"\t&%s,\n",fileName_TLF);
fprintf(oFile,"\t0,\n");
fprintf(oFile,"};\n");
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | end of %s\n",outFileName);
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"#endif\n");
printf("--------[ 16Bit-RGBA Texture Information ]\n");
printf(" FILE = [%s]\n",outFileName);
printf(" Width = %ld\n", pBmih->biWidth);
printf(" Height = %ld\n", pBmih->biHeight);
printf(" Colors = 16-Bit : 65536 colors\n");
printf("--------[ Alpha Information ]\n");
printf(" AlphaCount = %d\n",nuki16b.count);
for(i=0;i<nuki16b.count;i++){
printf(" AlphaPixelNO = %d\n",nuki16b.info[i].pixel_no);
}
printf("-----------------------------------------------------------\n");
free(pixTmp);
free(pixTmp2);
}
void Bmp4Bit2Ci4Bit(BITMAPINFOHEADER *pBmih,ulong TblCnt,FILE* iFile,FILE* oFile)
{
uchar *pPixelHead;
uchar *pTmpPixel_1,*pTmpPixel_2;
RGBQUAD *pColTblHead;
RGBQUAD wColTbl;
ushort palRed,palGreen,palBlue,palAlpha;
long i,j;
NUKI nuki;
nuki.count=0;
for(i=0;i<MAX_PAL;i++){
nuki.info[i].flag = OFF;
nuki.info[i].pal_no = 0;
}
pColTblHead = (RGBQUAD *)malloc( sizeof(RGBQUAD) * TblCnt );
fread(pColTblHead,sizeof(RGBQUAD),TblCnt,iFile);
pPixelHead=(uchar *)malloc( sizeof(uchar)* pBmih->biWidth * (pBmih->biHeight/2) );
fread(pPixelHead,sizeof(uchar),(pBmih->biWidth * pBmih->biHeight)/2,iFile);
#if DEBUG_OFF
printf("Color Table Count = [%ld]\n",TblCnt);
printf("Color Table size = [%ld]\n",TblCnt*sizeof(RGBQUAD));
printf("Pixel Data size = [%ld]\n",(long)( (sizeof(uchar) * pBmih->biWidth * pBmih->biHeight)/2) );
#endif
pTmpPixel_1 = (uchar *)malloc( sizeof(uchar) * pBmih->biWidth * (pBmih->biHeight/2) );
pTmpPixel_2 = (uchar *)malloc( sizeof(uchar) * pBmih->biWidth * (pBmih->biHeight/2) );
for(i=0;i<pBmih->biHeight * (pBmih->biWidth/2);i++){
pTmpPixel_1[i]=pPixelHead[(pBmih->biHeight * (pBmih->biWidth/2))-i-1];
}
for(i=0;i<pBmih->biHeight;i++){
for(j=0;j<(pBmih->biWidth/2);j++){
pTmpPixel_2[i*(pBmih->biWidth/2) + ((pBmih->biWidth/2)-1-j)]=
pTmpPixel_1[i * (pBmih->biWidth/2) + j];
}
}
fprintf(oFile,"/*---------------------------------------------------------------------------*\n");
fprintf(oFile," | %s",outFileName);
fprintf(oFile," - 16色/16BIT-RGBA\n");
fprintf(oFile," |\n");
fprintf(oFile," | in file = %s \n",inFileName);
fprintf(oFile," | out file = %s \n",outFileName);
fprintf(oFile," |\n");
fprintf(oFile," | image height = %d\n",pBmih->biHeight);
fprintf(oFile," | image width = %d\n",pBmih->biWidth);
fprintf(oFile," | image format = G_IM_FMT_CI\n");
fprintf(oFile," | image bit size = G_IM_SIZ_4b\n");
fprintf(oFile," | tlut type = G_TT_RGBA16\n");
fprintf(oFile," | tlut size = 16\n");
fprintf(oFile," | usePalette = %2d/16\n",TblCnt);
fprintf(oFile," | dmyPalette = %2d/16\n",PAL_16 - TblCnt);
fprintf(oFile," |\n");
fprintf(oFile," *---------------------------------------------------------------------------*/ \n");
fprintf(oFile,"#ifndef _%s_H_\n",fileName);
fprintf(oFile,"#define _%s_H_\n",fileName);
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | include\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"#include \"sprite.h\"\n");
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | externs\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"extern TMF %s;\n",fileName_TMF);
fprintf(oFile,"extern u16 %s[];\n",fileName_TLF_TLUT);
fprintf(oFile,"extern TLF %s;\n",fileName_TLF);
fprintf(oFile,"extern PICTURE %s;\n",fileName);
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | SPRITE DATA\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TMF_IMG);
fprintf(oFile,"\n");
fprintf(oFile,"static u32 %s[]\n",fileName_TMF_IMG);
fprintf(oFile,"={\n");
for(i=0;i<pBmih->biHeight*(pBmih->biWidth/2);i++){
if(!i) fprintf(oFile,"\t");
if( !(i&3) ) fprintf(oFile,"0x");
fprintf(oFile,"%02x",pTmpPixel_2[i]);
if( !((i+1)&3) ) fprintf(oFile,",");
if( ((i+1)&15) == 0 ){
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
}
fprintf(oFile,"\n");
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TMF);
fprintf(oFile,"\n");
fprintf(oFile,"static TMF %s\n",fileName_TMF);
fprintf(oFile,"={\n");
fprintf(oFile,"\t%s,\t/* image address\t*/\n",fileName_TMF_IMG);
fprintf(oFile,"\tG_IM_FMT_CI,\t/* image format\t\t*/\n");
fprintf(oFile,"\tG_IM_SIZ_4b,\t/* image bit size\t*/\n");
fprintf(oFile,"\t%d,\t\t\t/* image width\t\t*/\n",pBmih->biWidth);
fprintf(oFile,"\t%d,\t\t\t/* image height\t\t*/\n",pBmih->biHeight);
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TLF_TLUT);
fprintf(oFile,"\n");
fprintf(oFile,"static u16 %s[]\n",fileName_TLF_TLUT);
fprintf(oFile,"={\n");
for(i=0;i<16;i++){
if(i<TblCnt){
wColTbl=pColTblHead[i];
palRed = wColTbl.rgbRed;
palBlue = wColTbl.rgbBlue;
palGreen = wColTbl.rgbGreen;
if( 0x0000==(palRed | palGreen | palBlue) ){
nuki.info[nuki.count].flag = ON;
nuki.info[nuki.count].pal_no = i;
nuki.count++;
palAlpha = 0;
}else{
palAlpha = 1;
}
if( ((i)&15) == 0 ){
fprintf(oFile,"\t");
fprintf(oFile,"/* entry_tlut_no_%d */",i/16);
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
fprintf(oFile,"IAP(255,%3d)",palBlue);
fprintf(oFile,",") ;
if( ((i+1)&3) == 0 ){
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
}else{
if( ((i)&15) == 0 ){
fprintf(oFile,"/* entry_tlut_no_%d */",i/16);
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
fprintf(oFile,"IAP( 255,0)");
fprintf(oFile,",") ;
if( ((i+1)&3) == 0 ){
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
}
}
fprintf(oFile,"\n");
fprintf(oFile,"};\n");
printf("--------[ CI-4Bit Texture Information ]\n");
printf(" FILE = [%s]\n",outFileName);
printf(" Width = %ld\n", pBmih->biWidth);
printf(" Height = %ld\n", pBmih->biHeight);
printf(" Colors = 4-Bit : Index 16 colors\n");
printf(" UsePalette = %2d/16\n",TblCnt);
printf(" DmyPalette = %2d/16\n",PAL_16 - TblCnt);
if((PAL_16 - TblCnt)){
printf(" DmyPalOut = RGBA16CIP( 0, 0, 0, 0)\n");
}
printf("--------[ Alpha Information ]\n");
printf(" AlphaCount = %d\n",nuki.count);
for(j=0;j<nuki.count;j++){
printf(" AlphaPalNO = %d\n",nuki.info[j].pal_no);
}
printf("-----------------------------------------------------------\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TLF);
fprintf(oFile,"\n");
fprintf(oFile,"static TLF %s\n",fileName_TLF);
fprintf(oFile,"={\n");
fprintf(oFile,"\tG_TT_RGBA16,\t\t/* TLUT type\t\t*/\n");
fprintf(oFile,"\t%s,\t/* TLUT address\t\t*/\n",fileName_TLF_TLUT);
fprintf(oFile,"\t16,\t\t\t\t\t/* TLUT size\t\t*/\n");
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName);
fprintf(oFile,"\n");
fprintf(oFile,"PICTURE %s\n",fileName);
fprintf(oFile,"={\n");
fprintf(oFile,"\t&%s,\n",fileName_TMF);
fprintf(oFile,"\t&%s,\n",fileName_TLF);
fprintf(oFile,"\t0,\n");
fprintf(oFile,"};\n");
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | end of %s\n",outFileName);
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"#endif\n");
free(pPixelHead);
free(pColTblHead);
free(pTmpPixel_1);
free(pTmpPixel_2);
}
void Bmp8Bit2Ci8Bit(BITMAPINFOHEADER *pBmih,ulong TblCnt,FILE* iFile,FILE* oFile)
{
uchar *pPixelHead;
uchar *pTmpPixel_1,*pTmpPixel_2;
RGBQUAD *pColTblHead;
RGBQUAD wColTbl;
ushort palRed,palGreen,palBlue,palAlpha;
long i,j;
NUKI nuki;
int lpcnt=0;
nuki.count=0;
for(i=0;i<MAX_PAL;i++){
nuki.info[i].flag = OFF;
nuki.info[i].pal_no = 0;
}
pColTblHead = (RGBQUAD *)malloc( sizeof(RGBQUAD) * TblCnt );
fread(pColTblHead,sizeof(RGBQUAD),TblCnt,iFile);
pPixelHead=(uchar *)malloc( sizeof(uchar)* pBmih->biWidth * (pBmih->biHeight) );
fread(pPixelHead,sizeof(uchar),(pBmih->biWidth * pBmih->biHeight),iFile);
#if DEBUG_OFF
printf("\tColor Table Count = [%ld]\n",TblCnt);
printf("\tColor Table size = [%ld]\n",TblCnt*sizeof(RGBQUAD));
printf("\tPixel Data size = [%ld]\n",(long)( (sizeof(uchar) * pBmih->biWidth * pBmih->biHeight)) );
#endif
pTmpPixel_1 = (uchar *)malloc( sizeof(uchar) * pBmih->biWidth * (pBmih->biHeight) );
pTmpPixel_2 = (uchar *)malloc( sizeof(uchar) * pBmih->biWidth * (pBmih->biHeight) );
for(i=0;i<pBmih->biHeight * pBmih->biWidth;i++){
pTmpPixel_1[i]=pPixelHead[(pBmih->biHeight * pBmih->biWidth)-i-1];
}
for(i=0;i<pBmih->biHeight;i++){
for(j=0;j<pBmih->biWidth;j++){
pTmpPixel_2[i*pBmih->biWidth + (pBmih->biWidth-1-j)]=
pTmpPixel_1[i * pBmih->biWidth + j];
}
}
fprintf(oFile,"/*---------------------------------------------------------------------------*\n");
fprintf(oFile," | %s",outFileName);
fprintf(oFile," - 256色/16BIT-RGBA \n");
fprintf(oFile," |\n");
fprintf(oFile," | in file = %s \n",inFileName);
fprintf(oFile," | out file = %s \n",outFileName);
fprintf(oFile," |\n");
fprintf(oFile," | image height = %d\n",pBmih->biHeight);
fprintf(oFile," | image width = %d\n",pBmih->biWidth);
fprintf(oFile," | image format = G_IM_FMT_CI\n");
fprintf(oFile," | image bit size = G_IM_SIZ_8b\n");
fprintf(oFile," | tlut type = G_TT_RGBA16\n");
fprintf(oFile," | tlut size = 256\n");
fprintf(oFile," | usePalette = %2d/256\n",TblCnt);
fprintf(oFile," | dmyPalette = %2d/256\n",PAL_256 - TblCnt);
fprintf(oFile," |\n");
fprintf(oFile," *---------------------------------------------------------------------------*/ \n");
fprintf(oFile,"#ifndef _%s_H_\n",fileName);
fprintf(oFile,"#define _%s_H_\n",fileName);
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | include\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"#include \"sprite.h\"\n");
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | externs\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"extern TMF %s;\n",fileName_TMF);
fprintf(oFile,"extern u16 %s[];\n",fileName_TLF_TLUT);
fprintf(oFile,"extern TLF %s;\n",fileName_TLF);
fprintf(oFile,"extern PICTURE %s;\n",fileName);
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | SPRITE DATA\n");
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TMF_IMG);
fprintf(oFile,"\n");
fprintf(oFile,"static u32 %s[]\n",fileName_TMF_IMG);
fprintf(oFile,"={\n");
for(i=0;i<pBmih->biHeight*pBmih->biWidth;i++){
if(!i){
fprintf(oFile,"\t");
}
if( !(i&3) ){
fprintf(oFile,"0x");
}
fprintf(oFile,"%02x",pTmpPixel_2[i]);
if( !((i+1)&3) ){
fprintf(oFile,",") ;
}
if( ((i+1)&15) == 0 ){
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
}
fprintf(oFile,"\n");
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TMF);
fprintf(oFile,"\n");
fprintf(oFile,"static TMF %s\n",fileName_TMF);
fprintf(oFile,"={\n");
fprintf(oFile,"\t%s,\t/* image address\t*/\n",fileName_TMF_IMG);
fprintf(oFile,"\tG_IM_FMT_CI,\t/* image format\t\t*/\n");
fprintf(oFile,"\tG_IM_SIZ_8b,\t/* image bit size\t*/\n");
fprintf(oFile,"\t%d,\t\t\t/* image width\t\t*/\n",pBmih->biWidth);
fprintf(oFile,"\t%d,\t\t\t/* image height\t\t*/\n",pBmih->biHeight);
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TLF_TLUT);
fprintf(oFile,"\n");
fprintf(oFile,"static u16 %s[]\n",fileName_TLF_TLUT);
fprintf(oFile,"={\n");
for(i=0;i<256;i++){
if(i<TblCnt){
wColTbl=pColTblHead[i];
palRed = wColTbl.rgbRed;
palBlue = wColTbl.rgbBlue;
palGreen = wColTbl.rgbGreen;
palRed >>= 3;
palGreen >>= 3;
palBlue >>= 3;
if( 0x0000==(palRed | palGreen | palBlue) ){
nuki.info[nuki.count].flag = ON;
nuki.info[nuki.count].pal_no = i;
nuki.count++;
palAlpha = 0;
}else{
palAlpha = 1;
}
if( ((i)&15) == 0 ){
fprintf(oFile,"\t");
fprintf(oFile,"/* entry_tlut_no_%d */",i/16);
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
fprintf(oFile,"RGBA16CIP(%2d,%2d,%2d,%2d)",palRed,palGreen,palBlue,palAlpha);
fprintf(oFile,",") ;
if( ((i+1)&3) == 0 ){
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
}else{
if( ((i)&15) == 0 ){
fprintf(oFile,"/* entry_tlut_no_%d */",i/16);
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
fprintf(oFile,"RGBA16CIP( 0, 0, 0, 0)");
fprintf(oFile,",") ;
if( ((i+1)&3) == 0 ){
fprintf(oFile,"\n") ;
fprintf(oFile,"\t");
}
}
}
fprintf(oFile,"\n");
fprintf(oFile,"};\n");
printf("--------[ CI-8Bit Texture Information ]\n");
printf(" FILE = [%s]\n",outFileName);
printf(" Width = %ld\n", pBmih->biWidth);
printf(" Height = %ld\n", pBmih->biHeight);
printf(" Colors = 8-Bit : Index 256 colors\n");
printf(" UsePalette = %2d/256\n",TblCnt);
printf(" DmyPalette = %2d/256\n",PAL_256 - TblCnt);
if((PAL_256 - TblCnt)){
printf(" DmyPalOut = RGBA16CIP( 0, 0, 0, 0)\n");
}
printf("--------[ Alpha Information ]\n");
printf(" AlphaCount = %d\n",nuki.count);
for(j=0;j<nuki.count;j++){
printf(" AlphaPalNO = %d\n",nuki.info[j].pal_no);
}
printf("-----------------------------------------------------------\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName_TLF);
fprintf(oFile,"\n");
fprintf(oFile,"static TLF %s\n",fileName_TLF);
fprintf(oFile,"={\n");
fprintf(oFile,"\tG_TT_RGBA16,\t\t/* TLUT type\t\t*/\n");
fprintf(oFile,"\t%s,\t/* TLUT address\t\t*/\n",fileName_TLF_TLUT);
fprintf(oFile,"\t256,\t\t\t\t\t/* TLUT size\t\t*/\n");
fprintf(oFile,"};\n");
fprintf(oFile,"\n");
fprintf(oFile,"\n");
fprintf(oFile,"static Gfx %s_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n",fileName);
fprintf(oFile,"\n");
fprintf(oFile,"PICTURE %s\n",fileName);
fprintf(oFile,"={\n");
fprintf(oFile,"\t&%s,\n",fileName_TMF);
fprintf(oFile,"\t&%s,\n",fileName_TLF);
fprintf(oFile,"\t0,\n");
fprintf(oFile,"};\n");
fprintf(oFile,"/*------------------------------------------------------------*\n");
fprintf(oFile," | end of %s\n",outFileName);
fprintf(oFile," *------------------------------------------------------------*/\n");
fprintf(oFile,"#endif\n");
free(pPixelHead);
free(pColTblHead);
free(pTmpPixel_1);
free(pTmpPixel_2);
}
int getFilename(char *fullName, char *newName)
{
#define GF_MOZI_MAX 256
int i,j;
i = j = 0;
while(*fullName != '\0'){
if(*fullName == '\\'){
j=0 ;
}
if(j>GF_MOZI_MAX){
DispErr(4);
exit(0);
}
if(*fullName == '.'){
newName[i] = '\0';
return 1;
}
newName[i++] = *fullName++;
j++;
}
return 0;
}
int getFilenameAll(char *fullName, char *newName)
{
#define GFA_MOZI_MAX 256
int i,j;
i = j = 0;
while(*fullName != '\0'){
if(*fullName == '\\'){
j=0 ;
}
if(j>GFA_MOZI_MAX){
DispErr(4);
exit(0);
}
if(*fullName == '\0'){
newName[i] = '\0';
return 1;
}
newName[i++] = *fullName++;
j++;
}
return 0;
}
int checkFileHeader( BITMAPFILEHEADER *pBmfh ,FILE* iFile )
{
fread(pBmfh, 14, 1, iFile);
if(pBmfh->bfType != 19778) return FALSE;
else return TRUE;
}
ulong checkBmpInfo( BITMAPFILEHEADER *pBmfh, BITMAPINFOHEADER *pBmih,
FILE *iFile, FILE *oFile)
{
ulong tblcnt;
fread(pBmih, 40, 1, iFile);
printf("--------< File Information (*.bmp,*.ci,alpha) >------------\n");
printf("--------[ BMP Image Information ]\n");
printf(" FILE = [%s]\n",inFileName);
printf(" Width = %ld\n", pBmih->biWidth);
printf(" Height = %ld\n", pBmih->biHeight);
printf(" Colors = ");
switch(pBmih->biBitCount){
case 1:
printf("1-bit monochrome\n");
break;
case 4:
printf("4-bit 16 colors\n");
break;
case 8:
printf("8-bit 256 colors\n");
break;
case 24:
printf("24-bit colors\n");
break;
default:
printf("Unknown color format\n");
break;
}
printf(" Compression = ");
switch(pBmih->biCompression){
case BI_RGB:
printf("No Compression\n");
break;
case BI_RLE8:
printf("RLE8\n");
break;
case BI_RLE4:
printf("RLE4\n");
break;
default:
printf("Unknown compression format\n");
fclose(oFile);
fclose(iFile);
DispErr(2);
exit(1);
}
if(pBmih->biCompression != BI_RGB){
fclose(oFile);
fclose(iFile);
DispErr(3);
exit(1);
}
switch(pBmih->biBitCount){
case 4:
case 8:
if( !pBmih->biClrUsed ) tblcnt = (ulong)pow(2, pBmih->biBitCount);
else tblcnt = pBmih->biClrUsed;
break;
case 24:
tblcnt = pBmih->biClrUsed;
break;
case 1:
case 16:
case 32:
default:
fclose(iFile);
fclose(oFile);
DispErr(2);
exit(1);
}
return tblcnt;
}
void DispErr(int errnum)
{
switch (errnum) {
case 1 :
puts("ERR: InputFile is not a BMP file.\n");
break;
case 2 :
puts("ERR: Sorry, this bitcount is not supported.\n");
break;
case 3 :
puts("ERR: Sorry, RLE bitmap is not supported.\n");
break;
case 4 :
puts("ERR: ファイル名称を確認してください.\n");
break;
default :
puts("ERR: Sorry,Sorry,Sorry,Sorry. ");
break;
}
}
unsigned short chendian16(unsigned short *num)
{
unsigned char high, low;
unsigned short out;
high = (*num >> 8) & 0x00FF;
low = *num & 0x00FF;
out = ((unsigned int)low << 8) | (unsigned int)high;
*num = out;
return out;
}
unsigned long chendian32(unsigned long *num)
{
unsigned short high, low;
unsigned long out;
high = (*num >> 16) & 0x0000FFFF;
low = *num & 0x0000FFFF;
high = chendian16(&high);
low = chendian16(&low);
out = ((unsigned long)low << 16) | (unsigned long)high;
*num = out;
return out;
}
void DispUsage(void){
puts("");
puts("bmp2ci ver 0.01 = bmpfile to cifile converter");
puts("");
puts("usage: bmp2ci <bmpFilename> <ciFilename>");
puts(" : supported BMP files");
puts(" : No Compression. 4-bit/8-bit/24-bit colors.");
puts(" : attention.");
puts(" : palette or pixel = Convert RGBA5551-Format.");
}