3 * Copyright (C) 2010-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
22 #if defined(HAVE_OMXLIB)
26 #include <IL/OMX_Video.h>
29 #if defined(STANDALONE)
30 #define XB_FMT_A8R8G8B8 1
33 #include "filesystem/File.h"
34 #include "guilib/XBTF.h"
37 #include "system_gl.h"
39 #include <EGL/eglext.h>
40 #include "threads/Thread.h"
42 using namespace XFILE;
47 class COMXImage : public CThread
51 bool (*callback)(EGLDisplay egl_display, EGLContext egl_context, void *cookie);
56 virtual void OnStartup();
57 virtual void OnExit();
58 virtual void Process();
63 EGLImageKHR egl_image;
71 static COMXImageFile *LoadJpeg(const CStdString& texturePath);
72 static void CloseJpeg(COMXImageFile *file);
74 static bool DecodeJpeg(COMXImageFile *file, unsigned int maxWidth, unsigned int maxHeight, unsigned int stride, void *pixels);
75 static bool CreateThumbnailFromSurface(unsigned char* buffer, unsigned int width, unsigned int height,
76 unsigned int format, unsigned int pitch, const CStdString& destFile);
77 static bool ClampLimits(unsigned int &width, unsigned int &height, unsigned int m_width, unsigned int m_height, bool transposed = false);
78 static bool CreateThumb(const CStdString& srcFile, unsigned int width, unsigned int height, std::string &additional_info, const CStdString& destFile);
79 bool SendMessage(bool (*callback)(EGLDisplay egl_display, EGLContext egl_context, void *cookie), void *cookie);
80 bool DecodeJpegToTexture(COMXImageFile *file, unsigned int width, unsigned int height, void **userdata);
81 void DestroyTexture(void *userdata);
82 void GetTexture(void *userdata, GLuint *texture);
83 bool AllocTextureInternal(EGLDisplay egl_display, EGLContext egl_context, struct textureinfo *tex);
84 bool DestroyTextureInternal(EGLDisplay egl_display, EGLContext egl_context, struct textureinfo *tex);
86 EGLContext m_egl_context;
89 EGLContext GetEGLContext();
90 CCriticalSection m_texqueue_lock;
91 XbmcThreads::ConditionVariable m_texqueue_cond;
92 std::queue <struct callbackinfo *> m_texqueue;
99 virtual ~COMXImageFile();
100 bool ReadFile(const CStdString& inputFile);
101 int GetOrientation() { return m_orientation; };
102 unsigned int GetWidth() { return m_width; };
103 unsigned int GetHeight() { return m_height; };
104 unsigned long GetImageSize() { return m_image_size; };
105 const uint8_t *GetImageBuffer() { return (const uint8_t *)m_image_buffer; };
106 const char *GetFilename() { return m_filename; };
108 OMX_IMAGE_CODINGTYPE GetCodingType(unsigned int &width, unsigned int &height);
109 uint8_t *m_image_buffer;
110 unsigned long m_image_size;
111 unsigned int m_width;
112 unsigned int m_height;
114 const char * m_filename;
121 virtual ~COMXImageDec();
123 // Required overrides
125 bool Decode(const uint8_t *data, unsigned size, unsigned int width, unsigned int height, unsigned stride, void *pixels);
126 unsigned int GetDecodedWidth() { return (unsigned int)m_decoded_format.format.image.nFrameWidth; };
127 unsigned int GetDecodedHeight() { return (unsigned int)m_decoded_format.format.image.nFrameHeight; };
128 unsigned int GetDecodedStride() { return (unsigned int)m_decoded_format.format.image.nStride; };
130 bool HandlePortSettingChange(unsigned int resize_width, unsigned int resize_height, unsigned int resize_stride);
132 COMXCoreComponent m_omx_decoder;
133 COMXCoreComponent m_omx_resize;
134 COMXCoreTunel m_omx_tunnel_decode;
135 OMX_BUFFERHEADERTYPE *m_decoded_buffer;
136 OMX_PARAM_PORTDEFINITIONTYPE m_decoded_format;
137 CCriticalSection m_OMXSection;
144 virtual ~COMXImageEnc();
146 // Required overrides
147 bool CreateThumbnailFromSurface(unsigned char* buffer, unsigned int width, unsigned int height,
148 unsigned int format, unsigned int pitch, const CStdString& destFile);
150 bool Encode(unsigned char *buffer, int size, unsigned int width, unsigned int height, unsigned int pitch);
152 COMXCoreComponent m_omx_encoder;
153 OMX_BUFFERHEADERTYPE *m_encoded_buffer;
154 OMX_PARAM_PORTDEFINITIONTYPE m_encoded_format;
155 CCriticalSection m_OMXSection;
162 virtual ~COMXImageReEnc();
164 // Required overrides
166 bool ReEncode(COMXImageFile &srcFile, unsigned int width, unsigned int height, void * &pDestBuffer, unsigned int &nDestSize);
168 bool HandlePortSettingChange(unsigned int resize_width, unsigned int resize_height, int orientation, bool port_settings_changed);
170 COMXCoreComponent m_omx_decoder;
171 COMXCoreComponent m_omx_resize;
172 COMXCoreComponent m_omx_encoder;
173 COMXCoreTunel m_omx_tunnel_decode;
174 COMXCoreTunel m_omx_tunnel_resize;
175 OMX_BUFFERHEADERTYPE *m_encoded_buffer;
176 CCriticalSection m_OMXSection;
178 unsigned int m_nDestAllocSize;
185 virtual ~COMXTexture();
187 // Required overrides
189 bool Decode(const uint8_t *data, unsigned size, unsigned int width, unsigned int height, void *egl_image);
191 bool HandlePortSettingChange(unsigned int resize_width, unsigned int resize_height, void *egl_image, bool port_settings_changed);
194 COMXCoreComponent m_omx_decoder;
195 COMXCoreComponent m_omx_resize;
196 COMXCoreComponent m_omx_egl_render;
198 COMXCoreTunel m_omx_tunnel_decode;
199 COMXCoreTunel m_omx_tunnel_egl;
201 OMX_BUFFERHEADERTYPE *m_egl_buffer;
202 CCriticalSection m_OMXSection;
205 extern COMXImage g_OMXImage;