2 * Copyright (c) 2016 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.
17 #include <dali/public-api/object/base-object.h>
18 #include <dali/devel-api/adaptor-framework/bitmap-loader.h>
30 class BitmapLoader : public BaseObject
33 static IntrusivePtr<BitmapLoader> New( const std::string& url,
35 FittingMode::Type fittingMode,
36 SamplingMode::Type samplingMode,
37 bool orientationCorrection)
39 IntrusivePtr<BitmapLoader> internal = new BitmapLoader( url, size, fittingMode, samplingMode, orientationCorrection );
43 BitmapLoader(const std::string& url,
45 FittingMode::Type fittingMode,
46 SamplingMode::Type samplingMode,
47 bool orientationCorrection)
58 size_t bufferSize = mSize.GetWidth() * mSize.GetHeight() * 4;
59 unsigned char* buffer = static_cast<unsigned char*>(malloc(bufferSize));
60 memset(buffer, 0, bufferSize);
62 mPixelData = PixelData::New( buffer, mSize.GetWidth(), mSize.GetHeight(), Pixel::RGBA8888, PixelData::FREE);
65 PixelDataPtr GetPixelData() const
70 const std::string& GetUrl() const
77 return mPixelData ? true : false;
80 ImageDimensions mSize;
81 PixelDataPtr mPixelData;
82 const std::string mUrl;
87 inline Internal::BitmapLoader& GetImplementation(Dali::BitmapLoader& handle)
89 DALI_ASSERT_ALWAYS( handle && "handle is empty" );
90 BaseObject& object = handle.GetBaseObject();
91 return static_cast<Internal::BitmapLoader&>(object);
94 inline const Internal::BitmapLoader& GetImplementation(const Dali::BitmapLoader& handle)
96 DALI_ASSERT_ALWAYS( handle && "handle is empty" );
97 const BaseObject& object = handle.GetBaseObject();
98 return static_cast<const Internal::BitmapLoader&>(object);
101 Dali::BitmapLoader Dali::BitmapLoader::New(std::string const&url, Dali::Uint16Pair size, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode, bool orientationCorrection)
103 IntrusivePtr<Internal::BitmapLoader> internal = Internal::BitmapLoader::New(url, size, fittingMode, samplingMode, orientationCorrection);
104 return BitmapLoader( internal.Get() );
107 Dali::BitmapLoader::BitmapLoader(Dali::BitmapLoader const& handle)
111 Dali::BitmapLoader::BitmapLoader(Internal::BitmapLoader* internal)
112 :BaseHandle(internal)
115 Dali::BitmapLoader::~BitmapLoader()
118 void Dali::BitmapLoader::Load()
120 GetImplementation(*this).Load();
122 PixelDataPtr Dali::BitmapLoader::GetPixelData() const
124 return GetImplementation(*this).GetPixelData();
126 std::string Dali::BitmapLoader::GetUrl() const
128 return GetImplementation(*this).GetUrl();
130 bool Dali::BitmapLoader::IsLoaded()
132 return GetImplementation(*this).IsLoaded();