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.
18 #include "toolkit-bitmap-loader.h"
21 #include <dali/public-api/object/base-object.h>
23 #include <semaphore.h>
31 Dali::BitmapLoader gBitmapLoader;
38 class BitmapLoader : public BaseObject
41 static IntrusivePtr<BitmapLoader> New( const std::string& url,
43 FittingMode::Type fittingMode,
44 SamplingMode::Type samplingMode,
45 bool orientationCorrection)
47 IntrusivePtr<BitmapLoader> internal = new BitmapLoader( url, size, fittingMode, samplingMode, orientationCorrection );
51 BitmapLoader(const std::string& url,
53 FittingMode::Type fittingMode,
54 SamplingMode::Type samplingMode,
55 bool orientationCorrection)
60 sem_init( &mySemaphore, 0, 0 );
67 size_t bufferSize = mSize.GetWidth() * mSize.GetHeight() * 4;
68 unsigned char* buffer = static_cast<unsigned char*>(malloc(bufferSize));
69 memset(buffer, 0, bufferSize);
71 mPixelData = Dali::PixelData::New( buffer, bufferSize, mSize.GetWidth(), mSize.GetHeight(), Pixel::RGBA8888, Dali::PixelData::FREE);
73 sem_post( &mySemaphore );
76 Dali::PixelData GetPixelData() const
81 const std::string& GetUrl() const
88 return mPixelData ? true : false;
97 sem_wait( &mySemaphore );
100 ImageDimensions mSize;
101 Dali::PixelData mPixelData;
102 const std::string mUrl;
108 inline Internal::BitmapLoader& GetImplementation(Dali::BitmapLoader& handle)
110 DALI_ASSERT_ALWAYS( handle && "handle is empty" );
111 BaseObject& object = handle.GetBaseObject();
112 return static_cast<Internal::BitmapLoader&>(object);
115 inline const Internal::BitmapLoader& GetImplementation(const Dali::BitmapLoader& handle)
117 DALI_ASSERT_ALWAYS( handle && "handle is empty" );
118 const BaseObject& object = handle.GetBaseObject();
119 return static_cast<const Internal::BitmapLoader&>(object);
122 Dali::BitmapLoader Dali::BitmapLoader::New(std::string const&url, Dali::Uint16Pair size, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode, bool orientationCorrection)
124 IntrusivePtr<Internal::BitmapLoader> internal = Internal::BitmapLoader::New(url, size, fittingMode, samplingMode, orientationCorrection);
125 gBitmapLoader = BitmapLoader(internal.Get());
126 return gBitmapLoader;
129 BitmapLoader::BitmapLoader()
133 Dali::BitmapLoader::BitmapLoader(Dali::BitmapLoader const& handle)
137 Dali::BitmapLoader::BitmapLoader(Internal::BitmapLoader* internal)
138 :BaseHandle(internal)
141 Dali::BitmapLoader::~BitmapLoader()
144 BitmapLoader& BitmapLoader::operator=(const BitmapLoader& rhs)
146 BaseHandle::operator=(rhs);
149 void Dali::BitmapLoader::Load()
151 GetImplementation(*this).Load();
153 PixelData Dali::BitmapLoader::GetPixelData() const
155 return GetImplementation(*this).GetPixelData();
157 std::string Dali::BitmapLoader::GetUrl() const
159 return GetImplementation(*this).GetUrl();
161 bool Dali::BitmapLoader::IsLoaded()
163 return GetImplementation(*this).IsLoaded();
165 void Dali::BitmapLoader::WaitForLoading()
167 GetImplementation(*this).WaitForLoading();
170 BitmapLoader Dali::BitmapLoader::GetLatestCreated()
172 return gBitmapLoader;
175 void Dali::BitmapLoader::ResetLatestCreated()
177 gBitmapLoader.Reset();