TIF_MAP.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 - 2007 OpenFX Development Team
00004 
00005 -- */
00006 
00007 /*  TIF_MAP.C  */
00008 
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 
00012 #include <windows.h>
00013 
00014 int x_size, y_size;
00015 unsigned char *R,*G,*B;
00016 
00017 #define FAIL 0
00018 #define OK   1
00019 
00020 typedef struct SCREENBUFFER {
00021  unsigned char R,G,B,A;
00022 } fullscreenbuffer;
00023 
00024 
00025 extern long ReadTIF(char *filename, short info_only);
00026 
00027 static HINSTANCE hThisInstance;
00028 static void OneTiffFrame(char *outfile, fullscreenbuffer *FullScreenBuffer,
00029                   long ResolutionX, long ResolutionY);
00030 
00031 
00032 #if __WATCOMC__
00033 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00034 #else
00035 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00036 #endif
00037   switch (dwReason) {
00038     case DLL_PROCESS_ATTACH: {
00039       hThisInstance=hDLL;
00040       break;
00041     }
00042     case DLL_PROCESS_DETACH:
00043       break;
00044   }
00045   return TRUE;
00046 }
00047 
00048 void tif_display_line(unsigned char *pbgr, long line){
00049  register long i;
00050  unsigned char *r,*g,*b;
00051  r=(R+x_size*line);
00052  g=(G+x_size*line);
00053  b=(B+x_size*line);
00054  for(i=0;i<x_size;i++){
00055   *r++ = *pbgr++;
00056   *g++ = *pbgr++;
00057   *b++ = *pbgr++;
00058   pbgr++;
00059  }
00060 }
00061 
00062 BOOL _GetExternalImageSize
00063  (char *filename,
00064   long *x,
00065   long *y,
00066   unsigned char *source_buffer){
00067  if(ReadTIF(filename,1) == 0)return FALSE;
00068  *x = x_size;
00069  *y = y_size;
00070  return TRUE;
00071 }
00072 
00073 BOOL _GetExternalImage
00074  (char *filename,
00075   long x, long y,
00076   unsigned char *Red,
00077   unsigned char *Green,
00078   unsigned char *Blue,
00079   unsigned char *source_buffer){
00080  x_size=x;
00081  y_size=y;
00082  R=Red;
00083  G=Green;
00084  B=Blue;
00085  if(ReadTIF(filename,0) == 0)return FALSE;
00086  return TRUE;
00087 }
00088 
00089 BOOL _PutExternalImage
00090  (char *filename,
00091   long x, long y,
00092   long quality,
00093   fullscreenbuffer *image){
00094 OneTiffFrame(filename,image,x,y);
00095  return TRUE;
00096 }
00097 
00098 
00099 #ifdef _SUNSTYLE
00100 static short R_putlong(lng,f) long lng; FILE *f; {
00101 #else
00102 static short R_putlong(long lng, FILE *f){
00103 #endif
00104  if(fputc((char)(lng      ),f) == EOF)return FAIL; /* must be INTEL ordering */
00105  if(fputc((char)(lng >>  8),f) == EOF)return FAIL;
00106  if(fputc((char)(lng >> 16),f) == EOF)return FAIL;
00107  if(fputc((char)(lng >> 24),f) == EOF)return FAIL;
00108  return OK;
00109 }
00110 
00111 #ifdef _SUNSTYLE
00112 static short R_putshort(sht,f) short sht; FILE *f;{
00113 #else
00114 static short R_putshort(short sht, FILE *f){
00115 #endif
00116  if(fputc((char)(sht      ),f) == EOF)return FAIL; /* must be INTEL ordering */
00117  if(fputc((char)(sht >>  8),f) == EOF)return FAIL;
00118  return OK;
00119 }
00120 
00121 #ifdef _SUNSTYLE
00122 static short R_putbyte(c,f) char c; FILE *f;{
00123 #else
00124 static short R_putbyte(char c ,FILE *f){
00125 #endif
00126  if(fputc((char)(c),f) == EOF)return FAIL;
00127  return OK;
00128 }
00129 
00130 
00131 static void OneTiffFrame(char *outfile, fullscreenbuffer *FullScreenBuffer,
00132                   long ResolutionX, long ResolutionY){
00133  fullscreenbuffer *f=NULL;
00134  FILE *t24;
00135  short iok=0;
00136  long x,y,i,j,p,nh,adr0,adr1,adr2;
00137 //   sprintf(outputfile,"%s.TIF",out_root);
00138  if(FullScreenBuffer == NULL)return;
00139  if(FullScreenBuffer != NULL){
00140    if((t24=fopen(outfile,"wb")) != NULL){
00141      x=ResolutionX; y=ResolutionY; f=FullScreenBuffer;
00142      R_putshort(0x4949,t24);
00143      R_putshort(0x002a,t24);
00144      R_putlong(8,t24); /* first IFD pointer imediate */
00145      nh=13; R_putshort((short)nh,t24); /* entry count */
00146      adr1=8+2+nh*12+4+6;  /* should = p */
00147      adr2=adr1+y*sizeof(long);
00148      adr0=adr1-6;
00149      R_putshort(0x00ff,t24); R_putshort(3,t24); R_putshort(1,t24);  /* subf */
00150                              R_putshort(0,t24); R_putshort(1,t24);
00151                              R_putshort(0,t24);
00152      R_putshort(0x0100,t24); R_putshort(4,t24); R_putlong(1,t24);  /* width */
00153                              R_putlong(x,t24);
00154      R_putshort(0x0101,t24); R_putshort(4,t24); R_putlong(1,t24);  /* lenght */
00155                              R_putlong(y,t24);
00156      R_putshort(0x0102,t24); R_putshort(3,t24); R_putshort(3,t24);  /* bps */
00157                              R_putshort(0,t24); R_putlong(adr0,t24);
00158      R_putshort(0x0103,t24); R_putshort(3,t24); R_putshort(1,t24);
00159                              R_putshort(0,t24); R_putshort(1,t24);
00160                              R_putshort(0,t24);/* comp */
00161      R_putshort(0x0106,t24); R_putshort(3,t24); R_putshort(1,t24);
00162                              R_putshort(0,t24); R_putshort(2,t24);
00163                              R_putshort(0,t24); /* photo */
00164      R_putshort(0x0111,t24); R_putshort(4,t24); R_putlong(y,t24);  /* S-off */
00165                              R_putlong(adr1,t24);
00166      R_putshort(0x0115,t24); R_putshort(3,t24); R_putshort(1,t24);
00167                              R_putshort(0,t24); R_putshort(3,t24);
00168                              R_putshort(0,t24); /* spp  */
00169      R_putshort(0x0116,t24); R_putshort(4,t24); R_putlong(1,t24);  /* Rpstr */
00170                              R_putlong(1,t24);
00171      R_putshort(0x0117,t24); R_putshort(4,t24); R_putlong(y,t24);  /* str-c*/
00172                              R_putlong(adr2,t24);
00173      R_putshort(0x0118,t24); R_putshort(3,t24); R_putshort(1,t24);
00174                              R_putshort(0,t24); R_putshort(0,t24);
00175                              R_putshort(0,t24); /* spp  */
00176      R_putshort(0x0119,t24); R_putshort(3,t24); R_putshort(1,t24);
00177                              R_putshort(0,t24); R_putshort(255,t24);
00178                              R_putshort(0,t24); /* spp  */
00179      R_putshort(0x011c,t24); R_putshort(3,t24); R_putshort(1,t24);
00180                              R_putshort(0,t24); R_putshort(1,t24);
00181                              R_putshort(0,t24); /* spp  */
00182      R_putlong(0,t24);
00183      R_putshort(8,t24); R_putshort(8,t24); R_putshort(8,t24); /*b/sample */
00184      p=ftell(t24);
00185      for(i=0;i<y;i++)R_putlong(p+2*sizeof(long)*y+i*x*3,t24);
00186      for(i=0;i<y;i++)R_putlong(x*3,t24);
00187      for (i=0;i<y;i++){
00188        for (j=0;j<x;j++){
00189          if(R_putbyte(f->R,t24) == FAIL)goto FATALWRITE;
00190          if(R_putbyte(f->G,t24) == FAIL)goto FATALWRITE;
00191          if(R_putbyte(f->B,t24) == FAIL)goto FATALWRITE;
00192          f++;
00193        }
00194      }
00195      iok=1;
00196      FATALWRITE:
00197      fclose(t24);
00198    }
00199  }
00200 }

Generated on Sun Apr 27 14:20:13 2014 for OpenFX by  doxygen 1.5.6