home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / ImageLib / Image_lib / lib_source / ChunkyToHAM.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-02  |  3.6 KB  |  158 lines

  1. /* ChunkyToHAM.c © Paweî Marciniak <pmarciniak@lodz.home.pl>*/
  2. #include <exec/execbase.h>
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <graphics/rastport.h>
  6. #include <graphics/gfxbase.h>
  7. #include <graphics/view.h>
  8. #include <intuition/screens.h>
  9. #include <utility/tagitem.h>
  10. #include <proto/exec.h>
  11. #include <proto/graphics.h>
  12. #include <proto/utility.h>
  13.  
  14. #include "/include/libraries/image.h"
  15. #include "chunkytobm.h"
  16.  
  17. void RGBtoHAM( UBYTE *, UBYTE *, ULONG, ULONG, UBYTE );
  18.  
  19. extern struct NewBitMap *MyAllocBitMap( UWORD, UWORD, BYTE );
  20.  
  21. /* ChunkyToHAMA() (c) 1997 Paweî Marciniak
  22.   Modify date  |  Version  |  Comment
  23. ---------------+-----------+------------------------------
  24. 11-05-99 18:10 |  0.1      | Not working yet
  25. 23-05-99 18:52 |  1.0      | NOW! working
  26. 27-05-99 18:37 |  1.01     | BUG in Alloc rgbbuf2
  27. */
  28. struct BitMap * __saveds __asm ChunkyToHAMA( register __a0 struct ChunkyImg *CI_reg, register __a1 struct TagItem *Tags  )
  29. {
  30.   struct NewBitMap *NBM;
  31.   struct ChunkyImg *CI = CI_reg;
  32.   ULONG Error, n, i, csize=CI->ci_Width*CI->ci_Height;
  33.   UBYTE *rgbbuf, *rgbbuf2, *ptr;
  34.   UBYTE *chunkyPtr, *PalettePtr;
  35.   UBYTE mode=MODE_HAM6;
  36.   UBYTE paltab[3][256];
  37.  
  38.   struct RastPort temprp, *ChunkyRPort;
  39.   struct TagItem *ti, *TagsTmp = Tags;
  40.  
  41. /* Tagi */
  42.   while ( ti = NextTagItem( &TagsTmp ) )
  43.   {
  44.     switch ( ti->ti_Tag )
  45.     {
  46.       case CTBH_HamMode:
  47.         mode = ti->ti_Data;
  48.       break;
  49.  
  50.       default:
  51.       break;
  52.     }
  53.   }
  54.  
  55. /* sprawdzam iloôê kolorów jeôli > 256 wyjôcie */
  56.   if(CI->ci_NumColors > 256)
  57.   {
  58.     Error=1000;
  59.     return( 0 );
  60.   }
  61.  
  62.  
  63.  
  64.   if(!(ChunkyRPort=AllocVec( sizeof(struct RastPort),MEMF_ANY|MEMF_CLEAR )))
  65.   {
  66.     Error=1002;
  67.     return( 0 );
  68.   }
  69.  
  70.   InitRastPort( ChunkyRPort );
  71.   
  72.   PalettePtr = CI->ci_Palette;
  73.   chunkyPtr = CI->ci_ChunkyData;
  74.  
  75.   if(!(rgbbuf=AllocVec( csize*3, MEMF_ANY|MEMF_CLEAR )))
  76.   {
  77.     FreeVec( ChunkyRPort );
  78.     Error=1002;
  79.     return( 0 );
  80.   }
  81.  
  82.   if(!(rgbbuf2=AllocVec( csize, MEMF_ANY|MEMF_CLEAR )))
  83.   {
  84.     FreeVec( ChunkyRPort );
  85.     FreeVec( rgbbuf );
  86.     Error=1002;
  87.     return( 0 );
  88.   }
  89.  
  90.   for( i=0; i<CI->ci_NumColors; i++ )
  91.   {
  92.     paltab[0][i]=*PalettePtr;
  93.     PalettePtr++;
  94.     paltab[1][i]=*PalettePtr;
  95.     PalettePtr++;
  96.     paltab[2][i]=*PalettePtr;
  97.     PalettePtr++;
  98.   }
  99.  
  100.   ptr=rgbbuf;
  101. /* Konwersja chunky z paletâ na RGB */
  102.   for( i=0; i<csize; i++ )
  103.   {
  104.     *ptr=paltab[0][*chunkyPtr];
  105.     ptr++;
  106.     *ptr=paltab[1][*chunkyPtr];
  107.     ptr++;
  108.     *ptr=paltab[2][*chunkyPtr];
  109.     ptr++;
  110.     chunkyPtr++;
  111.   }
  112.  
  113.   RGBtoHAM( rgbbuf, rgbbuf2, CI->ci_Width, CI->ci_Height, mode );
  114.  
  115.   FreeVec( rgbbuf );
  116.  
  117. /* Iniciacja temprp */
  118.   InitRastPort( &temprp );
  119.   if(!(temprp.BitMap = AllocBitMap( CI->ci_Width, 1,
  120.                                     8, BMF_CLEAR, 0 )))
  121.   {
  122.     FreeVec( ChunkyRPort );
  123.     FreeVec( rgbbuf2 );
  124.     Error=1003;
  125.     return( 0 );
  126.   }
  127.  
  128.   if(!( NBM = (struct NewBitMap*)MyAllocBitMap( CI->ci_Width,
  129.                                                 CI->ci_Height,
  130.                                                 8)))
  131.   {
  132.     FreeVec( ChunkyRPort );
  133.     FreeBitMap( temprp.BitMap );
  134.     FreeVec( rgbbuf2 );
  135.     Error=1002;
  136.     return( 0 );
  137.   }
  138.   NBM->Width = CI->ci_Width;
  139.   NBM->Height = CI->ci_Height;
  140.   NBM->NumColors = 0;
  141.   ChunkyRPort->BitMap = (struct BitMap *)NBM;
  142.  
  143.   chunkyPtr = rgbbuf2;
  144.  
  145. /* konwersja chunky na bitmapë */
  146.   for( n = 0; n < CI->ci_Height; n++ )
  147.   {
  148.     chunkyPtr+=CI->ci_Width;
  149.     WritePixelLine8( ChunkyRPort, 0, n, CI->ci_Width, chunkyPtr, &temprp );
  150.   }
  151.  
  152.     FreeVec( ChunkyRPort );
  153.     FreeBitMap( temprp.BitMap );
  154.     FreeVec( rgbbuf2 );
  155.   return( (struct BitMap *)NBM );
  156. }
  157. /***********************************************************************/
  158.