#include <string>
// INTERNAL INCLUDES
+#include "image-loading.h"
#include "bitmap-loader-impl.h"
-#include "image-loaders/image-loader.h"
namespace Dali
{
ImageDimensions size,
FittingMode::Type fittingMode,
SamplingMode::Type samplingMode,
- bool orientationCorrection)
-: mResourceType( size, fittingMode, samplingMode, orientationCorrection ),
- mPixelData(),
- mUrl(url)
+ bool orientationCorrection )
+: mPixelData(),
+ mUrl(url),
+ mSize( size ),
+ mFittingMode( fittingMode ),
+ mSamplingMode( samplingMode ),
+ mOrientationCorrection( orientationCorrection )
{
}
void BitmapLoader::Load()
{
- IntrusivePtr<Dali::RefObject> resource = TizenPlatform::ImageLoader::LoadResourceSynchronously( mResourceType, mUrl );
-
- if( resource )
- {
- 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 = Dali::PixelData::New( bitmap->GetBufferOwnership(),
- bitmap->GetBufferSize(),
- bitmap->GetImageWidth(),
- bitmap->GetImageHeight(),
- bitmap->GetPixelFormat(),
- Dali::PixelData::FREE);
- }
+ mPixelData = Dali::LoadImageFromFile( mUrl, mSize, mFittingMode, mSamplingMode, mOrientationCorrection );
}
bool BitmapLoader::IsLoaded()
Dali::PixelData GetPixelData() const;
private:
- Integration::BitmapResourceType mResourceType;
+
Dali::PixelData mPixelData;
const std::string mUrl;
+ ImageDimensions mSize;
+ FittingMode::Type mFittingMode;
+ SamplingMode::Type mSamplingMode;
+ bool mOrientationCorrection;
+
};
} // Internal
--- /dev/null
+/*
+ * Copyright (c) 2016 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 "image-loading.h"
+
+// INTERNAL INCLUDES
+#include "image-loaders/image-loader.h"
+
+namespace Dali
+{
+
+PixelData LoadImageFromFile( const std::string& url, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection )
+{
+ Integration::BitmapResourceType resourceType( size, fittingMode, samplingMode, orientationCorrection );
+ IntrusivePtr<Dali::RefObject> resource = TizenPlatform::ImageLoader::LoadResourceSynchronously( resourceType, url );
+
+ if( resource )
+ {
+ 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.
+ return Dali::PixelData::New( bitmap->GetBufferOwnership(),
+ bitmap->GetBufferSize(),
+ bitmap->GetImageWidth(),
+ bitmap->GetImageHeight(),
+ bitmap->GetPixelFormat(),
+ Dali::PixelData::FREE );
+ }
+ return Dali::PixelData();
+}
+
+} // namespace Dali
--- /dev/null
+#ifndef DALI_IMAGE_LOADING_H
+#define DALI_IMAGE_LOADING_H
+
+/*
+ * Copyright (c) 2016 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 <string>
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/images/image-operations.h>
+#include <dali/public-api/images/pixel-data.h>
+
+namespace Dali
+{
+
+/**
+ * @brief Load an image synchronously from local file.
+ *
+ * @note This method is thread safe, i.e. can be called from any thread.
+ *
+ * @param [in] url The URL of the image file to load.
+ * @param [in] size The width and height to fit the loaded image to, 0.0 means whole image
+ * @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.
+ * @return handle to the loaded PixelData object or an empty handle in case loading failed.
+ */
+DALI_IMPORT_API PixelData LoadImageFromFile( const std::string& url,
+ ImageDimensions size = ImageDimensions( 0, 0 ),
+ FittingMode::Type fittingMode = FittingMode::DEFAULT,
+ SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR,
+ bool orientationCorrection = true );
+
+} // Dali
+
+#endif // DALI_IMAGE_LOADING_H
$(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/image-loading.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/imf-manager.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/orientation.cpp \
$(adaptor_devel_api_dir)/adaptor-framework/performance-logger.cpp \
$(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 \
+ $(adaptor_devel_api_dir)/adaptor-framework/image-loading.h \
$(adaptor_devel_api_dir)/adaptor-framework/imf-manager.h \
$(adaptor_devel_api_dir)/adaptor-framework/lifecycle-controller.h \
$(adaptor_devel_api_dir)/adaptor-framework/orientation.h \
SET(CAPI_LIB "dali-adaptor")
SET(TC_SOURCES
+ utc-Dali-Application.cpp
+ utc-Dali-BitmapLoader.cpp
+ utc-Dali-FileLoader.cpp
+ utc-Dali-ImageLoading.cpp
utc-Dali-Key.cpp
utc-Dali-NativeImageSource.cpp
utc-Dali-SingletonService.cpp
- utc-Dali-Window.cpp
utc-Dali-Timer.cpp
utc-Dali-TtsPlayer.cpp
- utc-Dali-Application.cpp
- utc-Dali-FileLoader.cpp
- utc-Dali-BitmapLoader.cpp
+ utc-Dali-Window.cpp
#utc-Dali-Watch.cpp
#utc-Dali-KeyGrab.cpp
)
--- /dev/null
+/*
+ * Copyright (c) 2016 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/image-loading.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_load_image_startup(void)
+{
+ test_return_value = TET_UNDEF;
+}
+
+void utc_dali_load_image_cleanup(void)
+{
+ test_return_value = TET_PASS;
+}
+
+int UtcDaliLoadImageP(void)
+{
+ PixelData pixelData = Dali::LoadImageFromFile( gImage_34_RGBA );
+ DALI_TEST_CHECK( pixelData );
+ DALI_TEST_EQUALS( pixelData.GetWidth(), 34u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelData.GetHeight(), 34u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
+
+ PixelData pixelData2 = Dali::LoadImageFromFile( gImage_128_RGB );
+ DALI_TEST_CHECK( pixelData2 );
+ DALI_TEST_EQUALS( pixelData2.GetWidth(), 128u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelData2.GetHeight(), 128u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelData2.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliLoadImageN(void)
+{
+ PixelData pixelData = Dali::LoadImageFromFile( gImageNonExist );
+ DALI_TEST_CHECK( !pixelData );
+
+ END_TEST;
+}