Remove ResourceImage usage from demos
[platform/core/uifw/dali-demo.git] / shared / utility.h
1 #ifndef __DALI_DEMO_UTILITY_H__
2 #define __DALI_DEMO_UTILITY_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 #include <dali/dali.h>
22 #include <dali/devel-api/images/atlas.h>
23 #include <dali/devel-api/rendering/texture.h>
24 #include <dali/devel-api/adaptor-framework/bitmap-loader.h>
25
26 namespace DemoHelper
27 {
28
29 Dali::PixelData LoadPixelData( const char* imagePath,
30                                Dali::ImageDimensions size,
31                                Dali::FittingMode::Type fittingMode,
32                                Dali::SamplingMode::Type samplingMode )
33 {
34   Dali::BitmapLoader loader = Dali::BitmapLoader::New( imagePath, size, fittingMode, samplingMode );
35   loader.Load();
36   return loader.GetPixelData();
37 }
38
39
40 Dali::Atlas LoadImage( const char* imagePath,
41                        Dali::ImageDimensions size = Dali::ImageDimensions(),
42                        Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT,
43                        Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT )
44 {
45   Dali::PixelData pixelData = LoadPixelData(imagePath, size, fittingMode, samplingMode);
46   Dali::Atlas image  =Dali:: Atlas::New( pixelData.GetWidth(), pixelData.GetHeight(), pixelData.GetPixelFormat() );
47   image.Upload( pixelData, 0u, 0u );
48
49   return image;
50 }
51
52 Dali::Texture LoadTexture( const char* imagePath,
53                            Dali::ImageDimensions size = Dali::ImageDimensions(),
54                            Dali::FittingMode::Type fittingMode = Dali::FittingMode::DEFAULT,
55                            Dali::SamplingMode::Type samplingMode = Dali::SamplingMode::DEFAULT )
56 {
57   Dali::PixelData pixelData = LoadPixelData(imagePath, size, fittingMode, samplingMode);
58   Dali::Texture texture  = Dali::Texture::New( Dali::TextureType::TEXTURE_2D,
59                                                pixelData.GetPixelFormat(),
60                                                pixelData.GetWidth(),
61                                                pixelData.GetHeight() );
62   texture.Upload( pixelData );
63
64   return texture;
65 }
66
67 /**
68  * @brief Load an bitmap resource.
69  *
70  * If it is required to scaled-down to no more than the stage dimensions,
71  * uses image scaling mode FittingMode::SCALE_TO_FILL to resize the image at
72  * load time to cover the entire stage with pixels with no borders,
73  * and filter mode BOX_THEN_LINEAR to sample the image with
74  * maximum quality.
75  */
76
77 Dali::Atlas LoadStageFillingImage( const char* imagePath )
78 {
79   Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
80   return LoadImage( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
81 }
82
83 Dali::Texture LoadStageFillingTexture( const char* imagePath )
84 {
85   Dali::Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
86   return LoadTexture( imagePath, Dali::ImageDimensions( stageSize.x, stageSize.y ), Dali::FittingMode::SCALE_TO_FILL, Dali::SamplingMode::BOX_THEN_LINEAR );
87 }
88
89 } // DemoHelper
90
91 #endif // __DALI_DEMO_HELPER_VIEW_H__