2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "image-atlas-manager.h"
22 #include <dali/public-api/images/resource-image.h>
35 const uint32_t DEFAULT_ATLAS_SIZE( 1024u ); // this size can fit 8 by 8 images of average size 128*128
36 const uint32_t MAX_ITEM_SIZE( 512u );
37 const uint32_t MAX_ITEM_AREA( MAX_ITEM_SIZE*MAX_ITEM_SIZE );
40 ImageAtlasManager::ImageAtlasManager()
41 : mBrokenImageUrl( "" )
45 ImageAtlasManager::~ImageAtlasManager()
49 TextureSet ImageAtlasManager::Add( Vector4& textureRect,
50 const std::string& url,
52 FittingMode::Type fittingMode,
53 bool orientationCorrection )
55 ImageDimensions dimensions = size;
59 dimensions = ResourceImage::GetImageSize( url );
62 // big image, atlasing is not applied
63 if( static_cast<uint32_t>(dimensions.GetWidth()) * static_cast<uint32_t>(dimensions.GetHeight()) > MAX_ITEM_AREA
64 || dimensions.GetWidth()>DEFAULT_ATLAS_SIZE
65 || dimensions.GetHeight()>DEFAULT_ATLAS_SIZE)
71 for( AtlasContainer::iterator iter = mAtlasList.begin(); iter != mAtlasList.end(); ++iter)
73 if( (*iter).Upload( textureRect, url, size, fittingMode, orientationCorrection ) )
75 return mTextureSetList[i];
81 mAtlasList.back().Upload( textureRect, url, size, fittingMode, orientationCorrection );
82 return mTextureSetList.back();
85 TextureSet ImageAtlasManager::Add( Vector4& textureRect,
89 // big buffer, atlasing is not applied
90 if( static_cast<uint32_t>(pixelData.GetWidth()) * static_cast<uint32_t>(pixelData.GetHeight()) > MAX_ITEM_AREA
91 || pixelData.GetWidth()>DEFAULT_ATLAS_SIZE
92 || pixelData.GetHeight()>DEFAULT_ATLAS_SIZE )
98 for( AtlasContainer::iterator iter = mAtlasList.begin(); iter != mAtlasList.end(); ++iter)
100 if( (*iter).Upload( textureRect, pixelData ) )
102 return mTextureSetList[i];
108 mAtlasList.back().Upload( textureRect, pixelData );
109 return mTextureSetList.back();
113 void ImageAtlasManager::Remove( TextureSet textureSet, const Vector4& textureRect )
116 for( TextureSetContainer::iterator iter = mTextureSetList.begin(); iter != mTextureSetList.end(); ++iter)
118 if( (*iter) == textureSet )
120 mAtlasList[i].Remove(textureRect);
127 void ImageAtlasManager::SetBrokenImage( const std::string& brokenImageUrl )
129 if( !brokenImageUrl.empty() )
131 mBrokenImageUrl = brokenImageUrl;
135 void ImageAtlasManager::CreateNewAtlas()
137 Toolkit::ImageAtlas newAtlas = Toolkit::ImageAtlas::New( DEFAULT_ATLAS_SIZE, DEFAULT_ATLAS_SIZE );
138 if( !mBrokenImageUrl.empty() )
140 newAtlas.SetBrokenImage( mBrokenImageUrl );
142 mAtlasList.push_back( newAtlas );
143 TextureSet textureSet = TextureSet::New();
144 textureSet.SetImage( 0u, newAtlas.GetAtlas() );
145 mTextureSetList.push_back( textureSet );
148 } // namespace Internal
150 } // namespace Toolkit