Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / gif-loading.cpp
1 /*
2  * Copyright (c) 2022 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  * Copyright notice for the EFL:
17  * Copyright (C) EFL developers (see AUTHORS)
18  */
19
20 // CLASS HEADER
21 #include <dali/internal/imaging/common/gif-loading.h>
22
23 // EXTERNAL INCLUDES
24 #include <fcntl.h>
25 #include <gif_lib.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <cstring>
30 #include <memory>
31
32 #include <dali/devel-api/threading/mutex.h>
33 #include <dali/integration-api/debug.h>
34 #include <dali/internal/imaging/common/file-download.h>
35 #include <dali/internal/system/common/file-reader.h>
36 #include <dali/public-api/images/pixel-data.h>
37
38 #define IMG_TOO_BIG(w, h)                                                       \
39   ((static_cast<unsigned long long>(w) * static_cast<unsigned long long>(h)) >= \
40    ((1ULL << (29 * (sizeof(void*) / 4))) - 2048))
41
42 #define LOADERR(x)     \
43   do                   \
44   {                    \
45     DALI_LOG_ERROR(x); \
46     goto on_error;     \
47   } while(0)
48
49 namespace Dali
50 {
51 namespace Internal
52 {
53 namespace Adaptor
54 {
55 namespace
56 {
57 #if defined(DEBUG_ENABLED)
58 Debug::Filter* gGifLoadingLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_GIF_LOADING");
59 #endif
60
61 const int        IMG_MAX_SIZE                = 65000;
62 constexpr size_t MAXIMUM_DOWNLOAD_IMAGE_SIZE = 50 * 1024 * 1024;
63
64 constexpr int LOCAL_CACHED_COLOR_GENERATE_THRESHOLD = 16; ///< Generate color map optimize only if colorCount * threshold < width * height, So we don't loop if image is small
65
66 #if GIFLIB_MAJOR < 5
67 const int DISPOSE_BACKGROUND = 2; /* Set area too background color */
68 const int DISPOSE_PREVIOUS   = 3; /* Restore to previous content */
69 #endif
70
71 struct FrameInfo
72 {
73   FrameInfo()
74   : x(0),
75     y(0),
76     w(0),
77     h(0),
78     delay(0),
79     transparent(-1),
80     dispose(DISPOSE_BACKGROUND),
81     interlace(0)
82   {
83   }
84
85   int            x, y, w, h;
86   unsigned short delay;            // delay time in 1/100ths of a sec
87   short          transparent : 10; // -1 == not, anything else == index
88   short          dispose : 6;      // 0, 1, 2, 3 (others invalid)
89   short          interlace : 1;    // interlaced or not
90 };
91
92 struct ImageFrame
93 {
94   ImageFrame()
95   : index(0),
96     data(nullptr),
97     info(),
98     loaded(false)
99   {
100   }
101
102   ~ImageFrame()
103   {
104     if(data != nullptr)
105     {
106       // De-allocate memory of the frame data.
107       delete[] data;
108       data = nullptr;
109     }
110   }
111
112   int       index;
113   uint32_t* data; /* frame decoding data */
114   FrameInfo info; /* special image type info */
115   bool      loaded : 1;
116 };
117
118 struct GifAnimationData
119 {
120   GifAnimationData()
121   : frames(),
122     frameCount(0),
123     loopCount(0),
124     currentFrame(0),
125     animated(false)
126   {
127   }
128
129   std::vector<ImageFrame> frames;
130   int                     frameCount;
131   int                     loopCount;
132   int                     currentFrame;
133   bool                    animated;
134 };
135
136 struct GifCachedColorData
137 {
138   GifCachedColorData() = default;
139
140   // precalculated colormap table
141   std::vector<std::uint32_t> globalCachedColor{};
142   std::vector<std::uint32_t> localCachedColor{};
143   ColorMapObject*            localCachedColorMap{nullptr}; // Weak-pointer of ColorMapObject. should be nullptr if image changed
144 };
145
146 // Forward declaration
147 struct GifAccessor;
148
149 struct LoaderInfo
150 {
151   LoaderInfo()
152   {
153   }
154
155   struct FileData
156   {
157     FileData()
158     : fileName(nullptr),
159       globalMap(nullptr),
160       length(0),
161       isLocalResource(true)
162     {
163     }
164
165     ~FileData()
166     {
167       if(globalMap)
168       {
169         free(globalMap);
170         globalMap = nullptr;
171       }
172     }
173
174     bool LoadFile();
175
176   private:
177     bool LoadLocalFile();
178     bool LoadRemoteFile();
179
180   public:
181     const char*    fileName;        /**< The absolute path of the file. */
182     unsigned char* globalMap;       /**< A pointer to the entire contents of the file */
183     long long      length;          /**< The length of the file in bytes. */
184     bool           isLocalResource; /**< The flag whether the file is a local resource */
185   };
186
187   struct FileInfo
188   {
189     FileInfo()
190     : map(nullptr),
191       position(0),
192       length(0)
193     {
194     }
195
196     unsigned char* map;
197     int            position, length; // yes - gif uses ints for file sizes.
198   };
199
200   FileData                     fileData;
201   GifAnimationData             animated;
202   GifCachedColorData           cachedColor;
203   std::unique_ptr<GifAccessor> gifAccessor{nullptr};
204   int                          imageNumber{0};
205   FileInfo                     fileInfo;
206 };
207
208 struct ImageProperties
209 {
210   unsigned int w{0};
211   unsigned int h{0};
212   bool         alpha{0};
213 };
214
215 /**
216  * Class to access gif open/close using riaa
217  */
218 struct GifAccessor
219 {
220   /**
221    * Constructor
222    * @param[in,out] fileInfo Contains ptr to memory, and is updated by DGifOpen
223    */
224   GifAccessor(LoaderInfo::FileInfo& fileInfo)
225   {
226 // actually ask libgif to open the file
227 #if GIFLIB_MAJOR >= 5
228     gif = DGifOpen(&fileInfo, FileRead, NULL);
229 #else
230     gif = DGifOpen(&fileInfo, FileRead);
231 #endif
232
233     if(!gif)
234     {
235       DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
236     }
237   }
238
239   ~GifAccessor()
240   {
241     if(gif)
242     {
243 #if(GIFLIB_MAJOR > 5) || ((GIFLIB_MAJOR == 5) && (GIFLIB_MINOR >= 1))
244       DGifCloseFile(gif, NULL);
245 #else
246       DGifCloseFile(gif);
247 #endif
248     }
249   }
250
251   /**
252    * @brief Copy data from gif file into buffer.
253    *
254    * @param[in] gifFileType A pointer pointing to GIF File Type
255    * @param[out] buffer A pointer to buffer containing GIF raw data
256    * @param[in] len The length in bytes to be copied
257    * @return The data length of the image in bytes
258    */
259   static int FileRead(GifFileType* gifFileType, GifByteType* buffer, int length)
260   {
261     LoaderInfo::FileInfo* fi = reinterpret_cast<LoaderInfo::FileInfo*>(gifFileType->UserData);
262
263     if(fi->position >= fi->length)
264     {
265       return 0; // if at or past end - no
266     }
267     if((fi->position + length) >= fi->length)
268     {
269       length = fi->length - fi->position;
270     }
271     memcpy(buffer, fi->map + fi->position, length);
272     fi->position += length;
273     return length;
274   }
275
276   GifFileType* gif = nullptr;
277 };
278
279 bool LoaderInfo::FileData::LoadFile()
280 {
281   bool success = false;
282   if(isLocalResource)
283   {
284     success = LoadLocalFile();
285   }
286   else
287   {
288     success = LoadRemoteFile();
289   }
290   return success;
291 }
292
293 bool LoaderInfo::FileData::LoadLocalFile()
294 {
295   Internal::Platform::FileReader fileReader(fileName);
296   FILE*                          fp = fileReader.GetFile();
297   if(fp == NULL)
298   {
299     return false;
300   }
301
302   if(fseek(fp, 0, SEEK_END) <= -1)
303   {
304     return false;
305   }
306
307   length = ftell(fp);
308   if(length <= -1)
309   {
310     return false;
311   }
312
313   if((!fseek(fp, 0, SEEK_SET)))
314   {
315     globalMap = reinterpret_cast<GifByteType*>(malloc(sizeof(GifByteType) * length));
316     length    = fread(globalMap, sizeof(GifByteType), length, fp);
317   }
318   else
319   {
320     return false;
321   }
322   return true;
323 }
324
325 bool LoaderInfo::FileData::LoadRemoteFile()
326 {
327   // remote file
328   bool                  succeeded = false;
329   Dali::Vector<uint8_t> dataBuffer;
330   size_t                dataSize;
331
332   succeeded = TizenPlatform::Network::DownloadRemoteFileIntoMemory(fileName, dataBuffer, dataSize, MAXIMUM_DOWNLOAD_IMAGE_SIZE);
333   if(succeeded)
334   {
335     size_t blobSize = dataBuffer.Size();
336     if(blobSize > 0U)
337     {
338       // Open a file handle on the memory buffer:
339       Dali::Internal::Platform::FileReader fileReader(dataBuffer, blobSize);
340       FILE* const                          fp = fileReader.GetFile();
341       if(NULL != fp)
342       {
343         if((!fseek(fp, 0, SEEK_SET)))
344         {
345           globalMap = reinterpret_cast<GifByteType*>(malloc(sizeof(GifByteType) * blobSize));
346           length    = fread(globalMap, sizeof(GifByteType), blobSize, fp);
347           succeeded = true;
348         }
349         else
350         {
351           DALI_LOG_ERROR("Error seeking within file\n");
352         }
353       }
354       else
355       {
356         DALI_LOG_ERROR("Error reading file\n");
357       }
358     }
359   }
360
361   return succeeded;
362 }
363
364 /**
365  * @brief This combines R, G, B and Alpha values into a single 32-bit (ABGR) value.
366  *
367  * @param[in] animated A structure containing GIF animation data
368  * @param[in] index Frame index to be searched in GIF
369  * @return A pointer to the ImageFrame.
370  */
371 inline int CombinePixelABGR(int a, int r, int g, int b)
372 {
373   return (((a) << 24) + ((b) << 16) + ((g) << 8) + (r));
374 }
375
376 inline int PixelLookup(ColorMapObject* colorMap, int index)
377 {
378   return CombinePixelABGR(0xFF, colorMap->Colors[index].Red, colorMap->Colors[index].Green, colorMap->Colors[index].Blue);
379 }
380
381 /**
382  * @brief Brute force find frame index - gifs are normally small so ok for now.
383  *
384  * @param[in] animated A structure containing GIF animation data
385  * @param[in] index Frame index to be searched in GIF
386  * @return A pointer to the ImageFrame.
387  */
388 ImageFrame* FindFrame(const GifAnimationData& animated, int index)
389 {
390   for(auto&& elem : animated.frames)
391   {
392     if(elem.index == index)
393     {
394       return const_cast<ImageFrame*>(&elem);
395     }
396   }
397   return nullptr;
398 }
399
400 /**
401  * @brief Fill in an image with a specific rgba color value.
402  *
403  * @param[in] data A pointer pointing to an image data
404  * @param[in] row A int containing the number of rows in an image
405  * @param[in] val A uint32_t containing rgba color value
406  * @param[in] x X-coordinate used an offset to calculate pixel position
407  * @param[in] y Y-coordinate used an offset to calculate pixel position
408  * @param[in] width Width of the image
409  * @param[in] height Height of the image
410  */
411 void FillImage(uint32_t* data, int row, uint32_t val, int x, int y, int width, int height)
412 {
413   int       xAxis, yAxis;
414   uint32_t* pixelPosition;
415
416   for(yAxis = 0; yAxis < height; yAxis++)
417   {
418     pixelPosition = data + ((y + yAxis) * row) + x;
419     for(xAxis = 0; xAxis < width; xAxis++)
420     {
421       *pixelPosition = val;
422       pixelPosition++;
423     }
424   }
425 }
426
427 /**
428  * @brief Fill a rgba data pixle blob with a frame color (bg or trans)
429  *
430  * @param[in] data A pointer pointing to an image data
431  * @param[in] row A int containing the number of rows in an image
432  * @param[in] gif A pointer pointing to GIF File Type
433  * @param[in] frameInfo A pointer pointing to Frame Information data
434  * @param[in] x X-coordinate used an offset to calculate pixel position
435  * @param[in] y Y-coordinate used an offset to calculate pixel position
436  * @param[in] width Width of the image
437  * @param[in] height Height of the image
438  */
439 void FillFrame(uint32_t* data, int row, GifFileType* gif, FrameInfo* frameInfo, int x, int y, int w, int h)
440 {
441   // solid color fill for pre frame region
442   if(frameInfo->transparent < 0)
443   {
444     ColorMapObject* colorMap;
445     int             backGroundColor;
446
447     // work out color to use from colorMap
448     if(gif->Image.ColorMap)
449     {
450       colorMap = gif->Image.ColorMap;
451     }
452     else
453     {
454       colorMap = gif->SColorMap;
455     }
456     backGroundColor = gif->SBackGroundColor;
457     // and do the fill
458     FillImage(data, row, CombinePixelABGR(0xff, colorMap->Colors[backGroundColor].Red, colorMap->Colors[backGroundColor].Green, colorMap->Colors[backGroundColor].Blue), x, y, w, h);
459   }
460   // fill in region with 0 (transparent)
461   else
462   {
463     FillImage(data, row, 0, x, y, w, h);
464   }
465 }
466
467 /**
468  * @brief Store common fields from gif file info into frame info
469  *
470  * @param[in] gif A pointer pointing to GIF File Type
471  * @param[in] frameInfo A pointer pointing to Frame Information data
472  */
473 void StoreFrameInfo(GifFileType* gif, FrameInfo* frameInfo)
474 {
475   frameInfo->x         = gif->Image.Left;
476   frameInfo->y         = gif->Image.Top;
477   frameInfo->w         = gif->Image.Width;
478   frameInfo->h         = gif->Image.Height;
479   frameInfo->interlace = gif->Image.Interlace;
480 }
481
482 /**
483  * @brief Check if image fills "screen space" and if so, if it is transparent
484  * at all then the image could be transparent - OR if image doesnt fill,
485  * then it could be trasnparent (full coverage of screen). Some gifs will
486  * be recognized as solid here for faster rendering, but not all.
487  *
488  * @param[out] full A boolean to show whether image is transparent or not
489  * @param[in] frameInfo A pointer pointing to Frame Information data
490  * @param[in] width Width of the image
491  * @param[in] height Height of the image
492  */
493 void CheckTransparency(bool& full, FrameInfo* frameInfo, int width, int height)
494 {
495   if((frameInfo->x == 0) && (frameInfo->y == 0) &&
496      (frameInfo->w == width) && (frameInfo->h == height))
497   {
498     if(frameInfo->transparent >= 0)
499     {
500       full = false;
501     }
502   }
503   else
504   {
505     full = false;
506   }
507 }
508
509 /**
510  * @brief Fix coords and work out an x and y inset in orig data if out of image bounds.
511  */
512 void ClipCoordinates(int imageWidth, int imageHeight, int* xin, int* yin, int x0, int y0, int w0, int h0, int* x, int* y, int* w, int* h)
513 {
514   if(x0 < 0)
515   {
516     w0 += x0;
517     *xin = -x0;
518     x0   = 0;
519   }
520   if((x0 + w0) > imageWidth)
521   {
522     w0 = imageWidth - x0;
523   }
524   if(y0 < 0)
525   {
526     h0 += y0;
527     *yin = -y0;
528     y0   = 0;
529   }
530   if((y0 + h0) > imageHeight)
531   {
532     h0 = imageHeight - y0;
533   }
534   *x = x0;
535   *y = y0;
536   *w = w0;
537   *h = h0;
538 }
539
540 /**
541  * @brief Flush out rgba frame images to save memory but skip current,
542  * previous and lastPreservedFrame frames (needed for dispose mode DISPOSE_PREVIOUS)
543  *
544  * @param[in] animated A structure containing GIF animation data
545  * @param[in] width Width of the image
546  * @param[in] height Height of the image
547  * @param[in] thisframe The current frame
548  * @param[in] prevframe The previous frame
549  * @param[in] lastPreservedFrame The last preserved frame
550  */
551 void FlushFrames(GifAnimationData& animated, int width, int height, ImageFrame* thisframe, ImageFrame* prevframe, ImageFrame* lastPreservedFrame)
552 {
553   DALI_LOG_INFO(gGifLoadingLogFilter, Debug::Concise, "FlushFrames() START \n");
554
555   // target is the amount of memory we want to be under for stored frames
556   int total = 0, target = 512 * 1024;
557
558   // total up the amount of memory used by stored frames for this image
559   for(auto&& frame : animated.frames)
560   {
561     if(frame.data)
562     {
563       total++;
564     }
565   }
566   total *= (width * height * sizeof(uint32_t));
567
568   DALI_LOG_INFO(gGifLoadingLogFilter, Debug::Concise, "Total used frame size: %d\n", total);
569
570   // If we use more than target (512k) for frames - flush
571   if(total > target)
572   {
573     // Clean frames (except current and previous) until below target
574     for(auto&& frame : animated.frames)
575     {
576       if((frame.index != thisframe->index) && (!prevframe || frame.index != prevframe->index) &&
577          (!lastPreservedFrame || frame.index != lastPreservedFrame->index))
578       {
579         if(frame.data != nullptr)
580         {
581           delete[] frame.data;
582           frame.data = nullptr;
583
584           // subtract memory used and if below target - stop flush
585           total -= (width * height * sizeof(uint32_t));
586           if(total < target)
587           {
588             break;
589           }
590         }
591       }
592     }
593   }
594
595   DALI_LOG_INFO(gGifLoadingLogFilter, Debug::Concise, "FlushFrames() END \n");
596 }
597
598 /**
599  * @brief allocate frame and frame info and append to list and store fields.
600  *
601  * @param[in] animated A structure containing GIF animation data
602  * @param[in] transparent Transparent index of the new frame
603  * @param[in] dispose Dispose mode of new frame
604  * @param[in] delay The frame delay of new frame
605  * @param[in] index The index of new frame
606  */
607 FrameInfo* NewFrame(GifAnimationData& animated, int transparent, int dispose, int delay, int index)
608 {
609   ImageFrame frame;
610
611   // record transparent index to be used or -1 if none
612   // for this SPECIFIC frame
613   frame.info.transparent = transparent;
614   // record dispose mode (3 bits)
615   frame.info.dispose = dispose;
616   // record delay (2 bytes so max 65546 /100 sec)
617   frame.info.delay = delay;
618   // record the index number we are at
619   frame.index = index;
620   // that frame is stored AT image/screen size
621
622   animated.frames.push_back(frame);
623
624   DALI_LOG_INFO(gGifLoadingLogFilter, Debug::Concise, "NewFrame: animated.frames.size() = %d\n", animated.frames.size());
625
626   return &(animated.frames.back().info);
627 }
628
629 /**
630  * @brief Decode a gif image into rows then expand to 32bit into the destination
631  * data pointer.
632  */
633 bool DecodeImage(GifFileType* gif, GifCachedColorData& gifCachedColor, uint32_t* data, int rowpix, int xin, int yin, int transparent, int x, int y, int w, int h, bool fill)
634 {
635   int             intoffset[] = {0, 4, 2, 1};
636   int             intjump[]   = {8, 8, 4, 2};
637   int             i, xx, yy, pix, gifW, gifH;
638   GifRowType*     rows = NULL;
639   bool            ret  = false;
640   ColorMapObject* colorMap;
641   uint32_t*       p;
642
643   // cached color data.
644   const std::uint32_t* cachedColorPtr = nullptr;
645
646   // what we need is image size.
647   SavedImage* sp;
648   sp = &gif->SavedImages[gif->ImageCount - 1];
649
650   gifW = sp->ImageDesc.Width;
651   gifH = sp->ImageDesc.Height;
652
653   if((gifW < w) || (gifH < h))
654   {
655     DALI_LOG_ERROR("gifW : %d, w : %d, gifH : %d, h : %d\n", gifW, w, gifH, h);
656     DALI_ASSERT_DEBUG(false && "Dimensions are bigger than the Gif image size");
657     goto on_error;
658   }
659
660   // build a blob of memory to have pointers to rows of pixels
661   // AND store the decoded gif pixels (1 byte per pixel) as welll
662   rows = static_cast<GifRowType*>(malloc((gifH * sizeof(GifRowType)) + (gifW * gifH * sizeof(GifPixelType))));
663   if(!rows)
664   {
665     goto on_error;
666   }
667
668   // fill in the pointers at the start
669   for(yy = 0; yy < gifH; yy++)
670   {
671     rows[yy] = reinterpret_cast<unsigned char*>(rows) + (gifH * sizeof(GifRowType)) + (yy * gifW * sizeof(GifPixelType));
672   }
673
674   // if gif is interlaced, walk interlace pattern and decode into rows
675   if(gif->Image.Interlace)
676   {
677     for(i = 0; i < 4; i++)
678     {
679       for(yy = intoffset[i]; yy < gifH; yy += intjump[i])
680       {
681         if(DGifGetLine(gif, rows[yy], gifW) != GIF_OK)
682         {
683           goto on_error;
684         }
685       }
686     }
687   }
688   // normal top to bottom - decode into rows
689   else
690   {
691     for(yy = 0; yy < gifH; yy++)
692     {
693       if(DGifGetLine(gif, rows[yy], gifW) != GIF_OK)
694       {
695         goto on_error;
696       }
697     }
698   }
699
700   // work out what colormap to use
701   if(gif->Image.ColorMap)
702   {
703     colorMap = gif->Image.ColorMap;
704     // use local cached color map without re-calculate cache.
705     if(gifCachedColor.localCachedColorMap == colorMap)
706     {
707       cachedColorPtr = gifCachedColor.localCachedColor.data();
708     }
709     // else if w * h is big enough, generate local cached color.
710     else if(colorMap->ColorCount * LOCAL_CACHED_COLOR_GENERATE_THRESHOLD < w * h)
711     {
712       gifCachedColor.localCachedColor.resize(colorMap->ColorCount);
713       for(i = 0; i < colorMap->ColorCount; ++i)
714       {
715         gifCachedColor.localCachedColor[i] = PixelLookup(colorMap, i);
716       }
717       gifCachedColor.localCachedColorMap = colorMap;
718
719       cachedColorPtr = gifCachedColor.localCachedColor.data();
720     }
721   }
722   else
723   {
724     colorMap       = gif->SColorMap;
725     cachedColorPtr = gifCachedColor.globalCachedColor.data();
726   }
727
728   // HARD-CODING optimize
729   // if we need to deal with transparent pixels at all...
730   if(transparent >= 0)
731   {
732     // if we are told to FILL (overwrite with transparency kept)
733     if(fill)
734     {
735       // if we use cachedColor, use it
736       if(cachedColorPtr)
737       {
738         for(yy = 0; yy < h; yy++)
739         {
740           p = data + ((y + yy) * rowpix) + x;
741           for(xx = 0; xx < w; xx++)
742           {
743             pix = rows[yin + yy][xin + xx];
744             if(pix != transparent)
745             {
746               *p = cachedColorPtr[pix];
747             }
748             else
749             {
750               *p = 0;
751             }
752             p++;
753           }
754         }
755       }
756       // we don't have cachedColor. use PixelLookup function.
757       else
758       {
759         for(yy = 0; yy < h; yy++)
760         {
761           p = data + ((y + yy) * rowpix) + x;
762           for(xx = 0; xx < w; xx++)
763           {
764             pix = rows[yin + yy][xin + xx];
765             if(pix != transparent)
766             {
767               *p = PixelLookup(colorMap, pix);
768             }
769             else
770             {
771               *p = 0;
772             }
773             p++;
774           }
775         }
776       }
777     }
778     // paste on top with transparent pixels untouched
779     else
780     {
781       // if we use cachedColor, use it
782       if(cachedColorPtr)
783       {
784         for(yy = 0; yy < h; yy++)
785         {
786           p = data + ((y + yy) * rowpix) + x;
787           for(xx = 0; xx < w; xx++)
788           {
789             pix = rows[yin + yy][xin + xx];
790             if(pix != transparent)
791             {
792               *p = cachedColorPtr[pix];
793             }
794             p++;
795           }
796         }
797       }
798       // we don't have cachedColor. use PixelLookup function.
799       else
800       {
801         for(yy = 0; yy < h; yy++)
802         {
803           p = data + ((y + yy) * rowpix) + x;
804           for(xx = 0; xx < w; xx++)
805           {
806             pix = rows[yin + yy][xin + xx];
807             if(pix != transparent)
808             {
809               *p = PixelLookup(colorMap, pix);
810             }
811             p++;
812           }
813         }
814       }
815     }
816   }
817   else
818   {
819     // if we use cachedColor, use it
820     if(cachedColorPtr)
821     {
822       // walk pixels without worring about transparency at all
823       for(yy = 0; yy < h; yy++)
824       {
825         p = data + ((y + yy) * rowpix) + x;
826         for(xx = 0; xx < w; xx++)
827         {
828           pix = rows[yin + yy][xin + xx];
829           *p  = cachedColorPtr[pix];
830           p++;
831         }
832       }
833     }
834     // we don't have cachedColor. use PixelLookup function.
835     else
836     {
837       // walk pixels without worring about transparency at all
838       for(yy = 0; yy < h; yy++)
839       {
840         p = data + ((y + yy) * rowpix) + x;
841         for(xx = 0; xx < w; xx++)
842         {
843           pix = rows[yin + yy][xin + xx];
844           *p  = PixelLookup(colorMap, pix);
845           p++;
846         }
847       }
848     }
849   }
850   ret = true;
851
852 on_error:
853   if(rows)
854   {
855     free(rows);
856   }
857   return ret;
858 }
859
860 /**
861  * @brief Reader header from the gif file and populates structures accordingly.
862  *
863  * @param[in] loaderInfo A LoaderInfo structure containing file descriptor and other data about GIF.
864  * @param[out] prop A ImageProperties structure for storing information about GIF data.
865  * @param[out] error Error code
866  * @return The true or false whether reading was successful or not.
867  */
868 bool ReadHeader(LoaderInfo&      loaderInfo,
869                 ImageProperties& prop, //output struct
870                 int*             error)
871 {
872   GifAnimationData&     animated    = loaderInfo.animated;
873   GifCachedColorData&   cachedColor = loaderInfo.cachedColor;
874   LoaderInfo::FileData& fileData    = loaderInfo.fileData;
875   bool                  success     = false;
876   LoaderInfo::FileInfo  fileInfo;
877   GifRecordType         rec;
878
879   // it is possible which gif file have error midle of frames,
880   // in that case we should play gif file until meet error frame.
881   int        imageNumber = 0;
882   int        loopCount   = -1;
883   FrameInfo* frameInfo   = NULL;
884   bool       full        = true;
885
886   success = fileData.LoadFile();
887   if(!success || !fileData.globalMap)
888   {
889     success = false;
890     DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
891   }
892   else
893   {
894     fileInfo.map      = fileData.globalMap;
895     fileInfo.length   = fileData.length;
896     fileInfo.position = 0;
897     GifAccessor gifAccessor(fileInfo);
898
899     if(gifAccessor.gif)
900     {
901       // get the gif "screen size" (the actual image size)
902       prop.w = gifAccessor.gif->SWidth;
903       prop.h = gifAccessor.gif->SHeight;
904
905       // if size is invalid - abort here
906       if((prop.w < 1) || (prop.h < 1) || (prop.w > IMG_MAX_SIZE) || (prop.h > IMG_MAX_SIZE) || IMG_TOO_BIG(prop.w, prop.h))
907       {
908         if(IMG_TOO_BIG(prop.w, prop.h))
909         {
910           success = false;
911           DALI_LOG_ERROR("LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
912         }
913         else
914         {
915           success = false;
916           DALI_LOG_ERROR("LOAD_ERROR_GENERIC");
917         }
918       }
919       else
920       {
921         // walk through gif records in file to figure out info
922         success = true;
923         do
924         {
925           if(DGifGetRecordType(gifAccessor.gif, &rec) == GIF_ERROR)
926           {
927             // if we have a gif that ends part way through a sequence
928             // (or animation) consider it valid and just break - no error
929             if(imageNumber <= 1)
930             {
931               success = true;
932             }
933             else
934             {
935               success = false;
936               DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
937             }
938             break;
939           }
940
941           // get image description section
942           if(rec == IMAGE_DESC_RECORD_TYPE)
943           {
944             int          img_code;
945             GifByteType* img;
946
947             // get image desc
948             if(DGifGetImageDesc(gifAccessor.gif) == GIF_ERROR)
949             {
950               success = false;
951               DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
952               break;
953             }
954             // skip decoding and just walk image to next
955             if(DGifGetCode(gifAccessor.gif, &img_code, &img) == GIF_ERROR)
956             {
957               success = false;
958               DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
959               break;
960             }
961             // skip till next...
962             while(img)
963             {
964               img = NULL;
965               DGifGetCodeNext(gifAccessor.gif, &img);
966             }
967             // store geometry in the last frame info data
968             if(frameInfo)
969             {
970               StoreFrameInfo(gifAccessor.gif, frameInfo);
971               CheckTransparency(full, frameInfo, prop.w, prop.h);
972             }
973             // or if we dont have a frameInfo entry - create one even for stills
974             else
975             {
976               // allocate and save frame with field data
977               frameInfo = NewFrame(animated, -1, 0, 0, imageNumber + 1);
978               if(!frameInfo)
979               {
980                 success = false;
981                 DALI_LOG_ERROR("LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
982                 break;
983               }
984               // store geometry info from gif image
985               StoreFrameInfo(gifAccessor.gif, frameInfo);
986               // check for transparency/alpha
987               CheckTransparency(full, frameInfo, prop.w, prop.h);
988             }
989             imageNumber++;
990           }
991           // we have an extension code block - for animated gifs for sure
992           else if(rec == EXTENSION_RECORD_TYPE)
993           {
994             int          ext_code;
995             GifByteType* ext = NULL;
996
997             // get the first extension entry
998             DGifGetExtension(gifAccessor.gif, &ext_code, &ext);
999             while(ext)
1000             {
1001               // graphic control extension - for animated gif data
1002               // and transparent index + flag
1003               if(ext_code == 0xf9)
1004               {
1005                 // create frame and store it in image
1006                 int transparencyIndex = (ext[1] & 1) ? ext[4] : -1;
1007                 int disposeMode       = (ext[1] >> 2) & 0x7;
1008                 int delay             = (int(ext[3]) << 8) | int(ext[2]);
1009                 frameInfo             = NewFrame(animated, transparencyIndex, disposeMode, delay, imageNumber + 1);
1010                 if(!frameInfo)
1011                 {
1012                   success = false;
1013                   DALI_LOG_ERROR("LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
1014                   break;
1015                 }
1016               }
1017               // netscape extension indicating loop count.
1018               else if(ext_code == 0xff) /* application extension */
1019               {
1020                 if(!strncmp(reinterpret_cast<char*>(&ext[1]), "NETSCAPE2.0", 11) ||
1021                    !strncmp(reinterpret_cast<char*>(&ext[1]), "ANIMEXTS1.0", 11))
1022                 {
1023                   ext = NULL;
1024                   DGifGetExtensionNext(gifAccessor.gif, &ext);
1025                   if(ext[1] == 0x01)
1026                   {
1027                     loopCount = (int(ext[3]) << 8) | int(ext[2]);
1028                     if(loopCount > 0)
1029                     {
1030                       loopCount++;
1031                     }
1032                   }
1033                 }
1034               }
1035
1036               // and continue onto the next extension entry
1037               ext = NULL;
1038               DGifGetExtensionNext(gifAccessor.gif, &ext);
1039             }
1040           }
1041         } while(rec != TERMINATE_RECORD_TYPE && success);
1042
1043         if(success)
1044         {
1045           // if the gif main says we have more than one image or our image counting
1046           // says so, then this image is animated - indicate this
1047           if((gifAccessor.gif->ImageCount > 1) || (imageNumber > 1))
1048           {
1049             animated.animated  = 1;
1050             animated.loopCount = loopCount;
1051           }
1052           animated.frameCount = std::min(gifAccessor.gif->ImageCount, imageNumber);
1053
1054           if(!full)
1055           {
1056             prop.alpha = 1;
1057           }
1058
1059           animated.currentFrame = 1;
1060
1061           // cache global color map
1062           ColorMapObject* colorMap = gifAccessor.gif->SColorMap;
1063           if(colorMap)
1064           {
1065             cachedColor.globalCachedColor.resize(colorMap->ColorCount);
1066             for(int i = 0; i < colorMap->ColorCount; ++i)
1067             {
1068               cachedColor.globalCachedColor[i] = PixelLookup(colorMap, i);
1069             }
1070           }
1071           cachedColor.localCachedColorMap = nullptr;
1072
1073           // no errors in header scan etc. so set err and return value
1074           *error = 0;
1075         }
1076       }
1077     }
1078   }
1079   return success;
1080 }
1081
1082 /**
1083  * @brief Reader next frame of the gif file and populates structures accordingly.
1084  *
1085  * @param[in,out] loaderInfo A LoaderInfo structure containing file descriptor and other data about GIF.
1086  * @param[in,out] prop A ImageProperties structure containing information about gif data.
1087  * @param[out] pixels A pointer to buffer which will contain all pixel data of the frame on return.
1088  * @param[out] error Error code
1089  * @return The true or false whether reading was successful or not.
1090  */
1091 bool ReadNextFrame(LoaderInfo& loaderInfo, ImageProperties& prop, //  use for w and h
1092                    unsigned char* pixels,
1093                    int*           error)
1094 {
1095   GifAnimationData&     animated = loaderInfo.animated;
1096   LoaderInfo::FileData& fileData = loaderInfo.fileData;
1097   bool                  ret      = false;
1098   GifRecordType         rec;
1099   int                   index = 0, imageNumber = 0;
1100   FrameInfo*            frameInfo;
1101   ImageFrame*           frame              = NULL;
1102   ImageFrame*           lastPreservedFrame = NULL;
1103
1104   index = animated.currentFrame;
1105
1106   // if index is invalid for animated image - error out
1107   if((animated.animated) && ((index <= 0) || (index > animated.frameCount)))
1108   {
1109     DALI_LOG_ERROR("LOAD_ERROR_GENERIC");
1110     return false;
1111   }
1112
1113   // find the given frame index
1114   frame = FindFrame(animated, index);
1115   if(!frame)
1116   {
1117     DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
1118     return false;
1119   }
1120   else if(!(frame->loaded) || !(frame->data))
1121   {
1122     // if we want to go backwards, we likely need/want to re-decode from the
1123     // start as we have nothing to build on. If there is a gif, imageNumber
1124     // has been set already.
1125     if(loaderInfo.gifAccessor && loaderInfo.imageNumber > 0)
1126     {
1127       if((index > 0) && (index < loaderInfo.imageNumber) && (animated.animated))
1128       {
1129         loaderInfo.gifAccessor.reset();
1130         loaderInfo.imageNumber = 0;
1131       }
1132     }
1133
1134     // actually ask libgif to open the file
1135     if(!loaderInfo.gifAccessor)
1136     {
1137       loaderInfo.fileInfo.map      = fileData.globalMap;
1138       loaderInfo.fileInfo.length   = fileData.length;
1139       loaderInfo.fileInfo.position = 0;
1140       if(!loaderInfo.fileInfo.map)
1141       {
1142         DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
1143         return false;
1144       }
1145       std::unique_ptr<GifAccessor> gifAccessor = std::make_unique<GifAccessor>(loaderInfo.fileInfo);
1146       if(!gifAccessor->gif)
1147       {
1148         DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
1149         return false;
1150       }
1151       loaderInfo.gifAccessor = std::move(gifAccessor);
1152       loaderInfo.imageNumber = 1;
1153     }
1154
1155     // our current position is the previous frame we decoded from the file
1156     imageNumber = loaderInfo.imageNumber;
1157
1158     // walk through gif records in file to figure out info
1159     do
1160     {
1161       if(DGifGetRecordType(loaderInfo.gifAccessor->gif, &rec) == GIF_ERROR)
1162       {
1163         DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
1164         return false;
1165       }
1166
1167       if(rec == EXTENSION_RECORD_TYPE)
1168       {
1169         int          ext_code;
1170         GifByteType* ext = NULL;
1171         DGifGetExtension(loaderInfo.gifAccessor->gif, &ext_code, &ext);
1172
1173         while(ext)
1174         {
1175           ext = NULL;
1176           DGifGetExtensionNext(loaderInfo.gifAccessor->gif, &ext);
1177         }
1178       }
1179       // get image description section
1180       else if(rec == IMAGE_DESC_RECORD_TYPE)
1181       {
1182         int          xin = 0, yin = 0, x = 0, y = 0, w = 0, h = 0;
1183         int          img_code;
1184         GifByteType* img;
1185         ImageFrame*  previousFrame = NULL;
1186         ImageFrame*  thisFrame     = NULL;
1187
1188         // get image desc
1189         if(DGifGetImageDesc(loaderInfo.gifAccessor->gif) == GIF_ERROR)
1190         {
1191           DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
1192           return false;
1193         }
1194
1195         // get the previous frame entry AND the current one to fill in
1196         previousFrame = FindFrame(animated, imageNumber - 1);
1197         thisFrame     = FindFrame(animated, imageNumber);
1198
1199         // if we have a frame AND we're animated AND we have no data...
1200         if((thisFrame) && (!thisFrame->data) && (animated.animated))
1201         {
1202           bool first = false;
1203
1204           // allocate it
1205           thisFrame->data = new uint32_t[prop.w * prop.h];
1206
1207           if(!thisFrame->data)
1208           {
1209             DALI_LOG_ERROR("LOAD_ERROR_RESOURCE_ALLOCATION_FAILED");
1210             return false;
1211           }
1212
1213           // if we have no prior frame OR prior frame data... empty
1214           if((!previousFrame) || (!previousFrame->data))
1215           {
1216             first     = true;
1217             frameInfo = &(thisFrame->info);
1218             memset(thisFrame->data, 0, prop.w * prop.h * sizeof(uint32_t));
1219           }
1220           // we have a prior frame to copy data from...
1221           else
1222           {
1223             frameInfo = &(previousFrame->info);
1224
1225             // fix coords of sub image in case it goes out...
1226             ClipCoordinates(prop.w, prop.h, &xin, &yin, frameInfo->x, frameInfo->y, frameInfo->w, frameInfo->h, &x, &y, &w, &h);
1227
1228             // if dispose mode is not restore - then copy pre frame
1229             if(frameInfo->dispose != DISPOSE_PREVIOUS)
1230             {
1231               memcpy(thisFrame->data, previousFrame->data, prop.w * prop.h * sizeof(uint32_t));
1232             }
1233
1234             // if dispose mode is "background" then fill with bg
1235             if(frameInfo->dispose == DISPOSE_BACKGROUND)
1236             {
1237               FillFrame(thisFrame->data, prop.w, loaderInfo.gifAccessor->gif, frameInfo, x, y, w, h);
1238             }
1239             else if(frameInfo->dispose == DISPOSE_PREVIOUS) // GIF_DISPOSE_RESTORE
1240             {
1241               int prevIndex = 2;
1242               do
1243               {
1244                 // Find last preserved frame.
1245                 lastPreservedFrame = FindFrame(animated, imageNumber - prevIndex);
1246                 if(!lastPreservedFrame)
1247                 {
1248                   DALI_LOG_ERROR("LOAD_ERROR_LAST_PRESERVED_FRAME_NOT_FOUND");
1249                   return false;
1250                 }
1251                 prevIndex++;
1252               } while(lastPreservedFrame && lastPreservedFrame->info.dispose == DISPOSE_PREVIOUS);
1253
1254               if(lastPreservedFrame)
1255               {
1256                 memcpy(thisFrame->data, lastPreservedFrame->data, prop.w * prop.h * sizeof(uint32_t));
1257               }
1258             }
1259           }
1260           // now draw this frame on top
1261           frameInfo = &(thisFrame->info);
1262           ClipCoordinates(prop.w, prop.h, &xin, &yin, frameInfo->x, frameInfo->y, frameInfo->w, frameInfo->h, &x, &y, &w, &h);
1263           if(!DecodeImage(loaderInfo.gifAccessor->gif, loaderInfo.cachedColor, thisFrame->data, prop.w, xin, yin, frameInfo->transparent, x, y, w, h, first))
1264           {
1265             DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
1266             return false;
1267           }
1268
1269           // mark as loaded and done
1270           thisFrame->loaded = true;
1271
1272           FlushFrames(animated, prop.w, prop.h, thisFrame, previousFrame, lastPreservedFrame);
1273         }
1274         // if we have a frame BUT the image is not animated. different
1275         // path
1276         else if((thisFrame) && (!thisFrame->data) && (!animated.animated))
1277         {
1278           // if we don't have the data decoded yet - decode it
1279           if((!thisFrame->loaded) || (!thisFrame->data))
1280           {
1281             // use frame info but we WONT allocate frame pixels
1282             frameInfo = &(thisFrame->info);
1283             ClipCoordinates(prop.w, prop.h, &xin, &yin, frameInfo->x, frameInfo->y, frameInfo->w, frameInfo->h, &x, &y, &w, &h);
1284
1285             // clear out all pixels
1286             FillFrame(reinterpret_cast<uint32_t*>(pixels), prop.w, loaderInfo.gifAccessor->gif, frameInfo, 0, 0, prop.w, prop.h);
1287
1288             // and decode the gif with overwriting
1289             if(!DecodeImage(loaderInfo.gifAccessor->gif, loaderInfo.cachedColor, reinterpret_cast<uint32_t*>(pixels), prop.w, xin, yin, frameInfo->transparent, x, y, w, h, true))
1290             {
1291               DALI_LOG_ERROR("LOAD_ERROR_CORRUPT_FILE\n");
1292               return false;
1293             }
1294
1295             // mark as loaded and done
1296             thisFrame->loaded = true;
1297           }
1298           // flush mem we don't need (at expense of decode cpu)
1299         }
1300         else
1301         {
1302           // skip decoding and just walk image to next
1303           if(DGifGetCode(loaderInfo.gifAccessor->gif, &img_code, &img) == GIF_ERROR)
1304           {
1305             DALI_LOG_ERROR("LOAD_ERROR_UNKNOWN_FORMAT\n");
1306             return false;
1307           }
1308
1309           while(img)
1310           {
1311             img = NULL;
1312             DGifGetCodeNext(loaderInfo.gifAccessor->gif, &img);
1313           }
1314         }
1315
1316         imageNumber++;
1317         // if we found the image we wanted - get out of here
1318         if(imageNumber > index)
1319         {
1320           break;
1321         }
1322       }
1323     } while(rec != TERMINATE_RECORD_TYPE);
1324
1325     // if we are at the end of the animation or not animated, close file
1326     loaderInfo.imageNumber = imageNumber;
1327     if((animated.frameCount <= 1) || (rec == TERMINATE_RECORD_TYPE))
1328     {
1329       loaderInfo.gifAccessor.reset();
1330       loaderInfo.imageNumber = 0;
1331     }
1332   }
1333
1334   // no errors in header scan etc. so set err and return value
1335   *error = 0;
1336   ret    = true;
1337
1338   // if it was an animated image we need to copy the data to the
1339   // pixels for the image from the frame holding the data
1340   if(animated.animated && frame->data)
1341   {
1342     memcpy(pixels, frame->data, prop.w * prop.h * sizeof(uint32_t));
1343   }
1344
1345   return ret;
1346 }
1347
1348 } // unnamed namespace
1349
1350 struct GifLoading::Impl
1351 {
1352 public:
1353   Impl(const std::string& url, bool isLocalResource)
1354   : mUrl(url),
1355     mLoadSucceeded(true),
1356     mMutex()
1357   {
1358     loaderInfo.gifAccessor = nullptr;
1359     int error;
1360     loaderInfo.fileData.fileName        = mUrl.c_str();
1361     loaderInfo.fileData.isLocalResource = isLocalResource;
1362
1363     mLoadSucceeded = ReadHeader(loaderInfo, imageProperties, &error);
1364   }
1365
1366   // Moveable but not copyable
1367   Impl(const Impl&) = delete;
1368   Impl& operator=(const Impl&) = delete;
1369   Impl(Impl&&)                 = default;
1370   Impl& operator=(Impl&&) = default;
1371
1372   std::string     mUrl;
1373   LoaderInfo      loaderInfo;
1374   ImageProperties imageProperties;
1375   bool            mLoadSucceeded;
1376   Mutex           mMutex;
1377 };
1378
1379 AnimatedImageLoadingPtr GifLoading::New(const std::string& url, bool isLocalResource)
1380 {
1381   return AnimatedImageLoadingPtr(new GifLoading(url, isLocalResource));
1382 }
1383
1384 GifLoading::GifLoading(const std::string& url, bool isLocalResource)
1385 : mImpl(new GifLoading::Impl(url, isLocalResource))
1386 {
1387 }
1388
1389 GifLoading::~GifLoading()
1390 {
1391   delete mImpl;
1392 }
1393
1394 bool GifLoading::LoadNextNFrames(uint32_t frameStartIndex, int count, std::vector<Dali::PixelData>& pixelData)
1395 {
1396   int  error;
1397   bool ret = false;
1398
1399   Mutex::ScopedLock lock(mImpl->mMutex);
1400   if(!mImpl->mLoadSucceeded)
1401   {
1402     return false;
1403   }
1404
1405   const int bufferSize = mImpl->imageProperties.w * mImpl->imageProperties.h * sizeof(uint32_t);
1406
1407   DALI_LOG_INFO(gGifLoadingLogFilter, Debug::Concise, "LoadNextNFrames( frameStartIndex:%d, count:%d )\n", frameStartIndex, count);
1408
1409   for(int i = 0; i < count; ++i)
1410   {
1411     auto pixelBuffer = new unsigned char[bufferSize];
1412
1413     mImpl->loaderInfo.animated.currentFrame = 1 + ((frameStartIndex + i) % mImpl->loaderInfo.animated.frameCount);
1414
1415     if(ReadNextFrame(mImpl->loaderInfo, mImpl->imageProperties, pixelBuffer, &error))
1416     {
1417       if(pixelBuffer)
1418       {
1419         pixelData.push_back(Dali::PixelData::New(pixelBuffer, bufferSize, mImpl->imageProperties.w, mImpl->imageProperties.h, Dali::Pixel::RGBA8888, Dali::PixelData::DELETE_ARRAY));
1420         ret = true;
1421       }
1422     }
1423   }
1424
1425   return ret;
1426 }
1427
1428 Dali::Devel::PixelBuffer GifLoading::LoadFrame(uint32_t frameIndex)
1429 {
1430   int                      error;
1431   Dali::Devel::PixelBuffer pixelBuffer;
1432   if(!mImpl->mLoadSucceeded)
1433   {
1434     return pixelBuffer;
1435   }
1436
1437   Mutex::ScopedLock lock(mImpl->mMutex);
1438   DALI_LOG_INFO(gGifLoadingLogFilter, Debug::Concise, "LoadFrame( frameIndex:%d )\n", frameIndex);
1439
1440   pixelBuffer = Dali::Devel::PixelBuffer::New(mImpl->imageProperties.w, mImpl->imageProperties.h, Dali::Pixel::RGBA8888);
1441
1442   mImpl->loaderInfo.animated.currentFrame = 1 + (frameIndex % mImpl->loaderInfo.animated.frameCount);
1443   ReadNextFrame(mImpl->loaderInfo, mImpl->imageProperties, pixelBuffer.GetBuffer(), &error);
1444
1445   if(error != 0)
1446   {
1447     pixelBuffer = Dali::Devel::PixelBuffer();
1448   }
1449   return pixelBuffer;
1450 }
1451
1452 ImageDimensions GifLoading::GetImageSize() const
1453 {
1454   return ImageDimensions(mImpl->imageProperties.w, mImpl->imageProperties.h);
1455 }
1456
1457 uint32_t GifLoading::GetImageCount() const
1458 {
1459   return mImpl->loaderInfo.animated.frameCount;
1460 }
1461
1462 uint32_t GifLoading::GetFrameInterval(uint32_t frameIndex) const
1463 {
1464   return mImpl->loaderInfo.animated.frames[frameIndex].info.delay * 10;
1465 }
1466
1467 std::string GifLoading::GetUrl() const
1468 {
1469   return mImpl->mUrl;
1470 }
1471
1472 bool GifLoading::HasLoadingSucceeded() const
1473 {
1474   return mImpl->mLoadSucceeded;
1475 }
1476
1477 } // namespace Adaptor
1478
1479 } // namespace Internal
1480
1481 } // namespace Dali