6eddb5c6406e99341f7524832b3c0211cff54588
[platform/core/uifw/dali-core.git] / dali / public-api / scripting / scripting.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/scripting/scripting.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/actors/actor.h>
23 #include <dali/public-api/images/resource-image.h>
24 #include <dali/public-api/images/image-attributes.h>
25 #include <dali/public-api/object/type-registry.h>
26 #include <dali/internal/event/images/resource-image-impl.h>
27 #include <dali/internal/event/images/frame-buffer-image-impl.h>
28 #include <dali/internal/event/images/bitmap-image-impl.h>
29 #include <dali/internal/event/effects/shader-effect-impl.h>
30
31 namespace Dali
32 {
33
34 namespace Scripting
35 {
36
37 namespace
38 {
39
40 // Tables used here for converting strings to the enumerations and vice versa
41
42 const StringEnum< ColorMode > COLOR_MODE_TABLE[] =
43 {
44   { "USE_OWN_COLOR",                    USE_OWN_COLOR                    },
45   { "USE_PARENT_COLOR",                 USE_PARENT_COLOR                 },
46   { "USE_OWN_MULTIPLY_PARENT_COLOR",    USE_OWN_MULTIPLY_PARENT_COLOR    },
47   { "USE_OWN_MULTIPLY_PARENT_ALPHA",    USE_OWN_MULTIPLY_PARENT_ALPHA    },
48 };
49 const unsigned int COLOR_MODE_TABLE_COUNT = sizeof( COLOR_MODE_TABLE ) / sizeof( COLOR_MODE_TABLE[0] );
50
51 const StringEnum< PositionInheritanceMode > POSITION_INHERITANCE_MODE_TABLE[] =
52 {
53   { "INHERIT_PARENT_POSITION",                    INHERIT_PARENT_POSITION                    },
54   { "USE_PARENT_POSITION",                        USE_PARENT_POSITION                        },
55   { "USE_PARENT_POSITION_PLUS_LOCAL_POSITION",    USE_PARENT_POSITION_PLUS_LOCAL_POSITION    },
56   { "DONT_INHERIT_POSITION",                      DONT_INHERIT_POSITION                      },
57 };
58 const unsigned int POSITION_INHERITANCE_MODE_TABLE_COUNT = sizeof( POSITION_INHERITANCE_MODE_TABLE ) / sizeof( POSITION_INHERITANCE_MODE_TABLE[0] );
59
60 const StringEnum< DrawMode::Type > DRAW_MODE_TABLE[] =
61 {
62   { "NORMAL",     DrawMode::NORMAL     },
63   { "OVERLAY",    DrawMode::OVERLAY    },
64   { "STENCIL",    DrawMode::STENCIL    },
65 };
66 const unsigned int DRAW_MODE_TABLE_COUNT = sizeof( DRAW_MODE_TABLE ) / sizeof( DRAW_MODE_TABLE[0] );
67
68 const StringEnum< Vector3 > ANCHOR_CONSTANT_TABLE[] =
69 {
70   { "BACK_TOP_LEFT",          ParentOrigin::BACK_TOP_LEFT          },
71   { "BACK_TOP_CENTER",        ParentOrigin::BACK_TOP_CENTER        },
72   { "BACK_TOP_RIGHT",         ParentOrigin::BACK_TOP_RIGHT         },
73   { "BACK_CENTER_LEFT",       ParentOrigin::BACK_CENTER_LEFT       },
74   { "BACK_CENTER",            ParentOrigin::BACK_CENTER            },
75   { "BACK_CENTER_RIGHT",      ParentOrigin::BACK_CENTER_RIGHT      },
76   { "BACK_BOTTOM_LEFT",       ParentOrigin::BACK_BOTTOM_LEFT       },
77   { "BACK_BOTTOM_CENTER",     ParentOrigin::BACK_BOTTOM_CENTER     },
78   { "BACK_BOTTOM_RIGHT",      ParentOrigin::BACK_BOTTOM_RIGHT      },
79   { "TOP_LEFT",               ParentOrigin::TOP_LEFT               },
80   { "TOP_CENTER",             ParentOrigin::TOP_CENTER             },
81   { "TOP_RIGHT",              ParentOrigin::TOP_RIGHT              },
82   { "CENTER_LEFT",            ParentOrigin::CENTER_LEFT            },
83   { "CENTER",                 ParentOrigin::CENTER                 },
84   { "CENTER_RIGHT",           ParentOrigin::CENTER_RIGHT           },
85   { "BOTTOM_LEFT",            ParentOrigin::BOTTOM_LEFT            },
86   { "BOTTOM_CENTER",          ParentOrigin::BOTTOM_CENTER          },
87   { "BOTTOM_RIGHT",           ParentOrigin::BOTTOM_RIGHT           },
88   { "FRONT_TOP_LEFT",         ParentOrigin::FRONT_TOP_LEFT         },
89   { "FRONT_TOP_CENTER",       ParentOrigin::FRONT_TOP_CENTER       },
90   { "FRONT_TOP_RIGHT",        ParentOrigin::FRONT_TOP_RIGHT        },
91   { "FRONT_CENTER_LEFT",      ParentOrigin::FRONT_CENTER_LEFT      },
92   { "FRONT_CENTER",           ParentOrigin::FRONT_CENTER           },
93   { "FRONT_CENTER_RIGHT",     ParentOrigin::FRONT_CENTER_RIGHT     },
94   { "FRONT_BOTTOM_LEFT",      ParentOrigin::FRONT_BOTTOM_LEFT      },
95   { "FRONT_BOTTOM_CENTER",    ParentOrigin::FRONT_BOTTOM_CENTER    },
96   { "FRONT_BOTTOM_RIGHT",     ParentOrigin::FRONT_BOTTOM_RIGHT     },
97 };
98 const unsigned int ANCHOR_CONSTANT_TABLE_COUNT = sizeof( ANCHOR_CONSTANT_TABLE ) / sizeof( ANCHOR_CONSTANT_TABLE[0] );
99
100 const StringEnum< ResourceImage::LoadPolicy > IMAGE_LOAD_POLICY_TABLE[] =
101 {
102   { "IMMEDIATE", ResourceImage::IMMEDIATE },
103   { "ON_DEMAND", ResourceImage::ON_DEMAND },
104 };
105 const unsigned int IMAGE_LOAD_POLICY_TABLE_COUNT = sizeof( IMAGE_LOAD_POLICY_TABLE ) / sizeof( IMAGE_LOAD_POLICY_TABLE[0] );
106
107 const StringEnum< Image::ReleasePolicy > IMAGE_RELEASE_POLICY_TABLE[] =
108 {
109   { "UNUSED", Image::UNUSED },
110   { "NEVER",  Image::NEVER  },
111 };
112 const unsigned int IMAGE_RELEASE_POLICY_TABLE_COUNT = sizeof( IMAGE_RELEASE_POLICY_TABLE ) / sizeof( IMAGE_RELEASE_POLICY_TABLE[0] );
113
114 const StringEnum< Pixel::Format > PIXEL_FORMAT_TABLE[] =
115 {
116   { "A8",                                           Pixel::A8                                           },
117   { "L8",                                           Pixel::L8                                           },
118   { "LA88",                                         Pixel::LA88                                         },
119   { "RGB565",                                       Pixel::RGB565                                       },
120   { "BGR565",                                       Pixel::BGR565                                       },
121   { "RGBA4444",                                     Pixel::RGBA4444                                     },
122   { "BGRA4444",                                     Pixel::BGRA4444                                     },
123   { "RGBA5551",                                     Pixel::RGBA5551                                     },
124   { "BGRA5551",                                     Pixel::BGRA5551                                     },
125   { "RGB888",                                       Pixel::RGB888                                       },
126   { "RGB8888",                                      Pixel::RGB8888                                      },
127   { "BGR8888",                                      Pixel::BGR8888                                      },
128   { "RGBA8888",                                     Pixel::RGBA8888                                     },
129   { "BGRA8888",                                     Pixel::BGRA8888                                     },
130   { "COMPRESSED_R11_EAC",                           Pixel::COMPRESSED_R11_EAC                           },
131   { "COMPRESSED_SIGNED_R11_EAC",                    Pixel::COMPRESSED_SIGNED_R11_EAC                    },
132   { "COMPRESSED_RG11_EAC",                          Pixel::COMPRESSED_RG11_EAC                          },
133   { "COMPRESSED_SIGNED_RG11_EAC",                   Pixel::COMPRESSED_SIGNED_RG11_EAC                   },
134   { "COMPRESSED_RGB8_ETC2",                         Pixel::COMPRESSED_RGB8_ETC2                         },
135   { "COMPRESSED_SRGB8_ETC2",                        Pixel::COMPRESSED_SRGB8_ETC2                        },
136   { "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",     Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2     },
137   { "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",    Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2    },
138   { "COMPRESSED_RGBA8_ETC2_EAC",                    Pixel::COMPRESSED_RGBA8_ETC2_EAC                    },
139   { "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",             Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC             },
140   { "COMPRESSED_RGB8_ETC1",                         Pixel::COMPRESSED_RGB8_ETC1                         },
141   { "COMPRESSED_RGB_PVRTC_4BPPV1",                  Pixel::COMPRESSED_RGB_PVRTC_4BPPV1                  },
142 };
143 const unsigned int PIXEL_FORMAT_TABLE_COUNT = sizeof( PIXEL_FORMAT_TABLE ) / sizeof( PIXEL_FORMAT_TABLE[0] );
144
145 const StringEnum< ImageAttributes::ScalingMode > IMAGE_SCALING_MODE_TABLE[] =
146 {
147   { "SHRINK_TO_FIT", ImageAttributes::ShrinkToFit },
148   { "SCALE_TO_FILL", ImageAttributes::ScaleToFill },
149   { "FIT_WIDTH",     ImageAttributes::FitWidth    },
150   { "FIT_HEIGHT",    ImageAttributes::FitHeight   },
151 };
152 const unsigned int IMAGE_SCALING_MODE_TABLE_COUNT = sizeof( IMAGE_SCALING_MODE_TABLE ) / sizeof( IMAGE_SCALING_MODE_TABLE[0] );
153
154 } // unnamed namespace
155
156 bool CompareEnums( const char * a, const char * b )
157 {
158   while( ( *a != '\0' ) && ( *b != '\0' ) )
159   {
160     char ca = *a;
161     char cb = *b;
162
163     if( ( ( ca == '-' ) || ( ca == '_') ) &&
164         ( ( cb == '-' ) || ( cb == '_') ) )
165     {
166       ++a;
167       ++b;
168       continue;
169     }
170
171     if( ( 'A' <= ca ) && ( ca <= 'Z') )
172     {
173       ca = ca + ( 'a' - 'A' );
174     }
175
176     if( ( 'A' <= cb ) && ( cb <= 'Z') )
177     {
178       cb = cb + ( 'a' - 'A' );
179     }
180
181     if( ca != cb )
182     {
183       return false;
184     }
185
186     ++a;
187     ++b;
188   }
189
190   if( ( *a == '\0' ) && ( *b == '\0' ) )
191   {
192     return true;
193   }
194
195   return false;
196 }
197
198
199 ColorMode GetColorMode( const std::string& value )
200 {
201   return GetEnumeration< ColorMode >( value.c_str(), COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT );
202 }
203
204
205 std::string GetColorMode( ColorMode value )
206 {
207   return GetEnumerationName< ColorMode >( value, COLOR_MODE_TABLE, COLOR_MODE_TABLE_COUNT );
208 }
209
210 PositionInheritanceMode GetPositionInheritanceMode( const std::string& value )
211 {
212   return GetEnumeration< PositionInheritanceMode >( value.c_str(), POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT );
213 }
214
215
216 std::string GetPositionInheritanceMode( PositionInheritanceMode value )
217 {
218   return GetEnumerationName< PositionInheritanceMode >( value, POSITION_INHERITANCE_MODE_TABLE, POSITION_INHERITANCE_MODE_TABLE_COUNT );
219 }
220
221
222 DrawMode::Type GetDrawMode( const std::string& value )
223 {
224   return GetEnumeration< DrawMode::Type >( value.c_str(), DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT );
225 }
226
227
228 std::string GetDrawMode( DrawMode::Type value )
229 {
230   return GetEnumerationName< DrawMode::Type >( value, DRAW_MODE_TABLE, DRAW_MODE_TABLE_COUNT );
231 }
232
233
234 Vector3 GetAnchorConstant( const std::string& value )
235 {
236   return GetEnumeration< Vector3 >( value.c_str(), ANCHOR_CONSTANT_TABLE, ANCHOR_CONSTANT_TABLE_COUNT );
237 }
238
239
240 Image NewImage( const Property::Value& map )
241 {
242   Image ret;
243
244   std::string filename;
245   ResourceImage::LoadPolicy loadPolicy    = Dali::Internal::IMAGE_LOAD_POLICY_DEFAULT;
246   Image::ReleasePolicy releasePolicy = Dali::Internal::IMAGE_RELEASE_POLICY_DEFAULT;
247   ImageAttributes attributes         = ImageAttributes::New();
248
249   if( Property::MAP == map.GetType() )
250   {
251     std::string field = "filename";
252     if( map.HasKey(field) )
253     {
254       DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image filename property is not a string" );
255       filename = map.GetValue(field).Get<std::string>();
256     }
257
258     field = "load-policy";
259     if( map.HasKey(field) )
260     {
261       DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image load-policy property is not a string" );
262       std::string v(map.GetValue(field).Get<std::string>());
263       loadPolicy = GetEnumeration< ResourceImage::LoadPolicy >( v.c_str(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT );
264     }
265
266     field = "release-policy";
267     if( map.HasKey(field) )
268     {
269       DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image release-policy property is not a string" );
270       std::string v(map.GetValue(field).Get<std::string>());
271       releasePolicy = GetEnumeration< Image::ReleasePolicy >( v.c_str(), IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT );
272     }
273
274     if( map.HasKey("width") && map.HasKey("height") )
275     {
276       Property::Value &value = map.GetValue("width");
277       unsigned int w = 0, h = 0;
278       // handle floats and integer the same for json script
279       if( value.GetType() == Property::FLOAT)
280       {
281         w = static_cast<unsigned int>( value.Get<float>() );
282       }
283       else
284       {
285         DALI_ASSERT_ALWAYS(value.GetType() == Property::INTEGER && "Image width property is not a number" );
286         w = value.Get<int>();
287       }
288
289       value = map.GetValue("height");
290       if( value.GetType() == Property::FLOAT)
291       {
292         h = static_cast<unsigned int>( value.Get<float>() );
293       }
294       else
295       {
296         DALI_ASSERT_ALWAYS(value.GetType() == Property::INTEGER && "Image width property is not a number" );
297         h = value.Get<int>();
298       }
299
300       attributes.SetSize( w, h );
301     }
302
303     field = "pixel-format";
304     if( map.HasKey(field) )
305     {
306       DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image release-policy property is not a string" );
307       std::string s(map.GetValue(field).Get<std::string>());
308       attributes.SetPixelFormat( GetEnumeration< Pixel::Format >( s.c_str(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT ));
309     }
310
311     field = "scaling-mode";
312     if( map.HasKey(field) )
313     {
314       DALI_ASSERT_ALWAYS(map.GetValue(field).GetType() == Property::STRING && "Image release-policy property is not a string" );
315       std::string s(map.GetValue(field).Get<std::string>());
316       attributes.SetScalingMode( GetEnumeration< ImageAttributes::ScalingMode >( s.c_str(), IMAGE_SCALING_MODE_TABLE, IMAGE_SCALING_MODE_TABLE_COUNT ) );
317     }
318
319     if( map.HasKey("type") )
320     {
321       DALI_ASSERT_ALWAYS( map.GetValue("type").GetType() == Property::STRING );
322       std::string s(map.GetValue("type").Get<std::string>());
323       if("FrameBufferImage" == s)
324       {
325         ret = Image( new Internal::FrameBufferImage(attributes.GetWidth(),
326                                                     attributes.GetHeight(),
327                                                     attributes.GetPixelFormat(),
328                                                     releasePolicy) );
329       }
330       else if("BitmapImage" == s)
331       {
332         ret = Image( new Internal::BitmapImage(attributes.GetWidth(),
333                                                attributes.GetHeight(),
334                                                attributes.GetPixelFormat(),
335                                                releasePolicy) );
336       }
337       else if("Image" == s)
338       {
339         ret = ResourceImage::New(filename, attributes, loadPolicy, releasePolicy);
340       }
341       else
342       {
343         DALI_ASSERT_ALWAYS( !"Unknown image type" );
344       }
345     }
346     else
347     {
348       ret = ResourceImage::New(filename, attributes, loadPolicy, releasePolicy);
349     }
350   }
351
352   return ret;
353
354 } // Image NewImage( Property::Value map )
355
356
357 ShaderEffect NewShaderEffect( const Property::Value& map )
358 {
359   Internal::ShaderEffectPtr ret;
360
361   if( map.GetType() == Property::MAP )
362   {
363     ret = Internal::ShaderEffect::New(Dali::ShaderEffect::HINT_NONE); // hint can be reset if in map
364
365     if( map.HasKey("program") )
366     {
367       Property::Index index = ret->GetPropertyIndex("program");
368       DALI_ASSERT_DEBUG( map.GetValue("program").GetType() == Property::MAP );
369       ret->SetProperty(index, map.GetValue("program"));
370     }
371
372     for(int i = 0; i < map.GetSize(); ++i)
373     {
374       const std::string& key = map.GetKey(i);
375       if(key != "program")
376       {
377         Property::Index index = ret->GetPropertyIndex( key );
378
379         if( Property::INVALID_INDEX != index )
380         {
381           ret->SetProperty(index, map.GetItem(i));
382         }
383         else
384         {
385           // if its not a property then register it as a uniform (making a custom property)
386
387           if(map.GetItem(i).GetType() == Property::INTEGER)
388           {
389             // valid uniforms are floats, vec3's etc so we recast if the user accidentally
390             // set as integer. Note the map could have come from json script.
391             Property::Value asFloat( static_cast<float>( map.GetItem(i).Get<int>() ) );
392             ret->SetUniform( key, asFloat, Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT );
393           }
394           else
395           {
396             ret->SetUniform( key, map.GetItem(i), Dali::ShaderEffect::COORDINATE_TYPE_DEFAULT );
397           }
398         }
399       }
400     }
401   }
402
403   return Dali::ShaderEffect(ret.Get());
404 }
405
406
407 Actor NewActor( const Property::Map& map )
408 {
409   BaseHandle handle;
410
411   // First find type and create Actor
412   Property::Value* typeValue = map.Find( "type" );
413   if ( typeValue )
414   {
415     TypeInfo type = TypeRegistry::Get().GetTypeInfo( typeValue->Get< std::string >() );
416     if ( type )
417     {
418       handle = type.CreateInstance();
419     }
420   }
421
422   if ( !handle )
423   {
424     DALI_LOG_ERROR( "Actor type not provided, returning empty handle" );
425     return Actor();
426   }
427
428   Actor actor( Actor::DownCast( handle ) );
429
430   if ( actor )
431   {
432     // Now set the properties, or create children
433     for ( unsigned int i = 0, mapCount = map.Count(); i < mapCount; ++i )
434     {
435       const StringValuePair& pair( map.GetPair( i ) );
436       const std::string& key( pair.first );
437       if ( key == "type" )
438       {
439         continue;
440       }
441
442       const Property::Value& value( pair.second );
443
444       if ( key == "actors" )
445       {
446         // Create children
447
448         Property::Array actorArray = value.Get< Property::Array >();
449         for ( Property::Array::iterator arrayIter = actorArray.begin(), arrayEndIter = actorArray.end(); arrayIter != arrayEndIter; ++arrayIter )
450         {
451           actor.Add( NewActor( arrayIter->Get< Property::Map >() ) );
452         }
453       }
454       else if ( key == "signals" )
455       {
456         DALI_LOG_ERROR( "signals not supported" );
457       }
458       else if( key ==  "parent-origin" )
459       {
460         // Parent Origin can be a string constant as well as a Vector3
461
462         const Property::Type type( value.GetType() );
463         if ( type == Property::VECTOR3 )
464         {
465           actor.SetParentOrigin( value.Get< Vector3 >() );
466         }
467         else if( type == Property::STRING )
468         {
469           actor.SetParentOrigin( GetAnchorConstant( value.Get< std::string >() ) );
470         }
471       }
472       else if( key ==  "anchor-point" )
473       {
474         // Anchor Point can be a string constant as well as a Vector3
475
476         const Property::Type type( value.GetType() );
477         if ( type == Property::VECTOR3 )
478         {
479           actor.SetAnchorPoint( value.Get< Vector3 >() );
480         }
481         else if( type == Property::STRING )
482         {
483           actor.SetAnchorPoint( GetAnchorConstant( value.Get< std::string >() ) );
484         }
485       }
486       else
487       {
488         Property::Index index( actor.GetPropertyIndex( key ) );
489
490         if ( index != Property::INVALID_INDEX )
491         {
492           actor.SetProperty( index, value );
493         }
494       }
495     }
496   }
497
498   return actor;
499 }
500
501 void CreatePropertyMap( Actor actor, Property::Map& map )
502 {
503   map.Clear();
504
505   if ( actor )
506   {
507     map[ "type" ] = actor.GetTypeName();
508
509     // Default properties
510     Property::IndexContainer indices;
511     actor.GetPropertyIndices( indices );
512     const Property::IndexContainer::const_iterator endIter = indices.end();
513     for ( Property::IndexContainer::iterator iter = indices.begin(); iter != endIter; ++iter )
514     {
515       map[ actor.GetPropertyName( *iter ) ] = actor.GetProperty( *iter );
516     }
517
518     // Children
519     unsigned int childCount( actor.GetChildCount() );
520     if ( childCount )
521     {
522       Property::Array childArray;
523       for ( unsigned int child = 0; child < childCount; ++child )
524       {
525         Property::Map childMap;
526         CreatePropertyMap( actor.GetChildAt( child ), childMap );
527         childArray.push_back( childMap );
528       }
529       map[ "actors" ] = childArray;
530     }
531   }
532 }
533
534 void CreatePropertyMap( Image image, Property::Map& map )
535 {
536   map.Clear();
537
538   if ( image )
539   {
540     std::string imageType( "ResourceImage" );
541
542     // Get Type - cannot use TypeRegistry as Image is not an Object and thus, not registered
543     if ( BitmapImage::DownCast( image ) )
544     {
545       imageType = "BitmapImage";
546     }
547     else if ( FrameBufferImage::DownCast( image ) )
548     {
549       imageType = "FrameBufferImage";
550     }
551
552     map[ "type" ] = imageType;
553     map[ "release-policy" ] = GetEnumerationName< Image::ReleasePolicy >( image.GetReleasePolicy(), IMAGE_RELEASE_POLICY_TABLE, IMAGE_RELEASE_POLICY_TABLE_COUNT );
554
555     ResourceImage resourceImage = ResourceImage::DownCast( image );
556     if( resourceImage )
557     {
558       map[ "filename" ] = resourceImage.GetUrl();
559       map[ "load-policy" ] = GetEnumerationName< ResourceImage::LoadPolicy >( resourceImage.GetLoadPolicy(), IMAGE_LOAD_POLICY_TABLE, IMAGE_LOAD_POLICY_TABLE_COUNT );
560
561       ImageAttributes attributes( resourceImage.GetAttributes() );
562       map[ "pixel-format" ] = GetEnumerationName< Pixel::Format >( attributes.GetPixelFormat(), PIXEL_FORMAT_TABLE, PIXEL_FORMAT_TABLE_COUNT );
563       map[ "scaling-mode" ] = GetEnumerationName< ImageAttributes::ScalingMode >( attributes.GetScalingMode(), IMAGE_SCALING_MODE_TABLE, IMAGE_SCALING_MODE_TABLE_COUNT );
564     }
565
566     int width( image.GetWidth() );
567     int height( image.GetHeight() );
568
569     if ( width && height )
570     {
571       map[ "width" ] = width;
572       map[ "height" ] = height;
573     }
574   }
575 }
576
577 } // namespace scripting
578
579 } // namespace Dali
580
581
582
583