Merge pull request #5039 from CEikermann/patch-1
[vuplus_xbmc] / xbmc / pictures / Picture.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
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)
9  *  any later version.
10  *
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.
15  *
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/>.
19  *
20  */
21 #include "utils/StdString.h"
22 #include "utils/Job.h"
23
24 class CBaseTexture;
25
26 class CPicture
27 {
28 public:
29   static bool CreateThumbnailFromSurface(const unsigned char* buffer, int width, int height, int stride, const CStdString &thumbFile);
30
31   /*! \brief Create a tiled thumb of the given files
32    \param files the files to create the thumb from
33    \param thumb the filename of the thumb
34    */
35   static bool CreateTiledThumb(const std::vector<std::string> &files, const std::string &thumb);
36
37   /*! \brief Cache a texture, resizing, rotating and flipping as needed, and saving as a JPG or PNG
38    \param texture a pointer to a CBaseTexture
39    \param dest_width [in/out] maximum width in pixels of cached version - replaced with actual cached width
40    \param dest_height [in/out] maximum height in pixels of cached version - replaced with actual cached height
41    \param dest the output cache file
42    \return true if successful, false otherwise
43    */
44   static bool CacheTexture(CBaseTexture *texture, uint32_t &dest_width, uint32_t &dest_height, const std::string &dest);
45   static bool CacheTexture(uint8_t *pixels, uint32_t width, uint32_t height, uint32_t pitch, int orientation, uint32_t &dest_width, uint32_t &dest_height, const std::string &dest);
46
47 private:
48   static void GetScale(unsigned int width, unsigned int height, unsigned int &out_width, unsigned int &out_height);
49   static bool ScaleImage(uint8_t *in_pixels, unsigned int in_width, unsigned int in_height, unsigned int in_pitch,
50                          uint8_t *out_pixels, unsigned int out_width, unsigned int out_height, unsigned int out_pitch);
51   static bool OrientateImage(uint32_t *&pixels, unsigned int &width, unsigned int &height, int orientation);
52
53   static bool FlipHorizontal(uint32_t *&pixels, unsigned int &width, unsigned int &height);
54   static bool FlipVertical(uint32_t *&pixels, unsigned int &width, unsigned int &height);
55   static bool Rotate90CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height);
56   static bool Rotate270CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height);
57   static bool Rotate180CCW(uint32_t *&pixels, unsigned int &width, unsigned int &height);
58   static bool Transpose(uint32_t *&pixels, unsigned int &width, unsigned int &height);
59   static bool TransposeOffAxis(uint32_t *&pixels, unsigned int &width, unsigned int &height);
60 };
61
62 //this class calls CreateThumbnailFromSurface in a CJob, so a png file can be written without halting the render thread
63 class CThumbnailWriter : public CJob
64 {
65   public:
66     //WARNING: buffer is deleted from DoWork()
67     CThumbnailWriter(unsigned char* buffer, int width, int height, int stride, const CStdString& thumbFile);
68     bool DoWork();
69
70   private:
71     unsigned char* m_buffer;
72     int            m_width;
73     int            m_height;
74     int            m_stride;
75     CStdString     m_thumbFile;
76 };
77