// EXTERNAL INCLUDES
#include <string>
-#include <dali/integration-api/resource-types.h>
-#include <dali/integration-api/resource-cache.h>
-
// INTERNAL INCLUDES
#include "bitmap-loader-impl.h"
#include "image-loaders/image-loader.h"
namespace Internal
{
-IntrusivePtr<BitmapLoader> BitmapLoader::New(const std::string& filename)
+IntrusivePtr<BitmapLoader> BitmapLoader::New(const std::string& url,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection)
{
- IntrusivePtr<BitmapLoader> internal = new BitmapLoader();
- internal->Initialize(filename);
+ IntrusivePtr<BitmapLoader> internal = new BitmapLoader( url, size, fittingMode, samplingMode, orientationCorrection );
return internal;
}
-BitmapLoader::BitmapLoader()
-: mBitmap(NULL)
+BitmapLoader::BitmapLoader(const std::string& url,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection)
+: mResourceType( size, fittingMode, samplingMode, orientationCorrection ),
+ mBitmap(NULL),
+ mUrl(url),
+ mIsLoaded( false )
{
}
{
}
-void BitmapLoader::Initialize(const std::string& filename)
+void BitmapLoader::Load()
{
- // Load with default scaling and orientation correction:
- Integration::BitmapResourceType bitmapResourceType;
- Integration::ResourcePointer resource = TizenPlatform::ImageLoader::LoadResourceSynchronously( bitmapResourceType, filename );
+ IntrusivePtr<Dali::RefObject> resource = TizenPlatform::ImageLoader::LoadResourceSynchronously( mResourceType, mUrl );
mBitmap = static_cast<Integration::Bitmap*>(resource.Get());
+ mIsLoaded = true;
+}
+
+bool BitmapLoader::IsLoaded()
+{
+ return mIsLoaded;
}
unsigned char* BitmapLoader::GetPixelData() const
{
- return mBitmap->GetBuffer();
+ if( mIsLoaded )
+ {
+ return mBitmap->GetBuffer();
+ }
+
+ return NULL;
}
unsigned int BitmapLoader::GetImageHeight() const
{
- return mBitmap->GetImageHeight();
+ if( mIsLoaded )
+ {
+ return mBitmap->GetImageHeight();
+ }
+
+ return 0u;
}
unsigned int BitmapLoader::GetImageWidth() const
{
- return mBitmap->GetImageWidth();
-}
+ if( mIsLoaded )
+ {
+ return mBitmap->GetImageWidth();
+ }
-unsigned int BitmapLoader::GetBufferStride() const
-{
- return mBitmap->GetPackedPixelsProfile()->GetBufferStride();
+ return 0u;
}
Pixel::Format BitmapLoader::GetPixelFormat() const
{
- return mBitmap->GetPixelFormat();
+ if( mIsLoaded )
+ {
+ return mBitmap->GetPixelFormat();
+ }
+
+ return Pixel::RGBA8888;
}
} // namespace Internal
#include <dali/public-api/object/base-object.h>
#include <dali/public-api/common/intrusive-ptr.h>
#include <dali/integration-api/bitmap.h>
+#include <dali/integration-api/resource-types.h>
// INTERNAL INCLUDES
#include <bitmap-loader.h>
class BitmapLoader : public BaseObject
{
public:
- static IntrusivePtr<BitmapLoader> New(const std::string& filename);
+
+ /**
+ * @copydoc Dali::BitmapLoader::New
+ */
+ static IntrusivePtr<BitmapLoader> New( const std::string& url,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection);
/**
* Create the bitmap loader object.
*/
- BitmapLoader();
+ BitmapLoader(const std::string& url,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection);
protected:
/**
*/
~BitmapLoader();
+public:
+
/**
- * Second stage initialization - this will load the image synchronously.
- * @param[in] filename Filename of the bitmap image to load.
+ * @copydoc Dali::BitmapLoader::Load
*/
- void Initialize(const std::string& filename);
+ void Load();
-public:
+ /**
+ * @copydoc Dali::BitmapLoader::IsLoaded
+ */
+ bool IsLoaded();
/**
* Get the raw pixel data.
unsigned int GetImageWidth() const;
/**
- * Get the number of bytes in each row of pixels
- * @return The buffer stride in bytes.
- */
- unsigned int GetBufferStride() const;
-
- /**
* Get the pixel format of the loaded bitmap.
*/
Pixel::Format GetPixelFormat() const;
private:
+ Integration::BitmapResourceType mResourceType;
Integration::BitmapPtr mBitmap;
+ const std::string mUrl;
+ bool mIsLoaded;
};
} // Internal
// EXTERNAL INCLUDES
#include <string>
-#include <dali/integration-api/bitmap.h>
-#include <dali/integration-api/resource-types.h>
-#include <dali/integration-api/resource-cache.h>
-
// INTERNAL INCLUDES
-#include "image-loaders/image-loader.h"
#include <bitmap-loader-impl.h>
namespace Dali
{
-BitmapLoader BitmapLoader::New(const std::string& filename)
+BitmapLoader BitmapLoader::New( const std::string& url,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection)
{
- IntrusivePtr<Internal::BitmapLoader> internal = Internal::BitmapLoader::New(filename);
+ IntrusivePtr<Internal::BitmapLoader> internal = Internal::BitmapLoader::New(url, size, fittingMode, samplingMode, orientationCorrection);
return BitmapLoader( internal.Get() );
}
return *this;
}
+void BitmapLoader::Load()
+{
+ GetImplementation(*this).Load();
+}
+
+bool BitmapLoader::IsLoaded()
+{
+ return GetImplementation(*this).IsLoaded();
+}
+
unsigned char* BitmapLoader::GetPixelData() const
{
return GetImplementation(*this).GetPixelData();
return GetImplementation(*this).GetImageWidth();
}
-unsigned int BitmapLoader::GetBufferStride() const
-{
- return GetImplementation(*this).GetBufferStride();
-}
-
Pixel::Format BitmapLoader::GetPixelFormat() const
{
return GetImplementation(*this).GetPixelFormat();
#include <string>
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/images/pixel.h>
+#include <dali/public-api/images/image-operations.h>
#include <dali/public-api/object/base-handle.h>
namespace Dali
class BitmapLoader;
}
+/**
+ * @brief The BitmapLoader class is used to load bitmap from the URL synchronously.
+ *
+ * As the loading is synchronous, it will block the loop whilst executing.
+ * Therefore, it should be used sparingly in the main event thread, and better to be called in the worker thread.
+ * The Load() API is thread safe, it can be called from any thread without changing the state of DALI.
+ */
class DALI_IMPORT_API BitmapLoader : public BaseHandle
{
public:
+
/**
- * @brief Create an initialized bitmap loader. This will automatically load the image.
+ * @brief Create an initialized bitmap loader.
+ *
+ * By calling Load(), the synchronous loading is started immediately.
*
- * @param[in] filename Filename of the bitmap image to load.
+ * @param [in] url The URL of the image file to load.
+ * @param [in] size The width and height to fit the loaded image to.
+ * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
+ * @param [in] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
+ * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
*/
- static BitmapLoader New(const std::string& filename);
+ static BitmapLoader New( const std::string& url,
+ ImageDimensions size = ImageDimensions( 0, 0 ),
+ FittingMode::Type fittingMode = FittingMode::DEFAULT,
+ SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
+ bool orientationCorrection = true);
/**
* @brief Create an empty handle.
public:
/**
+ * @brief Start the synchronous loading.
+ */
+ void Load();
+
+ /**
+ * @brief Query whether the image is loaded.
+ *
+ * @reture true if the image is loaded, false otherwise.
+ */
+ bool IsLoaded();
+
+ /**
* Get the raw pixel data.
* @return The pixel data. Use the GetHeight(), GetWidth(), GetStride() and GetPixelFormat() methods
* to decode the data.
unsigned int GetImageWidth() const;
/**
- * Get the number of bytes in each row of pixels
- * @return The buffer stride in bytes.
- */
- unsigned int GetBufferStride() const;
-
- /**
* Get the pixel format of the loaded bitmap.
*/
Pixel::Format GetPixelFormat() const;
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// CLASS HEADER
+#include "event-thread-callback.h"
+
+// INTERNAL INCLUDES
+#include <adaptor-impl.h>
+
+namespace Dali
+{
+
+struct EventThreadCallback::Impl
+{
+ TriggerEventInterface* eventTrigger;
+};
+
+EventThreadCallback::EventThreadCallback( CallbackBase* callback )
+: mImpl( new Impl() )
+{
+ mImpl->eventTrigger = NULL;
+ if ( Adaptor::IsAvailable() )
+ {
+ Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation( Adaptor::Get() );
+ mImpl->eventTrigger = adaptorImpl.GetTriggerEventFactoryInterface().CreateTriggerEvent( callback, TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER );
+ }
+}
+
+EventThreadCallback::~EventThreadCallback()
+{
+ if ( Adaptor::IsAvailable() )
+ {
+ Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation( Adaptor::Get() );
+ adaptorImpl.GetTriggerEventFactoryInterface().DestroyTriggerEvent( mImpl->eventTrigger );
+ }
+ delete mImpl;
+}
+
+void EventThreadCallback::Trigger()
+{
+ if( mImpl->eventTrigger )
+ {
+ mImpl->eventTrigger->Trigger();
+ }
+}
+
+}
--- /dev/null
+#ifndef __DALI_EVENT_THREAD_CALLBACK_H_
+#define __DALI_EVENT_THREAD_CALLBACK_H_
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/signals/callback.h>
+
+namespace Dali
+{
+
+/**
+ * @brief The EventThreadCallback class provides a mechanism for the worker thread to trigger the execution of a given callback in main event thread .
+ *
+ * @note The EventThreadCallback object should only be created in the main thread.
+ */
+class DALI_IMPORT_API EventThreadCallback
+{
+public:
+
+ /**
+ * @brief Constructor. Create an object that will call the given callback in main event thread.
+ *
+ * @param[in] callback The callback to call.
+ */
+ EventThreadCallback( CallbackBase* callback );
+
+ /**
+ * @brief Destructor.
+ */
+ ~EventThreadCallback();
+
+ /**
+ * @brief Trigger the calling of callback.
+ *
+ * The method can be used from worker threads to notify the main thread as main thread is running the event loop and thus cannot be blocked
+ */
+ void Trigger();
+
+private:
+
+ // undefined copy constructor.
+ EventThreadCallback( const EventThreadCallback& );
+
+ // undefined assignment operator
+ EventThreadCallback& operator=( const EventThreadCallback& );
+
+private:
+
+ struct Impl;
+ Impl* mImpl;
+
+};
+
+}
+#endif /* __DALI_EVENT_THREAD_CALLBACK_H_ */
$(adaptor_devel_api_dir)/adaptor-framework/color-controller.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/drag-and-drop-detector.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/event-feeder.cpp \
+ $(adaptor_devel_api_dir)/adaptor-framework/event-thread-callback.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/feedback-player.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/file-loader.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/imf-manager.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/color-controller.h \
$(adaptor_devel_api_dir)/adaptor-framework/drag-and-drop-detector.h \
$(adaptor_devel_api_dir)/adaptor-framework/event-feeder.h \
+ $(adaptor_devel_api_dir)/adaptor-framework/event-thread-callback.h \
$(adaptor_devel_api_dir)/adaptor-framework/feedback-plugin.h \
$(adaptor_devel_api_dir)/adaptor-framework/feedback-player.h \
$(adaptor_devel_api_dir)/adaptor-framework/file-loader.h \