2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "frame-buffer-image-api.h"
22 #include <dali/public-api/images/frame-buffer-image.h>
26 #include <image/image-wrapper.h>
34 namespace FrameBufferImageApi
38 * FrameBufferImage represents a GLES Frame Buffer Object and contains the result
39 * of an 'off screen' render pass of a RenderTask.
40 * The FrameBufferImage can then be used with a Material (with optional shader
41 * effects) and rendered to the screen.
42 * @class FrameBufferImage
48 * @method FrameBufferImage
49 * @for FrameBufferImage
50 * @param {Object} options
51 * @param {Uint32Array} options.pixelBuffer Array of RGBA pixel data
52 * @param {Integer} options.width image width
53 * @param {Integer} options.height image height
54 * @param {Object } [options.nativeImage] ** currently not supported **
55 * @param {Integer} [options.pixelFormat] pixel format ( see dali constants, e.g. dali.PIXEL_FORMAT_RGB8888)
56 * @return {Object} Image
58 Image New( const v8::FunctionCallbackInfo< v8::Value >& args )
60 v8::Isolate* isolate = args.GetIsolate();
61 v8::HandleScope handleScope( isolate );
63 v8::Local<v8::Value> options( args[0] );
64 if( !options->IsObject() )
66 DALI_SCRIPT_EXCEPTION( isolate, "Missing param");
67 return FrameBufferImage();
70 v8::Local<v8::Object> obj = options->ToObject();
72 v8::Local<v8::Value> widthValue = obj->Get( v8::String::NewFromUtf8( isolate, "width" ) );
73 v8::Local<v8::Value> heightValue= obj->Get( v8::String::NewFromUtf8( isolate, "height" ) );
75 unsigned int width = 0;
76 unsigned int height = 0;
78 if( widthValue->IsUint32() && heightValue->IsUint32() )
80 width = widthValue->ToUint32()->Value();
81 height = heightValue->ToUint32()->Value();
85 DALI_SCRIPT_EXCEPTION( isolate, "Missing valid width and height params");
86 return FrameBufferImage();
89 Pixel::Format pixelFormat = Pixel::RGB8888;
90 v8::Local<v8::Value> pixelFormatValue = obj->Get( v8::String::NewFromUtf8( isolate, "pixelFormat" ) );
91 if( pixelFormatValue->IsUint32() )
93 pixelFormat = static_cast<Pixel::Format>( pixelFormatValue->ToUint32()->Value() );
97 DALI_SCRIPT_EXCEPTION( isolate, "Pixel format not specified");
98 return FrameBufferImage();
101 return FrameBufferImage::New( width, height, pixelFormat );
104 } // FrameBufferImageApi
106 } // namespace V8Plugin