home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2002 May / Game.EXE_05_2002.iso / Alawar / Lib / Format / PictureFormatTwin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-03  |  1.2 KB  |  60 lines

  1. #include "PictureFormatTwin.h"
  2. #include "PictureFormatManager.h"
  3. #include <AutoPtr.h>
  4. #include <Color.h>
  5. #include <String.hpp>
  6. #include <safe_new.h>
  7.  
  8. bool PictureFormatTwin::recursion = false;
  9.  
  10. PictureFormatTwin::PictureFormatTwin(const String & name)
  11. :    data( 0 ),
  12.     sx( 0 ),
  13.     sy( 0 )
  14. {
  15.     if( recursion )
  16.         return;
  17.     recursion = true;
  18.     AutoPtr<PictureFormat> cfor = PictureFormatManager::create_format( name );
  19.     AutoPtr<PictureFormat> afor = PictureFormatManager::create_format( name + "_a" );
  20.     recursion = false;
  21.     if( !cfor || !afor )
  22.         return;
  23.     if( cfor->width() != afor->width() || cfor->height() != afor->height() )
  24.         return;
  25.     sx = cfor->width();
  26.     sy = afor->height();
  27.  
  28.     data = new Color[sx*sy];
  29.  
  30.     const Color * cd = cfor->colors();
  31.     const Color * ad = afor->colors();
  32.     Color * curr = data;
  33.     const Color * data_end = curr + sx*sy;
  34.     for( ; curr != data_end; ++curr, ++cd, ++ad )
  35.     {
  36.         *curr = *cd;
  37.         curr->a = ad->r;
  38.     }
  39. }
  40.  
  41. PictureFormatTwin::~PictureFormatTwin()
  42. {
  43.     delete data; data = 0;
  44. }
  45.  
  46. int PictureFormatTwin::width()const
  47. {
  48.     return sx;
  49. }
  50.  
  51. int PictureFormatTwin::height()const
  52. {
  53.     return sy;
  54. }
  55.  
  56. const Color * PictureFormatTwin::colors()const
  57. {
  58.     return data;
  59. }
  60.