Fix keymap.
[vuplus_xbmc] / xbmc / guilib / DDSImage.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
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 <stdint.h>
25
26 class CDDSImage
27 {
28 public:
29   CDDSImage();
30   CDDSImage(unsigned int width, unsigned int height, unsigned int format);
31   ~CDDSImage();
32
33   unsigned int GetWidth() const;
34   unsigned int GetHeight() const;
35   unsigned int GetFormat() const;
36   unsigned int GetSize() const;
37   unsigned char *GetData() const;
38
39   bool ReadFile(const std::string &file);
40
41   /*! \brief Create a DDS image file from the given an ARGB buffer
42    \param file name of the file to write
43    \param width width of the pixel buffer
44    \param height height of the pixel buffer
45    \param pitch pitch of the pixel buffer
46    \param argb pixel buffer
47    \param maxMSE maximum mean square error to allow, ignored if 0 (the default)
48    \return true on successful image creation, false otherwise
49    */
50   bool Create(const std::string &file, unsigned int width, unsigned int height, unsigned int pitch, unsigned char const *argb, double maxMSE = 0);
51   
52   /*! \brief Decompress a DXT1/3/5 image to the given buffer
53    Assumes the buffer has been allocated to at least width*height*4
54    \param argb pixel buffer to write to (at least width*height*4 bytes)
55    \param width width of the pixel buffer
56    \param height height of the pixel buffer
57    \param pitch pitch of the pixel buffer
58    \param dxt compressed dxt data
59    \param format format of the compressed dxt data
60    \return true on success, false otherwise
61    */
62   static bool Decompress(unsigned char *argb, unsigned int width, unsigned int height, unsigned int pitch, unsigned char const *dxt, unsigned int format);
63
64 private:
65   void Allocate(unsigned int width, unsigned int height, unsigned int format);
66   static const char *GetFourCC(unsigned int format);
67   bool WriteFile(const std::string &file) const;
68
69   /*! \brief Compress an ARGB buffer into a DXT1/3/5 image
70    \param width width of the pixel buffer
71    \param height height of the pixel buffer
72    \param pitch pitch of the pixel buffer
73    \param argb pixel buffer
74    \param maxMSE maximum mean square error to allow, ignored if 0 (the default)
75    \return true on successful compression within the given maxMSE, false otherwise
76    */
77   bool Compress(unsigned int width, unsigned int height, unsigned int pitch, unsigned char const *argb, double maxMSE = 0);
78
79   static unsigned int GetStorageRequirements(unsigned int width, unsigned int height, unsigned int format);
80   enum {
81     ddsd_caps        = 0x00000001,
82     ddsd_height      = 0x00000002,
83     ddsd_width       = 0x00000004,
84     ddsd_pitch       = 0x00000008,
85     ddsd_pixelformat = 0x00001000,
86     ddsd_mipmapcount = 0x00020000,
87     ddsd_linearsize  = 0x00080000,
88     ddsd_depth       = 0x00800000
89   };
90
91   enum {
92     ddpf_alphapixels = 0x00000001,
93     ddpf_fourcc      = 0x00000004,
94     ddpf_rgb         = 0x00000040
95   };
96
97   enum {
98     ddscaps_complex = 0x00000008,
99     ddscaps_texture = 0x00001000,
100     ddscaps_mipmap  = 0x00400000
101   };
102
103   #pragma pack(push, 2)
104   typedef struct
105   {
106     uint32_t size;
107     uint32_t flags;
108     uint32_t fourcc;
109     uint32_t rgbBitCount;
110     uint32_t rBitMask;
111     uint32_t gBitMask;
112     uint32_t bBitMask;
113     uint32_t aBitMask;
114   } ddpixelformat;
115
116 #define DDPF_ALPHAPIXELS 0x00000001
117 #define DDPF_ALPHA       0x00000002
118 #define DDPF_FOURCC      0x00000004
119 #define DDPF_RGB         0x00000040
120 #define DDPF_YUV         0x00000200
121 #define DDPF_LUMINANCE   0x00020000
122
123   typedef struct
124   {
125     uint32_t flags1;
126     uint32_t flags2;
127     uint32_t reserved[2];
128   } ddcaps2;
129
130   typedef struct
131   {
132     uint32_t      size;
133     uint32_t      flags;
134     uint32_t      height;
135     uint32_t      width;
136     uint32_t      linearSize;
137     uint32_t      depth;
138     uint32_t      mipmapcount;
139     uint32_t      reserved[11];
140     ddpixelformat pixelFormat;
141     ddcaps2       caps;
142     uint32_t      reserved2;
143   } ddsurfacedesc2;
144   #pragma pack(pop)
145
146   ddsurfacedesc2 m_desc;
147   unsigned char *m_data;
148 };