}
BitmapLoader::BitmapLoader(const std::string& url,
- ImageDimensions size,
- FittingMode::Type fittingMode,
- SamplingMode::Type samplingMode,
- bool orientationCorrection)
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection)
: mResourceType( size, fittingMode, samplingMode, orientationCorrection ),
- mBitmap(NULL),
- mUrl(url),
- mIsLoaded( false )
+ mPixelData(),
+ mUrl(url)
{
}
{
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
-{
- if( mIsLoaded )
+ if( resource )
{
- return mBitmap->GetBuffer();
+ Integration::Bitmap* bitmap = static_cast<Integration::Bitmap*>(resource.Get());
+
+ // Use bitmap->GetBufferOwnership() to transfer the buffer ownership to pixelData.
+ // The destroy of bitmap will not release the buffer, instead, the pixelData is responsible for releasing when its reference count falls to zero.
+ mPixelData = PixelData::New( bitmap->GetBufferOwnership(),
+ bitmap->GetImageWidth(),
+ bitmap->GetImageHeight(),
+ bitmap->GetPixelFormat(),
+ PixelData::FREE);
}
-
- return NULL;
}
-unsigned int BitmapLoader::GetImageHeight() const
+bool BitmapLoader::IsLoaded()
{
- if( mIsLoaded )
- {
- return mBitmap->GetImageHeight();
- }
-
- return 0u;
+ return mPixelData ? true : false ;
}
-unsigned int BitmapLoader::GetImageWidth() const
+const std::string& BitmapLoader::GetUrl() const
{
- if( mIsLoaded )
- {
- return mBitmap->GetImageWidth();
- }
-
- return 0u;
+ return mUrl;
}
-Pixel::Format BitmapLoader::GetPixelFormat() const
+PixelDataPtr BitmapLoader::GetPixelData() const
{
- if( mIsLoaded )
- {
- return mBitmap->GetPixelFormat();
- }
-
- return Pixel::RGBA8888;
+ return mPixelData;
}
} // namespace Internal
bool IsLoaded();
/**
- * Get the raw pixel data.
- * @return The pixel data. Use the GetHeight(), GetWidth(), GetStride() and GetPixelFormat() methods
- * to decode the data.
+ * @copydoc Dali::BitmapLoader::GetUrl()
*/
- unsigned char* GetPixelData() const;
+ const std::string& GetUrl() const;
/**
- * Get the buffer height in pixels
- * @return the height of the buffer in pixels
+ * @copydoc Dali::BitmapLoader::GetPixelData
*/
- unsigned int GetImageHeight() const;
-
- /**
- * Get the buffer width in pixels
- * @return the width of the buffer in pixels
- */
- unsigned int GetImageWidth() const;
-
- /**
- * Get the pixel format of the loaded bitmap.
- */
- Pixel::Format GetPixelFormat() const;
+ PixelDataPtr GetPixelData() const;
private:
Integration::BitmapResourceType mResourceType;
- Integration::BitmapPtr mBitmap;
+ PixelDataPtr mPixelData;
const std::string mUrl;
- bool mIsLoaded;
};
} // Internal
return GetImplementation(*this).IsLoaded();
}
-unsigned char* BitmapLoader::GetPixelData() const
+std::string BitmapLoader::GetUrl() const
{
- return GetImplementation(*this).GetPixelData();
-}
-
-unsigned int BitmapLoader::GetImageHeight() const
-{
- return GetImplementation(*this).GetImageHeight();
+ return GetImplementation(*this).GetUrl();
}
-unsigned int BitmapLoader::GetImageWidth() const
+PixelDataPtr BitmapLoader::GetPixelData() const
{
- return GetImplementation(*this).GetImageWidth();
-}
-
-Pixel::Format BitmapLoader::GetPixelFormat() const
-{
- return GetImplementation(*this).GetPixelFormat();
+ return GetImplementation(*this).GetPixelData();
}
} // namespace Dali
#include <dali/public-api/images/pixel.h>
#include <dali/public-api/images/image-operations.h>
#include <dali/public-api/object/base-handle.h>
+#include <dali/devel-api/images/pixel-data.h>
namespace Dali
{
bool IsLoaded();
/**
- * Get the raw pixel data.
- * @return The pixel data. Use the GetHeight(), GetWidth(), GetStride() and GetPixelFormat() methods
- * to decode the data.
- */
- unsigned char* GetPixelData() const;
-
- /**
- * Get the buffer height in pixels
- * @return the height of the buffer in pixels
- */
- unsigned int GetImageHeight() const;
-
- /**
- * Get the buffer width in pixels
- * @return the width of the buffer in pixels
+ * @brief Returns the URL of the image.
+ *
+ * @return The URL of the image file.
*/
- unsigned int GetImageWidth() const;
+ std::string GetUrl() const;
/**
- * Get the pixel format of the loaded bitmap.
+ * @brief Get the pixel data.
+ *
+ * The returned pixel data is still valid after the BitmapLoader been destroyed.
+ *
+ * @return The pixel data.
*/
- Pixel::Format GetPixelFormat() const;
+ PixelDataPtr GetPixelData() const;
public: // Not intended for application developers
utc-Dali-TtsPlayer.cpp
utc-Dali-Application.cpp
utc-Dali-FileLoader.cpp
+ utc-Dali-BitmapLoader.cpp
)
LIST(APPEND TC_SOURCES
--- /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.
+ *
+ */
+
+#include <stdlib.h>
+#include <dali/dali.h>
+#include <dali-test-suite-utils.h>
+#include <dali/devel-api/adaptor-framework/bitmap-loader.h>
+
+using namespace Dali;
+
+namespace
+{
+// resolution: 34*34, pixel format: RGBA8888
+static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
+// resolution: 128*128, pixel format: RGB888
+static const char* gImage_128_RGB = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
+
+// this is image is not exist, for negative test
+static const char* gImageNonExist = "non-exist.jpg";
+}
+
+void utc_dali_bitmap_loader_startup(void)
+{
+ test_return_value = TET_UNDEF;
+}
+
+void utc_dali_bitmap_loader_cleanup(void)
+{
+ test_return_value = TET_PASS;
+}
+
+int UtcDaliBitmapLoaderNew(void)
+{
+ TestApplication application;
+
+ // invoke default handle constructor
+ BitmapLoader loader;
+
+ DALI_TEST_CHECK( !loader );
+
+ // initialise handle
+ loader = BitmapLoader::New( gImage_34_RGBA );
+
+ DALI_TEST_CHECK( loader );
+ END_TEST;
+}
+
+int UtcDaliBitmapLoaderCopyConstructor(void)
+{
+ TestApplication application;
+
+ BitmapLoader loader = BitmapLoader::New( gImage_34_RGBA);
+ BitmapLoader loaderCopy(loader);
+
+ DALI_TEST_EQUALS( (bool)loaderCopy, true, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliBitmapLoaderAssignmentOperator(void)
+{
+ TestApplication application;
+
+ BitmapLoader loader = BitmapLoader::New( gImage_34_RGBA );
+
+ BitmapLoader loader2;
+ DALI_TEST_EQUALS( (bool)loader2, false, TEST_LOCATION );
+
+ loader2 = loader;
+ DALI_TEST_EQUALS( (bool)loader2, true, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliBitmapLoaderGetUrl(void)
+{
+ TestApplication application;
+
+ BitmapLoader loader = BitmapLoader::New( gImage_34_RGBA );
+ DALI_TEST_CHECK( loader.GetUrl() == gImage_34_RGBA );
+
+ END_TEST;
+}
+
+
+int UtcDaliBitmapLoaderLoadP(void)
+{
+ TestApplication application;
+
+ BitmapLoader loader1 = BitmapLoader::New( gImage_34_RGBA );
+ DALI_TEST_CHECK( ! loader1.IsLoaded() );
+ loader1.Load();
+ DALI_TEST_CHECK( loader1.IsLoaded() );
+ PixelDataPtr pixelData1 = loader1.GetPixelData();
+ DALI_TEST_CHECK( pixelData1 );
+ DALI_TEST_CHECK( pixelData1->GetWidth() == 34u );
+ DALI_TEST_CHECK( pixelData1->GetHeight() == 34u );
+ DALI_TEST_CHECK( pixelData1->GetPixelFormat() == Pixel::RGBA8888 );
+
+ BitmapLoader loader2 = BitmapLoader::New( gImage_128_RGB );
+ DALI_TEST_CHECK( ! loader2.IsLoaded() );
+ loader2.Load();
+ DALI_TEST_CHECK( loader2.IsLoaded() );
+ PixelDataPtr pixelData2 = loader2.GetPixelData();
+ DALI_TEST_CHECK( pixelData2 );
+ DALI_TEST_CHECK( pixelData2->GetWidth() == 128u );
+ DALI_TEST_CHECK( pixelData2->GetHeight() == 128u );
+ DALI_TEST_CHECK( pixelData2->GetPixelFormat() == Pixel::RGB888 );
+
+ END_TEST;
+}
+
+int UtcDaliBitmapLoaderLoadN(void)
+{
+ TestApplication application;
+
+ BitmapLoader loader = BitmapLoader::New( gImageNonExist );
+ DALI_TEST_CHECK( ! loader.IsLoaded() );
+ loader.Load();
+
+ // cannot load image that is not exist
+ DALI_TEST_CHECK( ! loader.IsLoaded() );
+ PixelDataPtr pixelData = loader.GetPixelData();
+ DALI_TEST_CHECK( !pixelData);
+
+ END_TEST;
+}