home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / cd32 / cd32-tools / cdxl-1 / ilbmsupport.c < prev    next >
C/C++ Source or Header  |  1993-08-24  |  6KB  |  256 lines

  1. /**************
  2.  
  3.     ILBMSupport.c
  4.  
  5. ***************/
  6.  
  7. /*
  8.  * COPYRIGHT: Unless otherwise noted, all files are Copyright (c) 1993
  9.  * Commodore-Amiga, Inc.  All rights reserved.
  10.  *
  11.  * DISCLAIMER: This software is provided "as is".  No representations or
  12.  * warranties are made with respect to the accuracy, reliability, performance,
  13.  * currentness, or operation of this software, and all use is at your own risk.
  14.  * Neither commodore nor the authors assume any responsibility or liability
  15.  * whatsoever with respect to your use of this software.
  16.  */
  17.  
  18. // Tab size is 8!
  19.  
  20. #include "iffp/ilbmapp.h"
  21.  
  22. #include "cdxl/cdxlob.h"
  23. #include "cdxl/debugsoff.h"
  24.  
  25. /* // Uncomment to get debug output turned on
  26. #define KPRINTF
  27. #include "cdxl/debugson.h"
  28. */
  29.  
  30.  
  31. #define    ILBMINFO struct ILBMInfo
  32.  
  33. /* ILBM Property chunks to be grabbed
  34.  * List BMHD, CMAP and CAMG first so we can skip them when we write
  35.  * the file back out (they will be written out with separate code)
  36.  */
  37. LONG ilbmprops[] = 
  38. {
  39.     ID_ILBM, ID_BMHD,
  40.     ID_ILBM, ID_CMAP,
  41.     ID_ILBM, ID_CAMG,
  42.     ID_ILBM, ID_CCRT,
  43.     ID_ILBM, ID_AUTH,
  44.     ID_ILBM, ID_Copyright,
  45.     TAG_DONE
  46. };
  47.  
  48. // ILBM Collection chunks (more than one in file) to be gathered
  49. LONG ilbmcollects[] =
  50. {
  51.     ID_ILBM, ID_CRNG,
  52.     TAG_DONE
  53. };
  54.  
  55. // ILBM Chunk to stop on
  56. LONG ilbmstops[] =
  57. {
  58.     ID_ILBM, ID_BODY,
  59.     TAG_DONE
  60. };
  61.  
  62.  
  63. /* queryilbm
  64.  *
  65.  * Passed an initilized ILBMInfo with a not-in-use IFFHandle,
  66.  *   and a filename,
  67.  *   will open an ILBM, fill in ilbm->camg and ilbm->bmhd,
  68.  *   and close the ILBM.
  69.  *
  70.  * This allows you to determine if the ILBM is a size and
  71.  *   type you want to deal with.
  72.  *
  73.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  74.  */
  75.  
  76. // query just wants these chunks
  77. LONG queryprops[] =
  78. {
  79.     ID_ILBM, ID_BMHD,
  80.     ID_ILBM, ID_CAMG,
  81.     TAG_DONE
  82. };
  83.  
  84. // scan can stop when a BODY is reached
  85. LONG querystops[] =
  86. {
  87.     ID_ILBM, ID_BODY,
  88.     TAG_DONE
  89. };
  90.  
  91.  
  92. LONG
  93. queryilbm( ILBMINFO *ilbm, UBYTE *filename )
  94. {
  95.     LONG error = 0L;
  96.     BitMapHeader *bmhd;
  97.  
  98.     if ( !ilbm->ParseInfo.iff )
  99.     return(CLIENT_ERROR);
  100.  
  101.     if ( !(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)) ) {
  102.     D(PRINTF("queryilbm: openifile successful\n"));
  103.  
  104.     error = parseifile((struct ParseInfo *)ilbm,
  105.         ID_FORM, ID_ILBM,
  106.         ilbm->ParseInfo.propchks,
  107.         ilbm->ParseInfo.collectchks,
  108.         ilbm->ParseInfo.stopchks);
  109.  
  110.     D(PRINTF("queryilbm: after parseifile, error = %ld\n",error));
  111.  
  112.     if ( (!error) || (error == IFFERR_EOC) || (error == IFFERR_EOF) ) {
  113.         if ( contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM) ) {
  114.  
  115.         if(bmhd = (BitMapHeader*) findpropdata(ilbm->ParseInfo.iff,ID_ILBM,ID_BMHD)) {
  116.             *(&ilbm->Bmhd) = *bmhd;
  117.             ilbm->camg = getcamg(ilbm);
  118.         } else {
  119.             error = NOFILE;
  120.         }
  121.         } else {
  122.         message(SI(MSG_ILBM_NOILBM));
  123.         error = NOFILE;
  124.         }
  125.     }
  126.     closeifile( (struct ParseInfo *)ilbm );
  127.     }
  128.  
  129.     return(error);
  130.  
  131. } // queryilbm()
  132.  
  133.  
  134. DoQuery( UBYTE * filename, DISP_DEF * disp_def )
  135. {
  136.     ILBMINFO    * ilbm;
  137.     LONG      error = FALSE;
  138.  
  139.  
  140.     if (ilbm = (ILBMINFO *)AllocMem(sizeof(ILBMINFO),MEMF_PUBLIC|MEMF_CLEAR)) {
  141.  
  142.     ilbm->ParseInfo.propchks    = ilbmprops;
  143.     ilbm->ParseInfo.collectchks    = ilbmcollects;
  144.     ilbm->ParseInfo.stopchks    = ilbmstops;
  145.  
  146.     if( ilbm->ParseInfo.iff = AllocIFF() ) {
  147.         if( !(error = queryilbm(ilbm,filename))) {
  148.  
  149.         D(PRINTF("DoQuery: after query, this ILBM is %ld x %ld x %ld, modeid=$%lx\n",
  150.         ilbm->Bmhd.w, ilbm->Bmhd.h, ilbm->Bmhd.nPlanes, ilbm->camg);)
  151.  
  152.         disp_def->Width = disp_def->NominalWidth = MAX(ilbm->Bmhd.pageWidth, ilbm->Bmhd.w);
  153.         disp_def->Height = disp_def->NominalHeight = MAX(ilbm->Bmhd.pageHeight,ilbm->Bmhd.h);
  154.         disp_def->Depth = MIN(ilbm->Bmhd.nPlanes,MAXAMDEPTH);
  155.  
  156.         if ( !(disp_def->Flags & DISP_XLMODEID) )
  157.             disp_def->ModeID = ilbm->camg;
  158.         }
  159.         FreeIFF(ilbm->ParseInfo.iff);
  160.     }
  161.  
  162.     FreeMem( ilbm, sizeof(ILBMINFO) );
  163.     }
  164.  
  165.     return( !error );
  166.  
  167. } // DoQuery()
  168.  
  169.  
  170. DoILBM( UBYTE * filename, DISP_DEF * disp_def )
  171. {
  172.     ILBMINFO        * ilbm;
  173.     BitMapHeader    * bmhd;
  174.     LONG          error = FALSE;
  175.  
  176.     D(PRINTF("DoILBM 1 bm[0]= 0x%lx, bm[1]= 0x%lx\n",disp_def->bm[0],disp_def->bm[1]);)
  177.  
  178.     if (ilbm = (ILBMINFO *)AllocMem(sizeof(ILBMINFO),MEMF_CLEAR)) {
  179.  
  180.     D(PRINTF("DoILBM 2\n");)
  181.  
  182.     ilbm->vp = disp_def->vp;
  183.     ilbm->ParseInfo.propchks    = ilbmprops;
  184.     ilbm->ParseInfo.collectchks = ilbmcollects;
  185.     ilbm->ParseInfo.stopchks    = ilbmstops;
  186.  
  187.     if( ilbm->ParseInfo.iff = AllocIFF() ) {
  188.  
  189.         D(PRINTF("DoILBM 3\n");)
  190.  
  191.         if ( !(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)) ) {
  192.  
  193.         D(PRINTF("DoILBM 4\n");)
  194.  
  195.         error = parseifile((struct ParseInfo *)ilbm,
  196.             ID_FORM, ID_ILBM,
  197.             ilbm->ParseInfo.propchks,
  198.             ilbm->ParseInfo.collectchks,
  199.             ilbm->ParseInfo.stopchks);
  200.  
  201.         if ( (!error) || (error == IFFERR_EOC) || (error == IFFERR_EOF) ) {
  202.  
  203.             D(PRINTF("DoILBM 5\n");)
  204.  
  205.             if ( contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM) ) {
  206.  
  207.             D(PRINTF("DoILBM 6\n");)
  208.  
  209.             if(bmhd = (BitMapHeader*) findpropdata(ilbm->ParseInfo.iff,ID_ILBM,ID_BMHD)) {
  210.                 D(PRINTF("DoILBM 7\n");)
  211.  
  212.                 *(&ilbm->Bmhd) = *bmhd;
  213.                 ilbm->camg = getcamg(ilbm);
  214.                 error = loadbody(ilbm->ParseInfo.iff, disp_def->bm[0], &ilbm->Bmhd);
  215.             } else  {
  216.                 error = NOFILE;
  217.             }
  218.  
  219.             D(PRINTF("DoILBM 8 error= %ld\n",error);)
  220.  
  221.             if(!error) {
  222.                 D(PRINTF("DoILBM 9\n");)
  223.  
  224.                 if( !(disp_def->Flags & DISP_XLPALETTE) && !getcolors(ilbm) ) {
  225.                 D(PRINTF("DoILBM A\n");)
  226.  
  227.                 setcolors(ilbm,disp_def->vp);
  228.                 freecolors(ilbm);
  229.                 }
  230.  
  231.                 if ( disp_def->bm[0] && disp_def->bm[1] ) {
  232.                 BltBitMap( disp_def->bm[0],0,0,disp_def->bm[1],
  233.                  0,0,disp_def->Width,disp_def->Height,0xC0,0xFF,NULL);
  234.                 }
  235.  
  236.             }
  237.  
  238.             } else {
  239.             message(SI(MSG_ILBM_NOILBM));
  240.             error = NOFILE;
  241.             }
  242.             }
  243.             closeifile( (struct ParseInfo *)ilbm );
  244.         }
  245.  
  246.         FreeIFF(ilbm->ParseInfo.iff);
  247.     }
  248.  
  249.     FreeMem( ilbm, sizeof(ILBMINFO) );
  250.     }
  251.  
  252.     return( error );
  253.  
  254. } // DoILBM()
  255.  
  256.