home *** CD-ROM | disk | FTP | other *** search
- #include "PictureFormatTwin.h"
- #include "PictureFormatManager.h"
- #include <AutoPtr.h>
- #include <Color.h>
- #include <String.hpp>
- #include <safe_new.h>
-
- bool PictureFormatTwin::recursion = false;
-
- PictureFormatTwin::PictureFormatTwin(const String & name)
- : data( 0 ),
- sx( 0 ),
- sy( 0 )
- {
- if( recursion )
- return;
- recursion = true;
- AutoPtr<PictureFormat> cfor = PictureFormatManager::create_format( name );
- AutoPtr<PictureFormat> afor = PictureFormatManager::create_format( name + "_a" );
- recursion = false;
- if( !cfor || !afor )
- return;
- if( cfor->width() != afor->width() || cfor->height() != afor->height() )
- return;
- sx = cfor->width();
- sy = afor->height();
-
- data = new Color[sx*sy];
-
- const Color * cd = cfor->colors();
- const Color * ad = afor->colors();
- Color * curr = data;
- const Color * data_end = curr + sx*sy;
- for( ; curr != data_end; ++curr, ++cd, ++ad )
- {
- *curr = *cd;
- curr->a = ad->r;
- }
- }
-
- PictureFormatTwin::~PictureFormatTwin()
- {
- delete data; data = 0;
- }
-
- int PictureFormatTwin::width()const
- {
- return sx;
- }
-
- int PictureFormatTwin::height()const
- {
- return sy;
- }
-
- const Color * PictureFormatTwin::colors()const
- {
- return data;
- }
-