void ImageActor::SetDefaultProperty( Property::Index index, const Property::Value& propertyValue ) { if(index < DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT) { RenderableActor::SetDefaultProperty(index, propertyValue); } else { switch(index) { case Dali::ImageActor::PIXEL_AREA: { SetPixelArea(propertyValue.Get<Rect<int> >()); break; } case Dali::ImageActor::FADE_IN: { SetFadeIn(propertyValue.Get<bool>()); break; } case Dali::ImageActor::FADE_IN_DURATION: { SetFadeInDuration(propertyValue.Get<float>()); break; } case Dali::ImageActor::STYLE: { SetStyle(StyleEnum(propertyValue.Get<std::string>())); break; } case Dali::ImageActor::BORDER: { SetNinePatchBorder( propertyValue.Get<Vector4>(), true /*in pixels*/ ); break; } case Dali::ImageActor::IMAGE: { Dali::Image img = Scripting::NewImage( propertyValue ); if(img) { SetImage( &GetImplementation(img) ); } else { DALI_LOG_WARNING("Cannot create image from property value\n"); } break; } default: { DALI_LOG_WARNING("Unknown property (%d)\n", index); break; } } // switch(index) } // else }
bool ConvertStreamToBitmap( const ResourceType& resourceType, std::string path, FILE * const fp, const ResourceLoadingClient& client, BitmapPtr& ptr ) { DALI_LOG_TRACE_METHOD( gLogFilter ); DALI_ASSERT_DEBUG( ResourceBitmap == resourceType.id ); bool result = false; BitmapPtr bitmap = 0; if (fp != NULL) { LoadBitmapFunction function; LoadBitmapHeaderFunction header; Bitmap::Profile profile; if ( GetBitmapLoaderFunctions( fp, GetFormatHint( path ), function, header, profile ) ) { bitmap = Bitmap::New( profile, ResourcePolicy::OWNED_DISCARD ); DALI_LOG_SET_OBJECT_STRING( bitmap, path ); const BitmapResourceType& resType = static_cast<const BitmapResourceType&>( resourceType ); const ScalingParameters scalingParameters( resType.size, resType.scalingMode, resType.samplingMode ); const ImageLoader::Input input( fp, scalingParameters, resType.orientationCorrection ); // Check for cancellation now we have hit the filesystem, done some allocation, and burned some cycles: // This won't do anything from synchronous API, it's only useful when called from another thread. client.InterruptionPoint(); // Note: By design, this can throw an exception // Run the image type decoder: result = function( client, input, *bitmap ); if (!result) { DALI_LOG_WARNING( "Unable to convert %s\n", path.c_str() ); bitmap = 0; } // Apply the requested image attributes if not interrupted: client.InterruptionPoint(); // Note: By design, this can throw an exception bitmap = Internal::Platform::ApplyAttributesToBitmap( bitmap, resType.size, resType.scalingMode, resType.samplingMode ); } else { DALI_LOG_WARNING( "Image Decoder for %s unavailable\n", path.c_str() ); } } ptr.Reset( bitmap.Get() ); return result; }
Property::Value& Property::Value::GetValue(const std::string& key) const { DALI_ASSERT_DEBUG(Property::MAP == GetType() && "Property type invalid"); Property::Map *container = AnyCast<Property::Map>(&(mImpl->mValue)); DALI_ASSERT_DEBUG(container); if(container) { for(Property::Map::iterator iter = container->begin(); iter != container->end(); ++iter) { if(iter->first == key) { return iter->second; } } } DALI_LOG_WARNING("Cannot find property map key %s", key.c_str()); DALI_ASSERT_ALWAYS(!"Cannot find property map key"); // should never return this static Property::Value null; return null; }
bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_info& baseTypeInfo, Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit ) { bool ret = false; std::string baseTypeName = DemangleClassName(baseTypeInfo.name()); RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName); if( iter == mRegistryLut.end() ) { mRegistryLut[uniqueTypeName] = Dali::TypeInfo(new Internal::TypeInfo(uniqueTypeName, baseTypeName, createInstance)); ret = true; DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str()); } else { DALI_LOG_WARNING("Duplicate name for TypeRegistry for '%s'\n", + uniqueTypeName.c_str()); DALI_ASSERT_ALWAYS(!"Duplicate type name for Type Registation"); } if( callCreateOnInit ) { mInitFunctions.push_back(createInstance); } return ret; }
Property::Value ImageActor::GetDefaultProperty( Property::Index index ) const { Property::Value ret; if(index < DEFAULT_RENDERABLE_ACTOR_PROPERTY_MAX_COUNT) { ret = RenderableActor::GetDefaultProperty(index); } else { switch(index) { case Dali::ImageActor::PIXEL_AREA: { Rect<int> r = GetPixelArea(); ret = r; break; } case Dali::ImageActor::FADE_IN: { ret = GetFadeIn(); break; } case Dali::ImageActor::FADE_IN_DURATION: { ret = GetFadeInDuration(); break; } case Dali::ImageActor::STYLE: { ret = StyleString(GetStyle()); break; } case Dali::ImageActor::BORDER: { ret = GetNinePatchBorder(); break; } case Dali::ImageActor::IMAGE: { Property::Map map; Scripting::CreatePropertyMap( mImageAttachment->GetImage(), map ); ret = Property::Value( map ); break; } default: { DALI_LOG_WARNING("Unknown property (%d)\n", index); break; } } // switch(index) } return ret; }
///@ToDo: Rename GetClosestImageSize() functions. Make them use the orientation correction and scaling information. Requires jpeg loader to tell us about reorientation. [Is there still a requirement for this functionality at all?] ImageDimensions GetClosestImageSize( const std::string& filename, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection ) { unsigned int width = 0; unsigned int height = 0; Internal::Platform::FileCloser fc(filename.c_str(), "rb"); FILE *fp = fc.GetFile(); if (fp != NULL) { LoadBitmapFunction loaderFunction; LoadBitmapHeaderFunction headerFunction; Bitmap::Profile profile; if ( GetBitmapLoaderFunctions( fp, GetFormatHint(filename), loaderFunction, headerFunction, profile ) ) { const ImageLoader::Input input( fp, ScalingParameters( size, fittingMode, samplingMode ), orientationCorrection ); const bool read_res = headerFunction( input, width, height ); if(!read_res) { DALI_LOG_WARNING("Image Decoder failed to read header for %s\n", filename.c_str()); } } else { DALI_LOG_WARNING("Image Decoder for %s unavailable\n", filename.c_str()); } } return ImageDimensions( width, height ); }
ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer, ImageDimensions size, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection ) { unsigned int width = 0; unsigned int height = 0; // Get the blob of binary data that we need to decode: DALI_ASSERT_DEBUG( resourceBuffer ); Dali::RefCountedVector<uint8_t>* const encodedBlob = reinterpret_cast<Dali::RefCountedVector<uint8_t>*>( resourceBuffer.Get() ); if( encodedBlob != 0 ) { const size_t blobSize = encodedBlob->GetVector().Size(); uint8_t * const blobBytes = &(encodedBlob->GetVector()[0]); DALI_ASSERT_DEBUG( blobSize > 0U ); DALI_ASSERT_DEBUG( blobBytes != 0U ); if( blobBytes != 0 && blobSize > 0U ) { // Open a file handle on the memory buffer: Internal::Platform::FileCloser fc( blobBytes, blobSize, "rb" ); FILE *fp = fc.GetFile(); if ( fp != NULL ) { LoadBitmapFunction loaderFunction; LoadBitmapHeaderFunction headerFunction; Bitmap::Profile profile; if ( GetBitmapLoaderFunctions( fp, FORMAT_UNKNOWN, loaderFunction, headerFunction, profile ) ) { const ImageLoader::Input input( fp, ScalingParameters( size, fittingMode, samplingMode ), orientationCorrection ); const bool read_res = headerFunction( input, width, height ); if( !read_res ) { DALI_LOG_WARNING( "Image Decoder failed to read header for resourceBuffer\n" ); } } } } } return ImageDimensions( width, height ); }
void DaliWrapper::Shutdown() { // if we're running inside node then we don't have ownership of the context if( mRunMode == RUNNING_IN_NODE_JS ) { return; } DALI_LOG_WARNING("Destroying V8 DALi context\n"); if( !mContext.IsEmpty()) { v8::HandleScope handleScope( mIsolate ); v8::Local<v8::Context> context = v8::Local<v8::Context>::New(mIsolate, mContext); context->Exit(); // exit the context mContext.Reset(); // destroys the context } }
bool Network::DownloadRemoteFileIntoMemory( const std::string& url, Dali::Vector<uint8_t>& dataBuffer, size_t& dataSize, size_t maximumAllowedSizeBytes ) { if( url.empty() ) { DALI_LOG_WARNING("empty url requested \n"); return false; } // start a libcurl easy session, this internally calls curl_global_init, if we ever have more than one download // thread we need to explicity call curl_global_init() on startup from a single thread. CURL* curl_handle = curl_easy_init(); bool result = DownloadFile( curl_handle, url, dataBuffer, dataSize, maximumAllowedSizeBytes); // clean up session curl_easy_cleanup( curl_handle ); return result; }
bool LoadBitmapFromPng( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap ) { png_structp png = NULL; png_infop info = NULL; auto_png autoPng(png, info); /// @todo: consider parameters unsigned int y; unsigned int width, height; unsigned char *pixels; png_bytep *rows; unsigned int bpp = 0; // bytes per pixel bool valid = false; // Load info from the header if( !LoadPngHeader( input.file, width, height, png, info ) ) { return false; } Pixel::Format pixelFormat = Pixel::RGBA8888; // decide pixel format unsigned int colordepth = png_get_bit_depth(png, info); // Ask PNGLib to convert high precision images into something we can use: if (colordepth == 16) { png_set_strip_16(png); colordepth = 8; } png_byte colortype = png_get_color_type(png, info); if(colortype == PNG_COLOR_TYPE_GRAY) { switch( colordepth ) { case 8: { pixelFormat = Pixel::L8; valid = true; break; } default: { break; } } } else if(colortype == PNG_COLOR_TYPE_GRAY_ALPHA) { switch(colordepth) { case 8: { pixelFormat = Pixel::LA88; valid = true; break; } default: { break; } } } else if(colortype == PNG_COLOR_TYPE_RGB ) { switch(colordepth) { case 8: { pixelFormat = Pixel::RGB888; valid = true; break; } case 5: /// @todo is this correct for RGB16 5-6-5 ? { pixelFormat = Pixel::RGB565; valid = true; break; } default: { break; } } } else if(colortype == PNG_COLOR_TYPE_RGBA) { switch(colordepth) { case 8: { pixelFormat = Pixel::RGBA8888; valid = true; break; } default: { break; } } } else if(colortype == PNG_COLOR_TYPE_PALETTE) { switch(colordepth) { case 2: case 4: case 8: { /* Expand paletted or RGB images with transparency to full alpha channels * so the data will be available as RGBA quartets. PNG_INFO_tRNS = 0x10 */ if(png_get_valid(png, info, PNG_INFO_tRNS) == 0x10) { pixelFormat = Pixel::RGBA8888; valid = true; } else { pixelFormat = Pixel::RGB888; png_set_packing(png); png_set_packswap(png); png_set_palette_to_rgb(png); valid = true; } break; } default: { break; } } } if( !valid ) { DALI_LOG_WARNING( "Unsupported png format\n" ); return false; } // bytes per pixel bpp = Pixel::GetBytesPerPixel(pixelFormat); png_read_update_info(png, info); if(setjmp(png_jmpbuf(png))) { DALI_LOG_WARNING("error during png_read_image\n"); return false; } unsigned int rowBytes = png_get_rowbytes(png, info); unsigned int bufferWidth = GetTextureDimension(width); unsigned int bufferHeight = GetTextureDimension(height); unsigned int stride = bufferWidth*bpp; // not sure if this ever happens if( rowBytes > stride ) { stride = GetTextureDimension(rowBytes); bufferWidth = stride / bpp; } // decode the whole image into bitmap buffer pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(pixelFormat, width, height, bufferWidth, bufferHeight); DALI_ASSERT_DEBUG(pixels); rows = (png_bytep*) malloc(sizeof(png_bytep) * height); for(y=0; y<height; y++) { rows[y] = (png_byte*) (pixels + y * stride); } // decode image png_read_image(png, rows); free(rows); return true; }