#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
#define DEBUG ON
#define DEBUG_ON ON
#define DEBUG_OFF OFF
#define RB "rb"
#define WB "wb"
#define RT "rt"
#define WT "wt"
#define MAX_PAL 256
#define MAX_CHAR 256
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef struct {
int count;
struct {
long flag;
long pal_no;
}info[MAX_PAL];
}NUKI;
#define FOPEN(fp,filename,mode)\
if((fp = fopen(filename,mode)) == NULL){\
printf("ERROR : [%s]\n",filename);\
printf(" 指定ファイルが開けません。ファイル名を確認して下さい。\n");\
exit(1);\
}
void dispUsage( void );
int getFilenameAll(char *, char *);
char inFileName[MAX_CHAR];
char outFileName[MAX_CHAR];
int main(int argc,char *argv[])
{
FILE *infile, *outfile;
static char* helpTbl[] = {"-h","-?","/h","/?"};
uchar *palHead,*wp;
uchar tRed,tGreen,tBlue,tAlpha;
NUKI nuki;
long i;
nuki.count=0;
for(i=0;i<MAX_PAL;i++){
nuki.info[i].flag = 0;
nuki.info[i].pal_no = 0;
}
switch(argc){
case 1:
case 2:
dispUsage();
exit(1);
break;
case 3:
FOPEN(infile, argv[1],RB);
FOPEN(outfile,argv[2],WT);
break;
default:
dispUsage();
exit(1);
}
getFilenameAll(argv[1],inFileName);
getFilenameAll(argv[2],outFileName);
fprintf(outfile,"/*\n");
fprintf(outfile," Input File = [%s]\n",inFileName);
fprintf(outfile," Output File = [%s]\n",outFileName);
fprintf(outfile," 16色と256色のどちらのパレットを使用するか確認する事\n");
fprintf(outfile," */\n");
palHead = malloc(sizeof(uchar) * 3 * MAX_PAL);
fread(palHead,sizeof(uchar),MAX_PAL*3,infile);
wp=palHead;
for(i=0;i<MAX_PAL;i++){
tRed = wp[0];
tGreen = wp[1];
tBlue = wp[2];
tRed >>= 3;
tGreen >>= 3;
tBlue >>= 3;
if(0x0000 == (tRed|tGreen|tBlue)){
tAlpha = 0;
nuki.info[nuki.count].flag = 1;
nuki.info[nuki.count].pal_no = i;
nuki.count++;
}else{
tAlpha = 1;
}
if( ((i)&15) == 0 ){
fprintf(outfile,"\t");
fprintf(outfile,"/* entry_tlut_no_%d */",i/16);
fprintf(outfile,"\n") ;
fprintf(outfile,"\t");
}
fprintf(outfile,"RGBA16CIP(%2d,%2d,%2d,%2d)",tRed,tGreen,tBlue,tAlpha);
fprintf(outfile,",") ;
if( ((i+1)&3) == 0 ){
fprintf(outfile,"\n") ;
fprintf(outfile,"\t");
}
wp+=3;
}
printf("--------[ use files ]\n");
printf(" input file = [%s]\n",inFileName);
printf(" output file = [%s]\n",outFileName);
printf("--------[ Alpha Information ]\n");
printf(" AlphaCount = %d\n",nuki.count);
for(i=0;i<nuki.count;i++){
printf(" AlphaPalNO = %d\n",nuki.info[i].pal_no);
}
printf("-----------------------------------------------------------\n");
return EXIT_SUCCESS;
}
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){
printf("ファイル名取得失敗\n");
exit(0);
}
if(*fullName == '\0'){
newName[i] = '\0';
return 1;
}
newName[i++] = *fullName++;
j++;
}
return 0;
}
void dispUsage(void){
puts("");
puts("======================================================");
puts(" actp2cip ver 0.01");
puts("");
puts(" usage: actp2cip <ActPalFile> <CiPalFile>");
puts(" : supported PhotoShop ACT files");
puts("======================================================");
puts("");
}