00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <windows.h>
00012 #include <io.h>
00013 #include <stdio.h>
00014 #include <string.h>
00015
00016 #if __SC__
00017 #pragma ZTC align 1
00018 #endif
00019
00020 #include "../common/mem.h"
00021
00022 #define FI_DIB 0
00023 #define FI_GIF 1
00024 #define FI_TGA 2
00025 #define FI_CEL 3
00026 #define PALVERSION 0x300
00027 #define MAXPALETTE 256
00028 #define MAXTEXT 256
00029
00030 #if __X__MIPS__
00031 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00032 #endif
00033 extern short read_gif_image(char *, short);
00034 extern unsigned char p_red[],p_green[],p_blue[];
00035 extern int colourmap_size,x_size,y_size,gif_iLace;
00036
00037 HINSTANCE hInst = NULL;
00038 HPALETTE hpalCurrent = NULL;
00039 HBITMAP hbmCurrent = NULL;
00040 HDC hdcCurrent = NULL;
00041 RGBQUAD *pRgb = NULL;
00042 LPSTR lpBitmapHeader = NULL;
00043 LPSTR lpBitmapBits = NULL;
00044
00045 #define BOUND(x,min,max) ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
00046 #define SWAP(x,y) ((x)^=(y)^=(x)^=(y))
00047 #define MIN(x,y) (((x) <= (y)) : x ? y)
00048 #define StartWait() hcurSave = SetCursor(LoadCursor(NULL,IDC_WAIT))
00049 #define EndWait() SetCursor(hcurSave)
00050
00051 #define ISDIB(bft) ((bft) == BFT_BITMAP)
00052
00053 #define ALIGNULONG(i) ((i+3)/4*4)
00054
00055 #define WIDTHBYTES(i) ((i+31)/32*4)
00056
00057 static int x4_size,rowcount,rowinc;
00058 static LPSTR pixels;
00059 static POINT ptSize;
00060 static HCURSOR hcurSave;
00061
00062 static void FreeDib(void);
00063 static HPALETTE CreateImagePalette(LPBITMAPINFOHEADER lpbi);
00064 static WORD NumColours(LPBITMAPINFOHEADER lpbi);
00065 static HBITMAP BitmapFromDib(LPSTR lpHeader,LPSTR lpBits,HPALETTE hpal);
00066
00067 static void FreeDib(void){
00068 if (hpalCurrent) DeleteObject(hpalCurrent);
00069 if (hbmCurrent) DeleteObject(hbmCurrent);
00070 if(lpBitmapBits != NULL)X__Free((char *)lpBitmapBits);
00071 if(lpBitmapHeader != NULL)X__Free((char *)lpBitmapHeader);
00072 lpBitmapHeader = NULL;
00073 lpBitmapBits = NULL;
00074 hpalCurrent = NULL;
00075 hbmCurrent = NULL;
00076 pRgb = NULL;
00077 }
00078
00079 #define DibNumColors(bmih) (bmih.biClrUsed == 0 && bmih.biBitCount <= 8 \
00080 ? (int)(1 << (int)bmih.biBitCount) \
00081 : (int)bmih.biClrUsed)
00082
00083 static int dib_view(char *temp){
00084 HDC hdc;
00085 HANDLE hfbm;
00086 BITMAPFILEHEADER bmfh;
00087 DWORD dwRead;
00088 BITMAPINFOHEADER bmih;
00089 LPBITMAPINFOHEADER lpbi;
00090 LPBITMAPINFO lpinfo;
00091 long imagesize,nc;
00092 FreeDib();
00093 hfbm=CreateFile(temp,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,
00094 FILE_ATTRIBUTE_READONLY,(HANDLE)NULL);
00095 ReadFile(hfbm,&bmfh,sizeof(BITMAPFILEHEADER),&dwRead,(LPOVERLAPPED)NULL);
00096 ReadFile(hfbm,&bmih,sizeof(BITMAPINFOHEADER),&dwRead,(LPOVERLAPPED)NULL);
00097 nc=DibNumColors(bmih);
00098 lpBitmapHeader = (LPSTR)X__Malloc((long)sizeof(BITMAPINFOHEADER)+
00099 (nc*sizeof(RGBQUAD)));
00100 if(lpBitmapHeader == NULL)return 0;
00101 lpbi=(LPBITMAPINFOHEADER)lpBitmapHeader;
00102 lpinfo=(LPBITMAPINFO)lpBitmapHeader;
00103 lpbi->biSize=bmih.biSize;
00104 x_size=lpbi->biWidth=bmih.biWidth;
00105 lpbi->biHeight=bmih.biHeight;
00106 lpbi->biPlanes=bmih.biPlanes;
00107 lpbi->biBitCount=bmih.biBitCount;
00108 lpbi->biCompression=bmih.biCompression;
00109 lpbi->biSizeImage=bmih.biSizeImage;
00110 lpbi->biXPelsPerMeter=bmih.biXPelsPerMeter;
00111 lpbi->biYPelsPerMeter=bmih.biYPelsPerMeter;
00112 lpbi->biClrUsed=bmih.biClrUsed;
00113 lpbi->biClrImportant=bmih.biClrImportant;
00114 if(nc > 0)ReadFile(hfbm,lpinfo->bmiColors,(nc*sizeof(RGBQUAD)),
00115 &dwRead,(LPOVERLAPPED)NULL);
00116 hpalCurrent=NULL;
00117
00118 imagesize=bmfh.bfSize-bmfh.bfOffBits;
00119 lpBitmapBits=(LPSTR)X__Malloc(imagesize);
00120 if(lpBitmapBits == NULL){
00121 FreeDib();
00122 return 0;
00123 }
00124 memset(lpBitmapBits,0,imagesize);
00125 pixels=lpBitmapBits;
00126 ReadFile(hfbm,lpBitmapBits,imagesize,&dwRead,(LPOVERLAPPED)NULL);
00127 hdc = CreateCompatibleDC(NULL);
00128
00129 hbmCurrent=CreateDIBitmap(hdc,&bmih,CBM_INIT,lpBitmapBits,
00130 lpinfo,DIB_RGB_COLORS);
00131 DeleteDC(hdc);
00132 return 1;
00133 }
00134
00135 int out_line(unsigned char *linepixels, int linelen){
00136 register long l;
00137 l = (long)(y_size - 1 - rowcount)*(long)(x4_size);
00138 memcpy(pixels + l, linepixels, linelen);
00139 rowcount+=abs(rowinc);
00140 if(rowcount >= y_size){
00141 if (rowinc == -8){rowinc=8; rowcount=4;}
00142 else if(rowinc == 8){rowinc=4; rowcount=2;}
00143 else if(rowinc == 4){rowinc=2; rowcount=1;}
00144 }
00145 return 0;
00146 }
00147
00148 static int gif_view(char *temp){
00149 int i;
00150 long imagesize;
00151 LPBITMAPINFOHEADER lpbi;
00152 FreeDib();
00153 rowcount=0;
00154 rowinc=1;
00155 if(read_gif_image(temp,1) < 0)return 0;
00156 x4_size = ALIGNULONG(x_size);
00157 if(gif_iLace)rowinc = -8;
00158 lpBitmapHeader = (LPSTR)X__Malloc((long)sizeof(BITMAPINFOHEADER)
00159 +256L*sizeof(RGBQUAD));
00160 if(lpBitmapHeader == NULL)return 0;
00161 lpbi=(LPBITMAPINFOHEADER)lpBitmapHeader;
00162 lpbi->biSize=sizeof(BITMAPINFOHEADER);
00163 lpbi->biWidth=(DWORD)x4_size;
00164 lpbi->biHeight=(DWORD)y_size;
00165 lpbi->biPlanes=1;
00166 lpbi->biBitCount=8;
00167 lpbi->biCompression=BI_RGB;
00168 imagesize = lpbi->biSizeImage = (DWORD)x4_size*(DWORD)y_size;
00169 lpbi->biXPelsPerMeter=0;
00170 lpbi->biYPelsPerMeter=0;
00171 lpbi->biClrUsed=256;
00172 lpbi->biClrImportant=256;
00173 pRgb=(RGBQUAD *)((LPSTR)lpbi + lpbi->biSize);
00174 for(i=0;i<256;i++){
00175 pRgb[i].rgbRed = p_red[i] << 2;
00176 pRgb[i].rgbGreen = p_green[i] << 2;
00177 pRgb[i].rgbBlue = p_blue[i] << 2;
00178 }
00179 hpalCurrent=CreateImagePalette(lpbi);
00180 lpBitmapBits=(LPSTR)X__Malloc(imagesize);
00181 if(lpBitmapBits == NULL){
00182 FreeDib();
00183 return 0;
00184 }
00185 memset(lpBitmapBits,0,imagesize);
00186 pixels=lpBitmapBits;
00187 if(read_gif_image(temp,0) < 0){
00188 FreeDib();
00189 return 0;
00190 }
00191 hbmCurrent=BitmapFromDib(lpBitmapHeader,lpBitmapBits,hpalCurrent);
00192 if(hbmCurrent == NULL)return 0;
00193 return 1;
00194 }
00195
00196 static HPALETTE CreateImagePalette(LPBITMAPINFOHEADER lpbi){
00197 LOGPALETTE *pPal;
00198 HPALETTE hpal = NULL;
00199 WORD nNumColors;
00200 BYTE red;
00201 BYTE green;
00202 BYTE blue;
00203 int i;
00204 RGBQUAD *pRgb;
00205 if(lpbi == NULL)return NULL;
00206 if(lpbi->biSize != sizeof(BITMAPINFOHEADER))return NULL;
00207
00208 pRgb = (RGBQUAD *)((LPSTR)lpbi + (WORD)lpbi->biSize);
00209 nNumColors = NumColours(lpbi);
00210 if(nNumColors){
00211 pPal = (LOGPALETTE*)LocalAlloc(LPTR,sizeof(LOGPALETTE) + nNumColors * sizeof(PALETTEENTRY));
00212 if(pPal == NULL)return NULL;
00213 pPal->palNumEntries = nNumColors;
00214 pPal->palVersion = PALVERSION;
00215
00216
00217 for (i = 0; i < nNumColors; i++){
00218 pPal->palPalEntry[i].peRed = pRgb[i].rgbRed;
00219 pPal->palPalEntry[i].peGreen = pRgb[i].rgbGreen;
00220 pPal->palPalEntry[i].peBlue = pRgb[i].rgbBlue;
00221 pPal->palPalEntry[i].peFlags = (BYTE)0;
00222 }
00223 hpal = CreatePalette(pPal);
00224 LocalFree((HANDLE)pPal);
00225 }
00226 else if (lpbi->biBitCount == 24){
00227
00228
00229 nNumColors = MAXPALETTE;
00230 pPal=(LOGPALETTE*)LocalAlloc(LPTR,sizeof(LOGPALETTE) + nNumColors * sizeof(PALETTEENTRY));
00231 if(pPal == NULL)return NULL;
00232 pPal->palNumEntries = nNumColors;
00233 pPal->palVersion = PALVERSION;
00234 red = green = blue = 0;
00235
00236 for (i = 0; i < pPal->palNumEntries; i++){
00237 pPal->palPalEntry[i].peRed = red;
00238 pPal->palPalEntry[i].peGreen = green;
00239 pPal->palPalEntry[i].peBlue = blue;
00240 pPal->palPalEntry[i].peFlags = (BYTE)0;
00241 if (!(red += 32))if (!(green += 32)) blue += 64;
00242 }
00243 hpal = CreatePalette(pPal);
00244 LocalFree((HANDLE)pPal);
00245 }
00246 return hpal;
00247 }
00248
00249 static WORD NumColours(LPBITMAPINFOHEADER lpbi){
00250 WORD bits;
00251 if (lpbi->biClrUsed != 0)return (WORD)lpbi->biClrUsed;
00252 bits = lpbi->biBitCount;
00253 switch (bits){
00254 case 1: return 2;
00255 case 4: return 16;
00256 case 8: return 256;
00257 default: return 0;
00258 }
00259 }
00260
00261 static HBITMAP BitmapFromDib(LPSTR lpHeader,LPSTR lpBits,HPALETTE hpal){
00262 HDC hdc;
00263 HBITMAP hbm;
00264 HPALETTE hpalT;
00265 if (lpHeader == NULL || lpBits == NULL)return NULL;
00266 hdc = CreateCompatibleDC(NULL);
00267
00268 if(hpal != NULL){
00269 hpalT = SelectPalette(hdc,hpal,FALSE);
00270 RealizePalette(hdc);
00271 }
00272 hbm = CreateDIBitmap(hdc,
00273 (LPBITMAPINFOHEADER)lpHeader,
00274 (LONG)CBM_INIT,
00275 lpBits,
00276 (LPBITMAPINFO)lpHeader,
00277 DIB_RGB_COLORS );
00278 if(hpal != NULL)SelectPalette(hdc,hpalT,FALSE);
00279 DeleteDC(hdc);
00280 return hbm;
00281 }
00282
00283 static void tga_display_line(unsigned char *prgb,
00284 long wide, long line,
00285 long upsidedown, long hi){
00286 register long l,x,k;
00287 if(upsidedown)l = 3L*(long)(line)*(long)(x4_size);
00288 else l = 3L*(long)(hi - 1 - line)*(long)(x4_size);
00289 memcpy(pixels + l, prgb, (int)(wide*3));
00290 }
00291
00292 static short R_getvariword(long n, FILE *f, long *vw){
00293 long c;
00294 if((c=(long)getc(f)) == EOF)return 0;
00295 *vw = c; if(n == 1)return 1;
00296 if((c=(long)getc(f)) == EOF)return 0;
00297 *vw |= (c << 8); if(n == 2)return 1;
00298 if((c=(long)getc(f)) == EOF)return 0;
00299 *vw |= (c << 16); if(n == 3)return 1;
00300 if((c=(long)getc(f)) == EOF)return 0;
00301 *vw |= (c << 24);
00302 return 1;
00303 }
00304
00305 static short LoadTGA(char *filename, short info_only){
00306 char c0,c1,c2;
00307 long i,j,k,l,m,n,cmo,cml,xor,yor,wi,hi,iok=0,idsize,cm_type,vw,
00308 image_type,cmes,pixel_size,image_descriptor,n_attr,upsidedown,b_size,
00309 s1,s2,s,pat,wi3;
00310 FILE *t24;
00311 unsigned char *prgb;
00312 prgb=NULL;
00313 if((t24=fopen(filename,"rb")) != NULL){
00314 if(! R_getvariword(1,t24,&idsize))goto CLOSEOUT;
00315 if(! R_getvariword(1,t24,&cm_type))goto CLOSEOUT;
00316 if(! R_getvariword(1,t24,&image_type))goto CLOSEOUT;
00317 if(image_type != 2 && image_type != 10)goto CLOSEOUT;
00318 if(! R_getvariword(2,t24,&cmo))goto CLOSEOUT;
00319 if(! R_getvariword(2,t24,&cml))goto CLOSEOUT;
00320 if(! R_getvariword(1,t24,&cmes))goto CLOSEOUT;
00321 if(! R_getvariword(2,t24,&xor))goto CLOSEOUT;
00322 if(! R_getvariword(2,t24,&yor))goto CLOSEOUT;
00323 if(! R_getvariword(2,t24,&wi))goto CLOSEOUT;
00324 if(! R_getvariword(2,t24,&hi))goto CLOSEOUT;
00325 if(! R_getvariword(1,t24,&pixel_size))goto CLOSEOUT;
00326 if(! R_getvariword(1,t24,&image_descriptor))goto CLOSEOUT;
00327 if(idsize > 0)for(i=0;i<idsize;i++)if(getc(t24) == EOF)goto CLOSEOUT;
00328 if(cm_type == 1 && cml > 0){
00329 for(i=cmo;i<cml;i++)if(! R_getvariword(cmes/8,t24,&j))goto CLOSEOUT;
00330 }
00331 n_attr = image_descriptor & 0xf;
00332 upsidedown = (image_descriptor & 0x20) > 0 ? 0 : 1 ;
00333 if(info_only){
00334 x_size=(int)wi;
00335 y_size=(int)hi;
00336 fclose(t24);
00337 return 1;
00338 }
00339 if((prgb=(unsigned char *)X__Malloc((size_t)wi*3)) == NULL)goto CLOSEOUT;
00340 if((image_descriptor & 0xc0) > 0)goto CLOSEOUT;
00341 b_size=i=wi*hi;
00342 if (pixel_size == 16){n=2;s1=5;s2=10;s=3;pat=0x1f;}
00343 else if(pixel_size == 24){n=3;s1=8;s2=16;s=0;pat=0xff;}
00344 else {n=4;s1=8;s2=16;s=0;pat=0xff;}
00345 wi3=wi*3;
00346 if(image_type == 2){
00347 m=0; k=0; for(i=0;i<hi;i++)for(j=0;j<wi;j++){
00348 if(! R_getvariword(n,t24,&vw))goto CLOSEOUT;
00349 prgb[m ] = (char)( vw & pat) << s;
00350 prgb[m+1] = (char)((vw >> s1) & pat) << s;
00351 prgb[m+2] = (char)((vw >> s2) & pat) << s;
00352 k++; m+=3;
00353 if(m == wi3){
00354 tga_display_line(prgb,wi,i,upsidedown,hi); m=0;
00355 }
00356 }
00357 }
00358 else{
00359 m=0; l=0; k=0; while(k < b_size){
00360 i=getc(t24); if(feof(t24))goto CLOSEOUT;
00361 if(i < 128){
00362 for(j=0;j<i+1;j++){
00363 if(! R_getvariword(n,t24,&vw))goto CLOSEOUT;
00364 prgb[m ] = (char)( vw & pat) << s;
00365 prgb[m+1] = (char)((vw >> s1) & pat) << s;
00366 prgb[m+2] = (char)((vw >> s2) & pat) << s;
00367 k++; m+=3;
00368 if(m == wi3){
00369 tga_display_line(prgb,wi,l,upsidedown,hi); m=0; l++;
00370 }
00371 }
00372 }
00373 else{
00374 if(! R_getvariword(n,t24,&vw))goto CLOSEOUT;
00375 c0 = (char)( vw & pat) << s;
00376 c1 = (char)((vw >> s1) & pat) << s;
00377 c2 = (char)((vw >> s2) & pat) << s;
00378 i -= 128;
00379 for(j=0;j<i+1;j++){
00380 prgb[m ] = c0;
00381 prgb[m+1] = c1;
00382 prgb[m+2] = c2;
00383 k++; m+=3;
00384 if(m == wi3){
00385 tga_display_line(prgb,wi,l,upsidedown,hi); m=0; l++;
00386 }
00387 }
00388 }
00389 }
00390 }
00391 iok=1;
00392 CLOSEOUT:
00393 fclose(t24);
00394 if(prgb != NULL)X__Free((char *)prgb);
00395 }
00396 return (short)iok;
00397 }
00398
00399 static int tga_view(char *temp){
00400 int i;
00401 long imagesize;
00402 LPBITMAPINFOHEADER lpbi;
00403 if(LoadTGA(temp,1) == 0)return 0;
00404 x4_size=ALIGNULONG(x_size);
00405 FreeDib();
00406 lpBitmapHeader = (LPSTR)X__Malloc((long)sizeof(BITMAPINFOHEADER));
00407 if(lpBitmapHeader == NULL)return 0;
00408 lpbi=(LPBITMAPINFOHEADER)lpBitmapHeader;
00409 lpbi->biSize=sizeof(BITMAPINFOHEADER);
00410 lpbi->biWidth=(DWORD)x4_size;
00411 lpbi->biHeight=(DWORD)y_size;
00412 lpbi->biPlanes=1;
00413 lpbi->biBitCount=24;
00414 lpbi->biCompression=BI_RGB;
00415 imagesize = lpbi->biSizeImage = (DWORD)x4_size*(DWORD)y_size*3L;
00416 lpbi->biXPelsPerMeter=0;
00417 lpbi->biYPelsPerMeter=0;
00418 lpbi->biClrUsed=0;
00419 lpbi->biClrImportant=0;
00420 hpalCurrent=CreateImagePalette(lpbi);
00421 lpBitmapBits=(LPSTR)X__Malloc(imagesize);
00422 if(lpBitmapBits == NULL){
00423 FreeDib();
00424 return 0;
00425 }
00426 memset(lpBitmapBits,0,imagesize);
00427 pixels=lpBitmapBits;
00428 if(LoadTGA(temp,0) == 0){
00429 FreeDib();
00430 return 0;
00431 }
00432 hbmCurrent=BitmapFromDib(lpBitmapHeader,lpBitmapBits,hpalCurrent);
00433 if(hbmCurrent == NULL)return 0;
00434 return 1;
00435 }
00436
00437 #if 0
00438
00439 #include "..\render2\flc.h"
00440
00441 static FILE *Bit_File;
00442 static unsigned char *Screen=NULL;
00443
00444 static short RenderFlcBrun(FILE *f);
00445 static short RenderFlcColor(FILE *f, short type);
00446 static short LoadRenderAnimCel(FILE *f, Flc_head *flc, short info_only);
00447
00448 static long nx,ny,nx4;
00449
00450 static long LoadCEL(char *name, short info_only){
00451 long i,cel_type;
00452 struct pic_header aa_cel;
00453 Flc_head flc_cel;
00454 unsigned char cc,*pix;
00455 if((Bit_File=fopen(name,"rb")) == NULL)return 0;
00456 if(fread(&aa_cel,sizeof(struct pic_header),1,Bit_File) != 1)cel_type=0;
00457 else if(aa_cel.type == PIC_MAGIC){
00458 cel_type=1;
00459 nx = x_size = aa_cel.w;
00460 ny = y_size = aa_cel.h;
00461 }
00462 else{
00463 fseek(Bit_File,0,SEEK_SET);
00464 if(fread(&flc_cel,sizeof(Flc_head),1,Bit_File) != 1)cel_type=0;
00465 else if(flc_cel.type == FLCH_MAGIC){
00466 cel_type=2;
00467 nx = x_size = flc_cel.width;
00468 ny = y_size = flc_cel.height;
00469 }
00470 }
00471 nx4=ALIGNULONG(nx);
00472 if(cel_type == 0){fclose(Bit_File); return(0);}
00473 if(cel_type == 2){
00474 if(LoadRenderAnimCel(Bit_File,&flc_cel,info_only) < 0){
00475 fclose(Bit_File);
00476 return(0);
00477 }
00478 }
00479 else{
00480 for(i = 0; i < 256 ; i++) {
00481 fread(&cc,1,1,Bit_File); p_red[i] = cc << 2;
00482 fread(&cc,1,1,Bit_File); p_green[i] = cc << 2;
00483 fread(&cc,1,1,Bit_File); p_blue[i] = cc << 2;
00484 }
00485 if(info_only){
00486 fclose(Bit_File);
00487 return 1;
00488 }
00489 for(i=0;i<ny;i++){
00490 pix=Screen+(ny-1-i)*nx4;
00491 if(fread(pix,1,nx,Bit_File) != nx){
00492 fclose(Bit_File);
00493 return(0);
00494 }
00495 }
00496 }
00497 fclose(Bit_File);
00498 return(1);
00499 }
00500
00501 static short LoadRenderAnimCel(FILE *f,Flc_head *flc, short info_only){
00502 Flc_frame f_frame;
00503 Flc_chunk f_chunk;
00504 long i,j,k;
00505 char c;
00506 unsigned char *p;
00507
00508 fseek(f,flc->oframe1,SEEK_SET);
00509 if(fread(&f_frame,sizeof(Flc_frame),1,f) != 1 ||
00510 f_frame.type != FLCF_MAGIC)return -1;
00511
00512 for(i=0;i<f_frame.chunks;i++){
00513 if(fread(&f_chunk,sizeof(Flc_chunk),1,f) != 1)return -1;
00514
00515 if(f_chunk.type == FLC_COLOR256 || f_chunk.type == FLC_COLOR){
00516 if(RenderFlcColor(f,f_chunk.type) < 0)return -1;
00517 if(info_only)return 0;
00518 }
00519 else if(!info_only && f_chunk.type == FLC_BRUN){
00520 if(RenderFlcBrun(f) < 0)return -1;
00521 }
00522 else if(!info_only && f_chunk.type == FLC_COPY){
00523 for (k=0;k<ny;k++){
00524 p=Screen+(ny-1-k)*nx4;
00525 if(fread(p,1,nx,f) != nx)return -1;
00526 }
00527 }
00528 else{
00529 for(j=0;j<f_chunk.size-6;j++)fread(&c,1,1,f);
00530 }
00531 }
00532 return 0;
00533 }
00534
00535 static short RenderFlcColor(FILE *f, short type){
00536 short i,j,pk,packets,ci=0;
00537 unsigned char skip=0,change,colour;
00538 if(fread(&packets,2,1,f) != 1)return -1;
00539 for (pk=0; pk<packets; pk++ ) {
00540 if(fread(&skip,1,1,f) != 1)return -1;
00541 ci += skip;
00542 if(fread(&change,1,1,f) != 1)return -1;
00543 if (change == 0) change=255;
00544 for (i=0; i<=change; i++) {
00545 if(fread(&colour,1,1,f) != 1)return -1;
00546 if(type == FLC_COLOR)colour = colour << 2;
00547 p_red[ci] = colour;
00548 if(fread(&colour,1,1,f) != 1)return -1;
00549 if(type == FLC_COLOR)colour = colour << 2;
00550 p_green[ci] = colour;
00551 if(fread(&colour,1,1,f) != 1)return -1;
00552 if(type == FLC_COLOR)colour = colour << 2;
00553 p_blue[ci] = colour;
00554 ci++;
00555 }
00556 }
00557 return 0;
00558 }
00559
00560 static short RenderFlcBrun(FILE *f){
00561 char size=0;
00562 unsigned char packet,*p,colour;
00563 short i,line,pk;
00564 for (line=0;line<ny;line++){
00565 p=Screen+(ny-1-line)*nx4;
00566 if(fread(&packet,1,1,f) != 1)return -1;
00567 for(pk=0; pk<nx; pk+=abs(size)){
00568 if(fread(&size,1,1,f) != 1)return -1;
00569 if(size > 0){
00570 if(fread(&colour,1,1,f) != 1)return -1;
00571 for (i=0; i<size; i++) *p++ = colour;
00572 }
00573 else{
00574 for (i = size; i<0; i++){
00575 if(fread(&colour,1,1,f) != 1)return -1;
00576 *p++ = colour;
00577 }
00578 }
00579 }
00580 }
00581 return 0;
00582 }
00583
00584 static int cel_view(char *temp){
00585 int i;
00586 long imagesize;
00587 LPBITMAPINFOHEADER lpbi;
00588 FreeDib();
00589 rowcount=0;
00590 if(LoadCEL(temp,1) < 0){
00591 return 0;
00592 }
00593 x4_size = ALIGNULONG(x_size);
00594 lpBitmapHeader = (LPSTR)X__Malloc((long)sizeof(BITMAPINFOHEADER)
00595 +256L*sizeof(RGBQUAD));
00596 if(lpBitmapHeader == NULL){
00597 return 0;
00598 }
00599 lpbi=(LPBITMAPINFOHEADER)lpBitmapHeader;
00600 lpbi->biSize=sizeof(BITMAPINFOHEADER);
00601 lpbi->biWidth=(DWORD)x4_size;
00602 lpbi->biHeight=(DWORD)y_size;
00603 lpbi->biPlanes=1;
00604 lpbi->biBitCount=8;
00605 lpbi->biCompression=BI_RGB;
00606 imagesize = lpbi->biSizeImage = (DWORD)x4_size*(DWORD)y_size;
00607 lpbi->biXPelsPerMeter=0;
00608 lpbi->biYPelsPerMeter=0;
00609 lpbi->biClrUsed=256;
00610 lpbi->biClrImportant=256;
00611 pRgb=(RGBQUAD *)((LPSTR)lpbi + lpbi->biSize);
00612 for(i=0;i<256;i++){
00613 pRgb[i].rgbRed = p_red[i];
00614 pRgb[i].rgbGreen = p_green[i];
00615 pRgb[i].rgbBlue = p_blue[i];
00616 }
00617 hpalCurrent=CreateImagePalette(lpbi);
00618 lpBitmapBits=(LPSTR)X__Malloc(imagesize);
00619 if(lpBitmapBits == NULL){
00620 FreeDib();
00621 return 0;
00622 }
00623 memset(lpBitmapBits,0,imagesize);
00624 Screen=(unsigned char *)lpBitmapBits;
00625 if(LoadCEL(temp,0) < 0){
00626 FreeDib();
00627 return 0;
00628 }
00629 hbmCurrent=BitmapFromDib(lpBitmapHeader,lpBitmapBits,hpalCurrent);
00630 if(hbmCurrent == NULL)return 0;
00631 return 1;
00632 }
00633
00634 #endif
00635
00636 #if __WATCOMC__
00637 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00638 #else
00639 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00640 #endif
00641 switch (dwReason) {
00642 case DLL_PROCESS_ATTACH: {
00643 #if __X__MIPS__
00644 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00645
00646 #endif
00647 hInst=hDLL;
00648 break;
00649 }
00650 case DLL_PROCESS_DETACH:
00651 #if __X__MIPS__
00652 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00653
00654 #endif
00655 hInst=hDLL;
00656 break;
00657 }
00658 return TRUE;
00659 }
00660
00661 #if __SC__
00662 #pragma startaddress(DllMain)
00663 #endif
00664
00665 static BOOL bPrint=TRUE;
00666 static HWND hdlgCancel=NULL;
00667
00668 LRESULT CALLBACK AbortPrintJob(HWND hwndDlg, UINT message,
00669 WPARAM wParam,LPARAM lParam){
00670 RECT rc;
00671 switch(message){
00672 case WM_INITDIALOG:
00673 GetWindowRect(hwndDlg, &rc);
00674 SetWindowPos(hwndDlg, NULL,
00675 (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
00676 (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2,
00677 0, 0, SWP_NOSIZE | SWP_NOZORDER);
00678 return TRUE;
00679 case WM_COMMAND:
00680 bPrint=FALSE;
00681 return TRUE;
00682 default:
00683 return FALSE;
00684 }
00685 return FALSE;
00686 }
00687
00688 BOOL CALLBACK AbortProc(HDC hdc, int nCode){
00689 MSG msg;
00690 while(PeekMessage((LPMSG)&msg,(HWND)NULL,0,0,PM_REMOVE)){
00691 if(!IsDialogMessage(hdlgCancel,(LPMSG)&msg)){
00692 TranslateMessage((LPMSG)&msg);
00693 DispatchMessage((LPMSG)&msg);
00694 }
00695 }
00696 return bPrint;
00697 }
00698
00699 BOOL _PrintBitmap(HWND parent_window, char *filename){
00700 PRINTDLG pd;
00701 DOCINFO di;
00702 HPALETTE hpalT;
00703 HBITMAP holdBitmap;
00704 RECT rc;
00705 SIZE szMetric;
00706 int result=0,nError,imax,imin;
00707 char temp[256];
00708 memset(&pd,0,sizeof(PRINTDLG));
00709 pd.lStructSize=sizeof(PRINTDLG);
00710 pd.Flags=PD_RETURNDC;
00711 pd.hwndOwner=parent_window;
00712 pd.hDC=(HDC)NULL;
00713 pd.nFromPage=1;
00714 pd.nToPage=1;
00715 pd.nMinPage=0;
00716 pd.nMaxPage=1;
00717 pd.nCopies=1;
00718 pd.hInstance=NULL;
00719 pd.lCustData=0L;
00720 if(!PrintDlg(&pd))return FALSE;
00721 if(pd.hDC == NULL){
00722 MessageBox(parent_window,"Printer cannot draw.","Printing",MB_OK);
00723 return FALSE;
00724 }
00725 if(!(GetDeviceCaps(pd.hDC,RASTERCAPS) & RC_BITBLT)){
00726 DeleteDC(pd.hDC);
00727 MessageBox(parent_window,"Printer cannot display bitmaps.","Printing",MB_OK);
00728 return FALSE;
00729 }
00730 FreeDib();
00731 StartWait();
00732 strcpy(temp,filename);
00733 strupr(temp);
00734 hdcCurrent=pd.hDC;
00735 if (strstr(temp,".GIF"))result=gif_view(temp);
00736
00737 else if(strstr(temp,".TGA"))result=tga_view(temp);
00738 else if(strstr(temp,".BMP"))result=dib_view(temp);
00739 else result=0;
00740 EndWait();
00741 if(result == 1){
00742 HDC hdcMem;
00743 LPBITMAPINFOHEADER lpbi;
00744 float fScaleX,fScaleY;
00745 int xLeft,yTop,cWidthPels,cHeightPels;
00746 bPrint=TRUE;
00747 SetAbortProc(pd.hDC,AbortProc);
00748 hdlgCancel=CreateDialog(hInst,(LPSTR)"AbortDialog",parent_window,
00749 (DLGPROC)AbortPrintJob);
00750 di.cbSize=sizeof(DOCINFO);
00751 di.lpszDocName="Printing Image";
00752 di.lpszOutput=NULL;
00753 if((nError=StartDoc(pd.hDC,&di)) == SP_ERROR)goto Error;
00754 if((nError=StartPage(pd.hDC)) <= 0)goto Error;
00755 lpbi=(LPBITMAPINFOHEADER)lpBitmapHeader;
00756 cWidthPels=GetDeviceCaps(pd.hDC,HORZRES);
00757 cHeightPels=GetDeviceCaps(pd.hDC,VERTRES);
00758 imax=max(lpbi->biWidth,lpbi->biHeight);
00759 imin=min(cWidthPels,cHeightPels);
00760 fScaleX=fScaleY=((float)imin/(float)imax)*0.9;
00761
00762
00763
00764
00765
00766 xLeft=((cWidthPels/2)-((int)(((float)lpbi->biWidth)*fScaleX))/2);
00767 yTop=((cHeightPels/2)-((int)(((float)lpbi->biHeight)*fScaleY))/2);
00768 hdcMem=CreateCompatibleDC(pd.hDC);
00769 if(hdcMem == NULL){
00770 MessageBox(parent_window,"Bad Memory DC","Debug",MB_OK);
00771 goto Error;
00772 }
00773 if(hbmCurrent == NULL){
00774 MessageBox(parent_window,"No bitmap to print","Debug",MB_OK);
00775 DeleteDC(hdcMem);
00776 goto Error;
00777 }
00778 holdBitmap=SelectObject(hdcMem,hbmCurrent);
00779 if(holdBitmap == NULL){
00780 MessageBox(parent_window,"Bad Object Selection","Debug",MB_OK);
00781 DeleteDC(hdcMem);
00782 goto Error;
00783 }
00784
00785 if(hpalCurrent != NULL){
00786 hpalT = SelectPalette(pd.hDC,hpalCurrent,FALSE);
00787 RealizePalette (pd.hDC);
00788 }
00789 StretchBlt(pd.hDC,xLeft,yTop,
00790 (int)((float)lpbi->biWidth*fScaleX),
00791 (int)((float)lpbi->biHeight*fScaleY),
00792 hdcMem,0,0,
00793 lpbi->biWidth,
00794 lpbi->biHeight,
00795 SRCCOPY);
00796 SelectObject(hdcMem,holdBitmap);
00797 DeleteDC(hdcMem);
00798 if(hpalCurrent != NULL)SelectPalette(pd.hDC,hpalT,FALSE);
00799 GetTextExtentPoint(pd.hDC,filename,strlen(filename),&szMetric);
00800 xLeft=((cWidthPels/2)-(szMetric.cx/2));
00801 yTop=szMetric.cy;
00802 TextOut(pd.hDC,xLeft,yTop,filename,strlen(filename));
00803 if((nError=EndPage(pd.hDC)) <= 0)goto Error;
00804 if((nError=EndDoc(pd.hDC)) <= 0)goto Error;
00805 goto NoError;
00806 Error:
00807 MessageBox(parent_window,"Error setting up printer","Printing",MB_OK);
00808 NoError:
00809 DestroyWindow(hdlgCancel);
00810 }
00811 else MessageBox(parent_window,"Could not open image","Printing",MB_OK);
00812 DeleteDC(pd.hDC);
00813 FreeDib();
00814 return TRUE;
00815 }
00816