| 608 | } |
| 609 | |
| 610 | void TexturePacker::save( const std::string& Filepath, const Image::SaveType& Format, |
| 611 | const bool& KeepExtensions ) { |
| 612 | if ( !mPacked ) |
| 613 | packTextures(); |
| 614 | |
| 615 | if ( !mTextures.size() ) |
| 616 | return; |
| 617 | |
| 618 | mFilepath = Filepath; |
| 619 | mKeepExtensions = KeepExtensions; |
| 620 | |
| 621 | Image Img( (Uint32)mWidth, (Uint32)mHeight, getAtlasNumChannels() ); |
| 622 | |
| 623 | Img.fillWithColor( Color( 0, 0, 0, 0 ) ); |
| 624 | |
| 625 | TexturePackerTex* t = NULL; |
| 626 | std::vector<TexturePackerTex*>::iterator it; |
| 627 | |
| 628 | for ( it = mTextures.begin(); it != mTextures.end(); ++it ) { |
| 629 | t = ( *it ); |
| 630 | |
| 631 | if ( t->placed() ) { |
| 632 | Uint8* data; |
| 633 | |
| 634 | if ( NULL == t->getImage() ) { |
| 635 | Image imageLoaded( t->name() ); |
| 636 | |
| 637 | if ( NULL != imageLoaded.getPixelsPtr() && |
| 638 | t->width() == (int)imageLoaded.getWidth() && |
| 639 | t->height() == (int)imageLoaded.getHeight() ) { |
| 640 | if ( t->flipped() ) |
| 641 | imageLoaded.flip(); |
| 642 | |
| 643 | Img.copyImage( &imageLoaded, t->x(), t->y() ); |
| 644 | |
| 645 | mPlacedCount++; |
| 646 | } |
| 647 | } else { |
| 648 | data = t->getImage()->getPixels(); |
| 649 | |
| 650 | if ( NULL != data ) { |
| 651 | if ( t->flipped() ) |
| 652 | t->getImage()->flip(); |
| 653 | |
| 654 | Img.copyImage( t->getImage(), t->x(), t->y() ); |
| 655 | |
| 656 | mPlacedCount++; |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | mFormat = Format; |
| 663 | |
| 664 | Img.saveToFile( Filepath, Format ); |
| 665 | |
| 666 | childSave( Format ); |
| 667 | |