1 /* 2 * Copyright (C) 2014 Team Kodi 3 * http://kodi.tv 4 * 5 * This Program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2, or (at your option) 8 * any later version. 9 * 10 * This Program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with XBMC; see the file COPYING. If not, see 17 * <http://www.gnu.org/licenses/>. 18 * 19 */ 20 21 #pragma once 22 23 #include <string> 24 #include <vector> 25 26 /* forward declarations */ 27 28 class DecodedFrame; 29 class DecodedFrames; 30 31 class IDecoder 32 { 33 public: 34 virtual ~IDecoder() = default; 35 virtual bool CanDecode(const std::string &filename) = 0; 36 virtual bool LoadFile(const std::string &filename, DecodedFrames &frames) = 0; 37 virtual void FreeDecodedFrame(DecodedFrame &frame) = 0; 38 virtual const char* GetImageFormatName() = 0; 39 virtual const char* GetDecoderName() = 0; 40 GetSupportedExtensions()41 const std::vector<std::string>& GetSupportedExtensions() 42 { 43 m_supportedExtensions.clear(); 44 FillSupportedExtensions(); 45 return m_supportedExtensions; 46 } 47 48 protected: 49 virtual void FillSupportedExtensions() = 0; 50 //fill this with extensions in FillSupportedExtensions like ".png" 51 std::vector<std::string> m_supportedExtensions; 52 }; 53 54 class RGBAImage 55 { 56 public: 57 RGBAImage() = default; 58 59 char* pixels = nullptr; // image data 60 int width = 0; // width 61 int height = 0; // height 62 int bbp = 0; // bits per pixel 63 int pitch = 0; // rowsize in bytes 64 }; 65 66 class DecodedFrame 67 { 68 public: 69 DecodedFrame() = default; 70 RGBAImage rgbaImage; /* rgbaimage for this frame */ 71 int delay = 0; /* Frame delay in ms */ 72 IDecoder* decoder = nullptr; /* Pointer to decoder */ 73 }; 74 75 class DecodedFrames 76 { 77 public: 78 DecodedFrames() = default; 79 std::vector<DecodedFrame> frameList; 80 clear()81 void clear() 82 { 83 for (auto f : frameList) 84 { 85 if (f.decoder != NULL) 86 { 87 f.decoder->FreeDecodedFrame(f); 88 } 89 else 90 { 91 fprintf(stderr, 92 "ERROR: %s - can not determine decoder type for frame!\n", 93 __FUNCTION__); 94 } 95 } 96 frameList.clear(); 97 } 98 }; 99