home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 61.dms / 61.adf / source.files / ilbm2raw.c < prev    next >
C/C++ Source or Header  |  1986-03-21  |  4KB  |  140 lines

  1. /*--------------------------------------------------------------*/
  2. /* ilbm2raw.c                            */    
  3. /*             2/4/86                    */
  4. /* Reads in ILBM, outputs raw format, which is            */
  5. /* just the planes of bitmap data followed by the color map    */
  6. /*                                                              */
  7. /* By Jerry Morrison and Steve Shaw, Electronic Arts.           */
  8. /* This software is in the public domain.                       */
  9. /*                                                              */
  10. /* This version for the Commodore-Amiga computer.               */
  11. /*                                                              */
  12. /*    Callable from CLI only                    */
  13. /*--------------------------------------------------------------*/
  14.  
  15. #include "iff/intuall.h"
  16. #include "libraries/dos.h"
  17. #include "libraries/dosextens.h"
  18. #include "iff/ilbm.h"
  19. #include "iff/readpict.h"
  20. #include "iff/remalloc.h"
  21.  
  22. #undef NULL
  23. #include "lattice/stdio.h"
  24. /*----------------------------------------------------------------------*/
  25. /*    Iff error messages                        */
  26. /*----------------------------------------------------------------------*/
  27.  
  28. char MsgOkay[] = { "----- (IFF_OKAY) A good IFF file." };
  29. char MsgEndMark[] = {"----- (END_MARK) How did you get this message??" };
  30. char MsgDone[] = { "----- (IFF_DONE) How did you get this message??" };
  31. char MsgDos[] = { "----- (DOS_ERROR) The DOS gave back an error." };
  32. char MsgNot[] = { "----- (NOT_IFF) not an IFF file." };
  33. char MsgNoFile[] = { "----- (NO_FILE) no such file found." };
  34. char MsgClientError[] = {"----- (CLIENT_ERROR) IFF Checker bug."};
  35. char MsgForm[] = { "----- (BAD_FORM) How did you get this message??" };
  36. char MsgShort[] = { "----- (SHORT_CHUNK) How did you get this message??" };
  37. char MsgBad[] = { "----- (BAD_IFF) a mangled IFF file." };
  38.  
  39. /* MUST GET THESE IN RIGHT ORDER!!*/
  40. char *IFFPMessages[-LAST_ERROR+1] = {
  41.     /*IFF_OKAY*/  MsgOkay,
  42.     /*END_MARK*/  MsgEndMark,
  43.     /*IFF_DONE*/  MsgDone,
  44.     /*DOS_ERROR*/ MsgDos,
  45.     /*NOT_IFF*/   MsgNot,
  46.     /*NO_FILE*/   MsgNoFile,
  47.     /*CLIENT_ERROR*/ MsgClientError,
  48.     /*BAD_FORM*/  MsgForm,
  49.     /*SHORT_CHUNK*/  MsgShort,
  50.     /*BAD_IFF*/   MsgBad
  51.     };
  52.  
  53. LONG GfxBase;
  54.  
  55. /*--------------------------------------------------------------*/
  56.  
  57. SaveBitMap(name,bm,cols)
  58.     UBYTE *name;    
  59.     struct BitMap *bm;
  60.     SHORT *cols;
  61.     {
  62.     SHORT i;
  63.     LONG nb,plsize;
  64.     LONG file = Open( name, MODE_NEWFILE);
  65.     if( file == 0 )  {
  66.     printf(" couldn't open %s \n",name);
  67.     return (-1);    /* couldnt open a load-file */    
  68.     }
  69.     plsize = bm->BytesPerRow*bm->Rows;
  70.     for (i=0; i<bm->Depth; i++) {
  71.     nb =  Write(file, bm->Planes[i], plsize);
  72.     if (nb<plsize) break;
  73.     }
  74.     Write(file, cols, (1<<bm->Depth)*2);    /* save color map */
  75.     Close(file);
  76.     return(0);
  77.     }
  78.  
  79. struct BitMap bitmap = {0};
  80.  
  81. char depthString[] = "0";    /* Replaced with desired digit below.*/
  82.  
  83. ILBMFrame ilbmFrame;    /* Top level "client frame".*/
  84.  
  85. /** main() ******************************************************************/
  86.  
  87. UBYTE defSwitch[] = "b";
  88.  
  89. void main(argc, argv)  int argc;  char **argv;  {
  90.     LONG iffp, file;
  91.     UBYTE fname[40];
  92.     GfxBase = (LONG)OpenLibrary("graphics.library",0);
  93.     if (GfxBase==NULL) exit(0);
  94.     
  95.     if (argc) {
  96.     /* Invoked via CLI.  Make a lock for current directory. */
  97.     if (argc < 2) {
  98.         printf("Usage from CLI: 'ilbm2raw filename '\n");
  99.         }
  100.     else {
  101.         
  102.         file = Open(argv[1], MODE_OLDFILE);
  103.         
  104.         if (file) {
  105.         iffp = ReadPicture(file, &bitmap, &ilbmFrame, ChipAlloc);
  106.         Close(file);
  107.         if (iffp != IFF_DONE) {
  108.             printf(" Couldn't read file %s \n", argv[1]);
  109.             printf("%s\n",IFFPMessages[-iffp]);
  110.             }
  111.         else {
  112.             
  113.             strcpy(fname,argv[1]);
  114.  
  115.             if (ilbmFrame.bmHdr.pageWidth > 320) {
  116.             if (ilbmFrame.bmHdr.pageHeight > 200)
  117.                  strcat(fname, ".hi");
  118.             else strcat(fname, ".me");
  119.             }
  120.             else     strcat(fname, ".lo");
  121.  
  122.             depthString[0] = '0' + bitmap.Depth;
  123.             strcat(fname, depthString);
  124.  
  125.             printf(" Creating file %s \n", fname);
  126.             SaveBitMap(fname, &bitmap, ilbmFrame.colorMap);
  127.             }
  128.         }
  129.         else printf(" Couldn't open file: %s. \n", argv[1]);
  130.  
  131.         if (bitmap.Planes[0])  RemFree(bitmap.Planes[0]);
  132.  
  133.         printf("\n");
  134.         }
  135.     }
  136.     CloseLibrary(GfxBase);
  137.     exit(0);
  138.     }
  139.  
  140.