utc-Dali-MeshMaterial.cpp
utc-Dali-Mutex.cpp
utc-Dali-NativeImage.cpp
- utc-Dali-NinePatchImages.cpp
utc-Dali-ObjectRegistry.cpp
utc-Dali-PanGesture.cpp
utc-Dali-PanGestureDetector.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 <iostream>
-
-#include <stdlib.h>
-#include <dali/public-api/dali-core.h>
-#include <dali/devel-api/images/nine-patch-image.h>
-#include <dali-test-suite-utils.h>
-
-using namespace Dali;
-
-namespace {
-
-Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
-{
- Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
- Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
- unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
-
- memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
-
- return bitmap;
-}
-
-void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
-{
- PixelBuffer* pixbuffer = image->GetBuffer();
- unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
-
- for( unsigned int row = 0; row < imageWidth; ++row )
- {
- unsigned int pixelOffset = row * bytesPerPixel;
- pixbuffer[ pixelOffset + 3 ] = 0x00;
- pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
- pixbuffer[ pixelOffset + 3 ] = 0x00;
- }
-
- for ( unsigned int column = 0; column < imageHeight; ++column )
- {
- unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
- pixbuffer[ pixelOffset + 3 ] = 0x00;
- pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
- pixbuffer[ pixelOffset + 3 ] = 0x00;
- }
-}
-
-void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredStretchBorder, Pixel::Format pixelFormat )
-{
- PixelBuffer* pixbuffer = image->GetBuffer();
- unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
-
- for( unsigned int column = requiredStretchBorder.x; column < imageWidth - requiredStretchBorder.z; ++column )
- {
- unsigned int pixelOffset = column * bytesPerPixel;
- pixbuffer[ pixelOffset ] = 0x00;
- pixbuffer[ pixelOffset + 1 ] = 0x00;
- pixbuffer[ pixelOffset + 2 ] = 0x00;
- pixbuffer[ pixelOffset + 3 ] = 0xFF;
- }
-
- for( unsigned int row = requiredStretchBorder.y; row < imageHeight - requiredStretchBorder.w; ++row )
- {
- unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
- pixbuffer[ pixelOffset ] = 0x00;
- pixbuffer[ pixelOffset + 1 ] = 0x00;
- pixbuffer[ pixelOffset + 2 ] = 0x00;
- pixbuffer[ pixelOffset + 3 ] = 0xFF;
- }
-}
-
-void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
-{
- PixelBuffer* pixbuffer = image->GetBuffer();
- unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
-
- Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
- unsigned int bufferStride = srcProfile->GetBufferStride();
-
- // Add bottom child region
- for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
- {
- unsigned int pixelOffset = column * bytesPerPixel;
- pixelOffset += ( imageHeight - 1 ) * bufferStride;
- pixbuffer[ pixelOffset ] = 0x00;
- pixbuffer[ pixelOffset + 1 ] = 0x00;
- pixbuffer[ pixelOffset + 2 ] = 0x00;
- pixbuffer[ pixelOffset + 3 ] = 0xFF;
- }
-
- // Add right child region
- for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
- {
- unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
- pixbuffer[ pixelOffset ] = 0x00;
- pixbuffer[ pixelOffset + 1 ] = 0x00;
- pixbuffer[ pixelOffset + 2 ] = 0x00;
- pixbuffer[ pixelOffset + 3 ] = 0xFF;
- }
-}
-
-NinePatchImage CustomizeNinePatch( TestApplication& application,
- unsigned int ninePatchImageWidth,
- unsigned int ninePatchImageHeight,
- const Vector4& requiredStretchBorder,
- bool addChildRegion = false,
- Vector4 requiredChildRegion = Vector4::ZERO )
-{
- TestPlatformAbstraction& platform = application.GetPlatform();
-
- Pixel::Format pixelFormat = Pixel::RGBA8888;
-
- tet_infoline("Create Bitmap");
- platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
- Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
-
- tet_infoline("Clear border regions");
- InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
-
- tet_infoline("Add Stretch regions to Bitmap");
- AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredStretchBorder, pixelFormat );
-
- if( addChildRegion )
- {
- tet_infoline("Add Child regions to Bitmap");
- AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
- }
-
- tet_infoline("Setting resource as it's loaded synchronously");
- Integration::ResourcePointer resourcePtr(bitmap);
- platform.SetSynchronouslyLoadedResource( resourcePtr );
-
- std::string url( "blah.#.png" );
- Image image = ResourceImage::New( url );
-
- tet_infoline("Assign image to image rendering actor");
- Actor actor = CreateRenderableActor( image );
- Stage::GetCurrent().Add( actor );
-
- tet_infoline("Downcast Image to a nine-patch image\n");
- NinePatchImage ninePatchImage = NinePatchImage::DownCast( image );
-
- DALI_TEST_EQUALS( url, ninePatchImage.GetUrl(), TEST_LOCATION );
-
- return ninePatchImage;
-
-}
-
-} // namespace
-
-int UtcDaliNinePatchImageNew(void)
-{
- TestApplication application;
- tet_infoline("UtcDaliNinePatchImageNew - NinePatchImage::New(const std::string&)");
-
- // invoke default handle constructor
- NinePatchImage image;
-
- DALI_TEST_CHECK( !image );
-
- // initialise handle
- std::string url("blah.#.png");
- image = NinePatchImage::New( url );
-
- DALI_TEST_CHECK( image );
-
- DALI_TEST_EQUALS( url, image.GetUrl(), TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliNinePatchImageDowncast(void)
-{
- TestApplication application;
- tet_infoline("UtcDaliNinePatchImageDowncast - NinePatchImage::DownCast(BaseHandle)");
-
- NinePatchImage image = NinePatchImage::New( "blah.#.png" );
-
- BaseHandle object( image );
-
- NinePatchImage image2 = NinePatchImage::DownCast( object );
- DALI_TEST_CHECK( image2 );
-
- NinePatchImage image3 = DownCast< NinePatchImage >( object );
- DALI_TEST_CHECK( image3 );
-
- BaseHandle unInitializedObject;
- NinePatchImage image4 = NinePatchImage::DownCast( unInitializedObject );
- DALI_TEST_CHECK( !image4 );
-
- NinePatchImage image5 = DownCast< NinePatchImage >( unInitializedObject );
- DALI_TEST_CHECK( !image5 );
-
- Image image6 = NinePatchImage::New( "blah.#.png" );
- NinePatchImage image7 = NinePatchImage::DownCast( image6 );
- DALI_TEST_CHECK( image7 );
- END_TEST;
-}
-
-int UtcDaliNinePatchImageCopyConstructor(void)
-{
- TestApplication application;
-
- tet_infoline("UtcDaliNinePatchImageCopyConstructor - NinePatchImage::NinePatchImage( const NinePatchImage& )");
-
- NinePatchImage image1;
- DALI_TEST_CHECK( !image1 );
-
- image1 = NinePatchImage::New( "blah.#.png" );
- NinePatchImage image2( image1 );
-
- DALI_TEST_CHECK( image2 );
- DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliNinePatchImageGetStrechBorders(void)
-{
- TestApplication application;
- tet_infoline("UtcDaliNinePatchImageGetStrechBorders - NinePatchImage::GetStretchBorders()");
-
- /* Stretch region left(2) top(2) right (2) bottom (2)
- * ss
- * OOOOOO
- * OOOOOOc
- * sOOooOOc
- * sOOooOOc
- * OOOOOOc
- * OOOOOO
- * cccc
- */
-
- const unsigned int ninePatchImageHeight = 18;
- const unsigned int ninePatchImageWidth = 28;
- const Vector4 requiredStretchBorder( 3, 4, 5, 6 );
-
- NinePatchImage ninePatchImage = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, requiredStretchBorder );
- DALI_TEST_CHECK( ninePatchImage );
-
- if( ninePatchImage )
- {
- tet_infoline("Get Stretch regions from NinePatch");
-
- const NinePatchImage::StretchRanges& stretchPixelsX = ninePatchImage.GetStretchPixelsX();
- const NinePatchImage::StretchRanges& stretchPixelsY = ninePatchImage.GetStretchPixelsY();
-
- DALI_TEST_CHECK( stretchPixelsX.Size() == 1 );
- DALI_TEST_CHECK( stretchPixelsY.Size() == 1 );
-
- Vector4 stretchBorders;
- //The NinePatchImage stretch pixels are in the cropped image space, inset by 1 to get it to uncropped image space
- stretchBorders.x = stretchPixelsX[ 0 ].GetX() + 1;
- stretchBorders.y = stretchPixelsY[ 0 ].GetX() + 1;
- stretchBorders.z = ninePatchImageWidth - stretchPixelsX[ 0 ].GetY() - 1;
- stretchBorders.w = ninePatchImageHeight - stretchPixelsY[ 0 ].GetY() - 1;
-
- tet_printf("stretchBorders left(%f) right(%f) top(%f) bottom(%f)\n", stretchBorders.x, stretchBorders.z, stretchBorders.y, stretchBorders.w );
- DALI_TEST_CHECK( stretchBorders == requiredStretchBorder );
-
- Vector4 actualStretchBorders = ninePatchImage.GetStretchBorders();
- DALI_TEST_EQUALS( actualStretchBorders, requiredStretchBorder, 0.001, TEST_LOCATION );
- }
- else
- {
- tet_infoline("Image not NinePatch");
- test_return_value = TET_FAIL;
- }
-
- END_TEST;
-}
-
-int UtcDaliNinePatchImageGetChildRectangle(void)
-{
- TestApplication application;
- tet_infoline("UtcDaliNinePatchImageGetChildRectangle - NinePatchImage::GetChildRectangle()");
-
- /* Child region x(2) y(2) width (4) height (4)
- *
- * ss
- * OOOOOO
- * OOOOOOc
- * sOOooOOc
- * sOOooOOc
- * OOOOOOc
- * OOOOOO
- * cccc
- */
-
- const unsigned int ninePatchImageHeight = 18;
- const unsigned int ninePatchImageWidth = 28;
- const Vector4 requiredChildRegion( 2, 2, 2, 2 );
- const Vector4 requiredStretchBorder( 3, 4, 5, 6 );
-
- NinePatchImage ninePatchImage = CustomizeNinePatch( application,ninePatchImageWidth, ninePatchImageHeight, requiredStretchBorder, true, requiredChildRegion );
- DALI_TEST_CHECK( ninePatchImage );
-
- if ( ninePatchImage )
- {
- tet_infoline("Get Child regions from NinePatch");
- Rect< int > childRectangle = ninePatchImage.GetChildRectangle();
- tet_printf("childRectange x(%d) y(%d) width(%d) height(%d)\n", childRectangle.x, childRectangle.y, childRectangle.width, childRectangle.height );
- Rect< int > childRegion(requiredChildRegion.x, requiredChildRegion.y, ninePatchImageWidth - requiredChildRegion.x - requiredChildRegion.z, ninePatchImageHeight - requiredChildRegion.y - requiredChildRegion.w );
- DALI_TEST_CHECK( childRegion == childRectangle );
- }
- else
- {
- tet_infoline("Image not NinePatch");
- test_return_value = TET_FAIL;
- }
-
- END_TEST;
-}
-
-int UtcDaliNinePatchImageCreateCroppedBufferImage(void)
-{
- TestApplication application;
- tet_infoline("UtcDaliNinePatchImageCreateCroppedBufferImage - NinePatchImage::CreateCroppedBufferImage()");
-
- const unsigned int ninePatchImageHeight = 8;
- const unsigned int ninePatchImageWidth = 8;
- const Vector4 requiredStretchBorder( 1, 1, 1, 1 );
-
- NinePatchImage ninePatchImage = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, requiredStretchBorder );
- DALI_TEST_CHECK( ninePatchImage );
-
- if ( ninePatchImage )
- {
- BufferImage newImage = ninePatchImage.CreateCroppedBufferImage();
- DALI_TEST_CHECK( newImage );
-
- DALI_TEST_EQUALS( newImage.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
-
- DALI_TEST_EQUALS( newImage.GetBufferSize(), 144u/* 36*4 */, TEST_LOCATION );
- }
- else
- {
- tet_infoline("Image not NinePatch");
- test_return_value = TET_FAIL;
- }
-
- END_TEST;
-}
-
-int UtcDaliNinePatchImageIsNinePatchUrl(void)
-{
- TestApplication application;
- tet_infoline("UtcDaliNinePatchImageIsNinePatchUrl - NinePatchImage::IsNinePatchUrl(const std::string&)");
-
- DALI_TEST_CHECK( NinePatchImage::IsNinePatchUrl( "test.9.jpg" ) );
- DALI_TEST_CHECK( NinePatchImage::IsNinePatchUrl( "test.#.jpg" ) );
- DALI_TEST_CHECK( !NinePatchImage::IsNinePatchUrl( "test.9" ) );
- DALI_TEST_CHECK( !NinePatchImage::IsNinePatchUrl( "test.#" ) );
- DALI_TEST_CHECK( !NinePatchImage::IsNinePatchUrl( "test" ) );
-
- END_TEST;
-}
${devel_api_src_dir}/events/key-event-devel.cpp
${devel_api_src_dir}/images/distance-field.cpp
${devel_api_src_dir}/images/texture-set-image.cpp
- ${devel_api_src_dir}/images/nine-patch-image.cpp
${devel_api_src_dir}/images/pixel-data-devel.cpp
${devel_api_src_dir}/object/handle-devel.cpp
${devel_api_src_dir}/object/csharp-type-registry.cpp
SET( devel_api_core_images_header_files
${devel_api_src_dir}/images/distance-field.h
${devel_api_src_dir}/images/native-image-interface-extension.h
- ${devel_api_src_dir}/images/nine-patch-image.h
${devel_api_src_dir}/images/texture-set-image.h
${devel_api_src_dir}/images/pixel-data-devel.h
)
${devel_api_core_scripting_header_files}
${devel_api_core_threading_header_files}
${devel_api_core_update_header_files}
-)
\ No newline at end of file
+)
+++ /dev/null
-/*
- * Copyright (c) 2018 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 <dali/devel-api/images/nine-patch-image.h>
-
-// INTERNAL INCLUDES
-#include <dali/internal/common/image-attributes.h>
-#include <dali/public-api/math/vector2.h>
-#include <dali/internal/event/images/nine-patch-image-impl.h>
-
-
-namespace Dali
-{
-
-NinePatchImage::NinePatchImage()
-{
-}
-
-NinePatchImage::NinePatchImage(Internal::NinePatchImage* internal)
-: ResourceImage(internal)
-{
-}
-
-NinePatchImage::~NinePatchImage()
-{
-}
-
-NinePatchImage::NinePatchImage(const NinePatchImage& handle)
-: ResourceImage(handle)
-{
-}
-
-NinePatchImage& NinePatchImage::operator=(const NinePatchImage& rhs)
-{
- BaseHandle::operator=(rhs);
- return *this;
-}
-
-NinePatchImage NinePatchImage::New( const std::string& filename )
-{
- Internal::NinePatchImagePtr internal = Internal::NinePatchImage::New( filename );
- return NinePatchImage(internal.Get());
-}
-
-NinePatchImage NinePatchImage::DownCast( BaseHandle handle )
-{
- return NinePatchImage( dynamic_cast<Dali::Internal::NinePatchImage*>(handle.GetObjectPtr()) );
-}
-
-Vector4 NinePatchImage::GetStretchBorders()
-{
- Vector4 border;
-
- const NinePatchImage::StretchRanges& stretchPixelsX = GetStretchPixelsX();
- const NinePatchImage::StretchRanges& stretchPixelsY = GetStretchPixelsY();
-
- if( stretchPixelsX.Size() > 0 && stretchPixelsY.Size() > 0 )
- {
- //The NinePatchImage stretch pixels are in the cropped image space, inset by 1 to get it to uncropped image space
- border.x = static_cast<float>( stretchPixelsX[ 0 ].GetX() + 1 );
- border.y = static_cast<float>( stretchPixelsY[ 0 ].GetX() + 1 );
- border.z = static_cast<float>( GetWidth() - stretchPixelsX[ 0 ].GetY() - 1 );
- border.w = static_cast<float>( GetHeight() - stretchPixelsY[ 0 ].GetY() - 1 );
- }
-
- return border;
-}
-
-const NinePatchImage::StretchRanges& NinePatchImage::GetStretchPixelsX()
-{
- return GetImplementation(*this).GetStretchPixelsX();
-}
-
-const NinePatchImage::StretchRanges& NinePatchImage::GetStretchPixelsY()
-{
- return GetImplementation(*this).GetStretchPixelsY();
-}
-
-Rect<int> NinePatchImage::GetChildRectangle()
-{
- return GetImplementation(*this).GetChildRectangle();
-}
-
-BufferImage NinePatchImage::CreateCroppedBufferImage()
-{
- Internal::BufferImagePtr internal = GetImplementation(*this).CreateCroppedBufferImage();
- return BufferImage(internal.Get());
-}
-
-bool NinePatchImage::IsNinePatchUrl( const std::string& url )
-{
- return Internal::NinePatchImage::IsNinePatchUrl( url );
-}
-
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_NINE_PATCH_IMAGE_H
-#define DALI_NINE_PATCH_IMAGE_H
-
-/*
- * Copyright (c) 2019 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.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/public-api/images/resource-image.h>
-#include <dali/public-api/images/buffer-image.h>
-#include <dali/public-api/math/rect.h>
-
-namespace Dali
-{
-/**
- * @addtogroup dali_core_images
- * @{
- */
-
-namespace Internal DALI_INTERNAL
-{
-class NinePatchImage;
-}
-
-/**
- * @brief NinePatchImage represents an nine-patch image resource.
- *
- * It contains a bitmap that is synchronously loaded from the file system that contains
- * a 9 patch border - a 1 pixel border that describes the stretch borders and the child
- * area.
- *
- * The class offers an API to read the stretch area and child area, but it does not
- * remove the border from it's bitmap. An API can be used to obtain a BufferImage with
- * the border removed.
- *
- * If you don't retain a handle to this object, it will be automatically destroyed.
- * @SINCE_1_0.0
- */
-class DALI_CORE_API NinePatchImage : public ResourceImage
-{
-public:
- typedef Vector< Uint16Pair > StretchRanges;
-
-public:
- /**
- * @brief Constructor which creates an uninitialized NinePatchImage object.
- *
- * Use @ref NinePatchImage::New to create an initialised object.
- * @SINCE_1_0.0
- */
- NinePatchImage();
-
- /**
- * @brief Create a new NinePatchImage.
- *
- * A pixel buffer for image data is allocated and loaded from the filesystem.
- * Dali has ownership of the buffer.
- * @SINCE_1_0.0
- * @param [in] filename File to load synchronously into buffer
- * @return A handle to a new instance of NinePatchImage
- */
- static NinePatchImage New( const std::string& filename );
-
- /**
- * @brief Downcast a handle to NinePatchImage handle.
- *
- * If handle points to a NinePatchImage the downcast produces valid
- * handle. If not the returned handle is left uninitialized.
- *
- * @SINCE_1_0.0
- * @param[in] handle Handle to an object
- * @return Handle to a NinePatchImage or an uninitialized handle
- */
- static NinePatchImage DownCast( BaseHandle handle );
-
- /**
- * @brief Destructor
- *
- * This is non-virtual since derived Handle types must not contain data or virtual methods.
- * @SINCE_1_0.0
- */
- ~NinePatchImage();
-
- /**
- * @brief This copy constructor is required for (smart) pointer semantics.
- *
- * @SINCE_1_0.0
- * @param [in] handle A reference to the copied handle
- */
- NinePatchImage(const NinePatchImage& handle);
-
- /**
- * @brief This assignment operator is required for (smart) pointer semantics.
- *
- * @SINCE_1_0.0
- * @param [in] rhs A reference to the copied handle
- * @return A reference to this
- */
- NinePatchImage& operator=(const NinePatchImage& rhs);
-
- /**
- * @DEPRECATED_1_1.4. Use GetStretchPixelsX and GetStretchPixelsY instead.
- *
- * @brief Get the stretch borders
- *
- * @SINCE_1_0.0
- * @return The border in pixels from the left, top, right, and bottom of the image respectively.
- */
- Vector4 GetStretchBorders();
-
- /**
- * @brief Retrieves the horizontal stretch pixel ranges in the cropped image space
- *
- * @SINCE_1_1.4
- * @return the horizontal stretch pixel ranges in the cropped image space
- */
- const StretchRanges& GetStretchPixelsX();
-
- /**
- * @brief Retrieves the vertical stretch pixel ranges in the cropped image space
- *
- * @SINCE_1_1.4
- * @return the vertical stretch pixel ranges in the cropped image space
- */
- const StretchRanges& GetStretchPixelsY();
-
- /**
- * @brief Get the child rectangle
- *
- * @SINCE_1_0.0
- * @return The position and size of the child rectangle
- */
- Rect<int> GetChildRectangle();
-
- /**
- * @brief Creates a buffer image from the bitmap with the 1 pixel border cropped off.
- *
- * This does not change the internal bitmap.
- *
- * @SINCE_1_0.0
- * @return The cropped BufferImage
- */
- BufferImage CreateCroppedBufferImage();
-
- /**
- * @brief Helper method to determine if the filename indicates that the image has a 9 patch or n patch border.
- *
- * @SINCE_1_1.4
- * @param [in] url The URL of the image file.
- * @return true if it is a 9 patch or n patch image
- */
- static bool IsNinePatchUrl( const std::string& url );
-
-public: // Not intended for application developers
-
- explicit DALI_INTERNAL NinePatchImage(Internal::NinePatchImage*);
-};
-
-/**
- * @}
- */
-} // namespace Dali
-
-#endif // DALI_NINE_PATCH_IMAGE_H
+++ /dev/null
-/*
- * Copyright (c) 2018 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 <dali/internal/event/images/nine-patch-image-impl.h>
-
-// EXTERNAL INCLUDES
-#include <cstring> // for memcmp
-
-// INTERNAL INCLUDES
-#include <dali/public-api/object/type-registry.h>
-#include <dali/integration-api/bitmap.h>
-#include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/update/manager/update-manager.h>
-#include <dali/integration-api/platform-abstraction.h>
-#include <dali/integration-api/resource-types.h>
-
-
-namespace
-{
-void GetRedOffsetAndMask(Dali::Pixel::Format pixelFormat, int& byteOffset, int& bitMask)
-{
- switch (pixelFormat)
- {
- case Dali::Pixel::A8:
- case Dali::Pixel::L8:
- case Dali::Pixel::LA88:
- {
- byteOffset=0;
- bitMask=0;
- break;
- }
-
- case Dali::Pixel::RGB888:
- case Dali::Pixel::RGB8888:
- case Dali::Pixel::RGBA8888:
- {
- byteOffset=0;
- bitMask=0xFF;
- break;
- }
- case Dali::Pixel::BGR8888:
- case Dali::Pixel::BGRA8888:
- {
- byteOffset=2;
- bitMask=0xff;
- break;
- }
- case Dali::Pixel::RGB565:
- {
- byteOffset=0;
- bitMask=0xf8;
- break;
- }
- case Dali::Pixel::BGR565:
- {
- byteOffset=1;
- bitMask=0x1f;
- break;
- }
-
- case Dali::Pixel::RGBA4444:
- {
- byteOffset=0;
- bitMask=0xf0;
- break;
- }
- case Dali::Pixel::BGRA4444:
- {
- byteOffset=1;
- bitMask=0xf0;
- break;
- }
-
- case Dali::Pixel::RGBA5551:
- {
- byteOffset=0;
- bitMask=0xf8;
- break;
- }
-
- case Dali::Pixel::BGRA5551:
- {
- byteOffset=1;
- bitMask=0x1e;
- break;
- }
-
- case Dali::Pixel::INVALID:
- case Dali::Pixel::COMPRESSED_R11_EAC:
- case Dali::Pixel::COMPRESSED_SIGNED_R11_EAC:
- case Dali::Pixel::COMPRESSED_RG11_EAC:
- case Dali::Pixel::COMPRESSED_SIGNED_RG11_EAC:
- case Dali::Pixel::COMPRESSED_RGB8_ETC2:
- case Dali::Pixel::COMPRESSED_SRGB8_ETC2:
- case Dali::Pixel::COMPRESSED_RGB8_ETC1:
- case Dali::Pixel::COMPRESSED_RGB_PVRTC_4BPPV1:
- case Dali::Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
- case Dali::Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
- case Dali::Pixel::COMPRESSED_RGBA8_ETC2_EAC:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR:
- case Dali::Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
- case Dali::Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
- {
- DALI_LOG_ERROR("Pixel formats for compressed images are not compatible with simple masking-out of per-pixel alpha.\n");
- byteOffset=0;
- bitMask=0;
- break;
- }
-
- case Dali::Pixel::RGB16F:
- case Dali::Pixel::RGB32F:
- case Dali::Pixel::DEPTH_UNSIGNED_INT:
- case Dali::Pixel::DEPTH_FLOAT:
- case Dali::Pixel::DEPTH_STENCIL:
- {
- DALI_LOG_ERROR("Pixel format not compatible.\n");
- byteOffset=0;
- bitMask=0;
- break;
- }
- }
-}
-
-} // anonymous namespace
-
-
-namespace Dali
-{
-namespace Internal
-{
-
-NinePatchImagePtr NinePatchImage::New( const std::string& filename )
-{
- Internal::NinePatchImagePtr internal( new NinePatchImage( filename ) );
- internal->Initialize();
- return internal;
-}
-
-NinePatchImage::NinePatchImage( const std::string& filename )
-: ResourceImage(),
- mParsedBorder(false)
-{
- mUrl = filename;
- ThreadLocalStorage& tls = ThreadLocalStorage::Get();
-
- Integration::PlatformAbstraction& platformAbstraction = tls.GetPlatformAbstraction();
- Integration::BitmapResourceType resourceType;
-
- // Note, bitmap is only destroyed when the image is destroyed.
- Integration::ResourcePointer resource = platformAbstraction.LoadImageSynchronously( resourceType, filename );
- if( resource )
- {
- mBitmap = static_cast<Integration::Bitmap*>( resource.Get());
-
- mWidth = mBitmap->GetImageWidth();
- mHeight = mBitmap->GetImageHeight();
- mTexture = Texture::New( Dali::TextureType::TEXTURE_2D, mBitmap->GetPixelFormat(), mWidth, mHeight );
-
- uint32_t bufferSize = mBitmap->GetBufferSize();
- uint8_t* buffer = new uint8_t[bufferSize];
- memcpy( buffer, mBitmap->GetBuffer(), bufferSize );
- PixelDataPtr pixelData = PixelData::New( buffer, bufferSize, mWidth, mHeight, mBitmap->GetPixelFormat(), Dali::PixelData::DELETE_ARRAY );
- mTexture->Upload( pixelData );
- }
- else
- {
- mBitmap.Reset();
- mWidth = 0;
- mHeight = 0;
- }
-}
-
-NinePatchImage* NinePatchImage::DownCast( Image* image)
-{
- return dynamic_cast<NinePatchImage*>(image);
-}
-
-NinePatchImage::~NinePatchImage()
-{
-}
-
-const NinePatchImage::StretchRanges& NinePatchImage::GetStretchPixelsX()
-{
- if( ! mParsedBorder )
- {
- ParseBorders();
- }
- return mStretchPixelsX;
-}
-
-const NinePatchImage::StretchRanges& NinePatchImage::GetStretchPixelsY()
-{
- if( ! mParsedBorder )
- {
- ParseBorders();
- }
- return mStretchPixelsY;
-}
-
-Rect<int> NinePatchImage::GetChildRectangle()
-{
- if( ! mParsedBorder )
- {
- ParseBorders();
- }
- return mChildRectangle;
-}
-
-Internal::BufferImagePtr NinePatchImage::CreateCroppedBufferImage()
-{
- BufferImagePtr cropped;
-
- if( ! mBitmap )
- {
- DALI_LOG_ERROR( "NinePatchImage: Bitmap not loaded, cannot perform operation\n");
- }
- else
- {
- Pixel::Format pixelFormat = mBitmap->GetPixelFormat();
-
- cropped = BufferImage::New( mWidth-2, mHeight-2, pixelFormat );
-
- Integration::Bitmap::PackedPixelsProfile* srcProfile = mBitmap->GetPackedPixelsProfile();
- DALI_ASSERT_DEBUG( srcProfile && "Wrong profile for source bitmap");
-
- if( srcProfile )
- {
- PixelBuffer* destPixels = cropped->GetBuffer();
- uint32_t destStride = cropped->GetBufferStride();
- uint32_t pixelWidth = GetBytesPerPixel(pixelFormat);
-
- PixelBuffer* srcPixels = mBitmap->GetBuffer();
- uint32_t srcStride = srcProfile->GetBufferStride();
-
- for( uint32_t row=1; row < mHeight-1; ++row )
- {
- PixelBuffer* src = srcPixels + row*srcStride + pixelWidth;
- PixelBuffer* dest = destPixels + (row-1)*destStride;
- memcpy(dest, src, destStride );
- }
- }
-
- RectArea area;
- cropped->Update(area); // default area has no width or height
- }
- return cropped;
-}
-
-const std::string& NinePatchImage::GetUrl() const
-{
- return mUrl;
-}
-
-void NinePatchImage::ParseBorders()
-{
- if( !mBitmap )
- {
- DALI_LOG_ERROR( "NinePatchImage: Bitmap not loaded, cannot perform operation\n");
- return;
- }
-
- mStretchPixelsX.Clear();
- mStretchPixelsY.Clear();
-
- Pixel::Format pixelFormat = mBitmap->GetPixelFormat();
-
- const Integration::Bitmap::PackedPixelsProfile* srcProfile = mBitmap->GetPackedPixelsProfile();
- DALI_ASSERT_DEBUG( srcProfile && "Wrong profile for source bitmap" );
-
- if( srcProfile )
- {
- int alphaByte = 0;
- int alphaBits = 0;
- Pixel::GetAlphaOffsetAndMask( pixelFormat, alphaByte, alphaBits );
-
- int testByte = alphaByte;
- int testBits = alphaBits;
- int testValue = alphaBits; // Opaque == stretch
- if( ! alphaBits )
- {
- GetRedOffsetAndMask( pixelFormat, testByte, testBits );
- testValue = 0; // Black == stretch
- }
-
- uint32_t pixelWidth = GetBytesPerPixel( pixelFormat );
- const PixelBuffer* srcPixels = mBitmap->GetBuffer();
- uint32_t srcStride = srcProfile->GetBufferStride();
-
- //TOP
- const PixelBuffer* top = srcPixels + pixelWidth;
- uint32_t index = 0;
- uint32_t width = mBitmap->GetImageWidth();
- uint32_t height = mBitmap->GetImageHeight();
-
- for(; index < width - 2; )
- {
- Uint16Pair range = ParseRange( index, width - 2, top, pixelWidth, testByte, testBits, testValue );
- if( range.GetX() != 0xFFFF )
- {
- mStretchPixelsX.PushBack( range );
- }
- }
-
- //LEFT
- const PixelBuffer* left = srcPixels + srcStride;
- index = 0;
- for(; index < height - 2; )
- {
- Uint16Pair range = ParseRange( index, height - 2, left, srcStride, testByte, testBits, testValue );
- if( range.GetX() != 0xFFFF )
- {
- mStretchPixelsY.PushBack( range );
- }
- }
-
- //If there are no stretch pixels then make the entire image stretchable
- if( mStretchPixelsX.Size() == 0 )
- {
- mStretchPixelsX.PushBack( Uint16Pair( 0, width - 2 ) );
- }
- if( mStretchPixelsY.Size() == 0 )
- {
- mStretchPixelsY.PushBack( Uint16Pair( 0, height - 2 ) );
- }
-
- //Child Rectangle
- //BOTTOM
- const PixelBuffer* bottom = srcPixels + ( height - 1 ) * srcStride + pixelWidth;
- index = 0;
- Uint16Pair contentRangeX = ParseRange( index, width - 2, bottom, pixelWidth, testByte, testBits, testValue );
- if( contentRangeX.GetX() == 0xFFFF )
- {
- contentRangeX = Uint16Pair();
- }
-
- //RIGHT
- const PixelBuffer* right = srcPixels + srcStride + ( width - 1 ) * pixelWidth;
- index = 0;
- Uint16Pair contentRangeY = ParseRange( index, height - 2, right, srcStride, testByte, testBits, testValue );
- if( contentRangeY.GetX() == 0xFFFF )
- {
- contentRangeY = Uint16Pair();
- }
-
- mChildRectangle.x = contentRangeX.GetX() + 1;
- mChildRectangle.y = contentRangeY.GetX() + 1;
- mChildRectangle.width = contentRangeX.GetY() - contentRangeX.GetX();
- mChildRectangle.height = contentRangeY.GetY() - contentRangeY.GetX();
-
- mParsedBorder = true;
- }
-}
-
-Uint16Pair NinePatchImage::ParseRange( uint32_t& index, uint32_t width, const PixelBuffer* & pixel, uint32_t pixelStride, int testByte, int testBits, int testValue )
-{
- uint32_t start = 0xFFFF;
- for( ; index < width; ++index, pixel += pixelStride )
- {
- if( ( pixel[ testByte ] & testBits ) == testValue )
- {
- start = index;
- ++index;
- pixel += pixelStride;
- break;
- }
- }
-
- uint32_t end = width;
- for( ; index < width; ++index, pixel += pixelStride )
- {
- if( ( pixel[ testByte ] & testBits ) != testValue )
- {
- end = index;
- ++index;
- pixel += pixelStride;
- break;
- }
- }
-
- return Uint16Pair( start, end );
-}
-
-bool NinePatchImage::IsNinePatchUrl( const std::string& url )
-{
- bool match = false;
-
- std::string::const_reverse_iterator iter = url.rbegin();
- enum { SUFFIX, HASH, HASH_DOT, DONE } state = SUFFIX;
- while(iter < url.rend())
- {
- switch(state)
- {
- case SUFFIX:
- {
- if(*iter == '.')
- {
- state = HASH;
- }
- else if(!isalnum(*iter))
- {
- state = DONE;
- }
- }
- break;
- case HASH:
- {
- if( *iter == '#' || *iter == '9' )
- {
- state = HASH_DOT;
- }
- else
- {
- state = DONE;
- }
- }
- break;
- case HASH_DOT:
- {
- if(*iter == '.')
- {
- match = true;
- }
- state = DONE; // Stop testing characters
- }
- break;
- case DONE:
- {
- }
- break;
- }
-
- // Satisfy prevent
- if( state == DONE )
- {
- break;
- }
-
- ++iter;
- }
- return match;
-}
-
-} // namespace Internal
-
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_INTERNAL_NINE_PATCH_IMAGE_H
-#define DALI_INTERNAL_NINE_PATCH_IMAGE_H
-
-/*
- * Copyright (c) 2019 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.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/devel-api/images/nine-patch-image.h>
-#include <dali/internal/event/images/resource-image-impl.h>
-#include <dali/internal/event/images/buffer-image-impl.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-class NinePatchImage;
-typedef IntrusivePtr<NinePatchImage> NinePatchImagePtr;
-
-namespace SceneGraph
-{
-class UpdateManager;
-}
-
-/**
- * NinePatchImage represents an image resource that can be added to actors etc.
- * It's image data has a border which determines stretch and fill areas
- * Its pixel buffer data is loaded synchronously from file.
- */
-class NinePatchImage : public ResourceImage
-{
-public:
- typedef Dali::Vector< Uint16Pair > StretchRanges;
-
-public:
-
- /**
- * Create a new NinePatchImage.
- * Also a pixel buffer for image data is allocated.
- * Dali has ownership of the buffer.
- * @param [in] filename File to load synchronously into buffer
- */
- static NinePatchImagePtr New( const std::string& filename );
-
- /**
- * Create a new NinePatchImage
- * For better performance and portability use power of two dimensions.
- * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
- * @param [in] filename File to load synchronously into buffer
- */
- NinePatchImage( const std::string& filename );
-
- /**
- * Convert Image object to a 9 patch image object if possible.
- * @param[in] image The image to convert
- * @return A pointer to the 9 patch image object, or NULL
- * if the conversion is not possible.
- */
- static NinePatchImage* DownCast( Image* image);
-
-
-protected:
- /**
- * A reference counted object may only be deleted by calling Unreference()
- */
- virtual ~NinePatchImage();
-
-public:
- /**
- * @copydoc Dali::NinePatchImage::GetStretchPixelsX
- */
- const StretchRanges& GetStretchPixelsX();
-
- /**
- * @copydoc Dali::NinePatchImage::GetStretchPixelsY
- */
- const StretchRanges& GetStretchPixelsY();
-
- /**
- * Get the child rectangle
- * @return the position and size of the child rectangle
- */
- Rect<int> GetChildRectangle();
-
- /**
- * @brief Create a cropped image from the bitmap with the 1 pixel border cropped off.
- * This does not change the internal bitmap.
- *
- * @return the cropped bitmap.
- */
- BufferImagePtr CreateCroppedBufferImage();
-
- /**
- *
- * @copydoc Dali::NinePatchImage::
- */
- static bool IsNinePatchUrl( const std::string& url );
-
-private: // from ResourceImage
-
- /**
- * @copydoc ResourceImage::GetUrl()
- */
- virtual const std::string& GetUrl() const;
-
- /**
- * Read the borders of the bitmap and determine the child area
- * and stretch borders
- */
- void ParseBorders();
-
- Uint16Pair ParseRange( unsigned int& index, unsigned int width, const PixelBuffer* & pixel, unsigned int pixelStride, int testByte, int testBits, int testValue );
-
-private:
- Integration::BitmapPtr mBitmap;
- std::string mUrl;
- StretchRanges mStretchPixelsX; //< The horizontal stretchable pixels in the cropped image space
- StretchRanges mStretchPixelsY; //< The vertical stretchable pixels in the cropped image space
- Rect<int> mChildRectangle;
- bool mParsedBorder;
-};
-
-} // namespace Internal
-
-/**
- * Helper methods for public API.
- */
-inline Internal::NinePatchImage& GetImplementation(Dali::NinePatchImage& handle)
-{
- DALI_ASSERT_ALWAYS( handle && "NinePatchImage handle is empty" );
-
- BaseObject& image = handle.GetBaseObject();
-
- return static_cast<Internal::NinePatchImage&>(image);
-}
-
-inline const Internal::NinePatchImage& GetImplementation(const Dali::NinePatchImage& handle)
-{
- DALI_ASSERT_ALWAYS( handle && "NinePatchImage handle is empty" );
-
- const BaseObject& image = handle.GetBaseObject();
-
- return static_cast<const Internal::NinePatchImage&>(image);
-}
-
-} // namespace Dali
-
-#endif // DALI_INTERNAL_NINE_PATCH_IMAGE_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
#include <dali/integration-api/debug.h>
#include <dali/integration-api/platform-abstraction.h>
#include <dali/internal/event/common/thread-local-storage.h>
-#include <dali/internal/event/images/nine-patch-image-impl.h>
#include <dali/internal/event/common/stage-impl.h>
using namespace Dali::Integration;
ResourceImagePtr ResourceImage::New( const std::string& url, const ImageAttributes& attributes )
{
ResourceImagePtr image;
-
- if( NinePatchImage::IsNinePatchUrl( url ) )
- {
- image = NinePatchImage::New( url );
- }
- else
- {
- image = new ResourceImage(url, attributes);
- image->Initialize();
- image->Reload();
- }
+ image = new ResourceImage(url, attributes);
+ image->Initialize();
+ image->Reload();
DALI_LOG_SET_OBJECT_STRING( image, url );
${internal_src_dir}/event/images/image-impl.cpp
${internal_src_dir}/event/images/buffer-image-impl.cpp
${internal_src_dir}/event/images/frame-buffer-image-impl.cpp
- ${internal_src_dir}/event/images/nine-patch-image-impl.cpp
${internal_src_dir}/event/images/resource-image-impl.cpp
${internal_src_dir}/event/images/native-image-impl.cpp
${internal_src_dir}/event/images/pixel-data-impl.cpp