2 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
30 CDDSImage(unsigned int width, unsigned int height, unsigned int format);
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;
39 bool ReadFile(const std::string &file);
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
50 bool Create(const std::string &file, unsigned int width, unsigned int height, unsigned int pitch, unsigned char const *argb, double maxMSE = 0);
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
62 static bool Decompress(unsigned char *argb, unsigned int width, unsigned int height, unsigned int pitch, unsigned char const *dxt, unsigned int format);
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;
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
77 bool Compress(unsigned int width, unsigned int height, unsigned int pitch, unsigned char const *argb, double maxMSE = 0);
79 static unsigned int GetStorageRequirements(unsigned int width, unsigned int height, unsigned int format);
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
92 ddpf_alphapixels = 0x00000001,
93 ddpf_fourcc = 0x00000004,
98 ddscaps_complex = 0x00000008,
99 ddscaps_texture = 0x00001000,
100 ddscaps_mipmap = 0x00400000
103 #pragma pack(push, 2)
109 uint32_t rgbBitCount;
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
127 uint32_t reserved[2];
138 uint32_t mipmapcount;
139 uint32_t reserved[11];
140 ddpixelformat pixelFormat;
146 ddsurfacedesc2 m_desc;
147 unsigned char *m_data;