Blender  V2.93
DirectDrawSurface.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 /*
22  * This file is based on a similar file from the NVIDIA texture tools
23  * (http://nvidia-texture-tools.googlecode.com/)
24  *
25  * Original license from NVIDIA follows.
26  */
27 
28 /* Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
29  *
30  * Permission is hereby granted, free of charge, to any person
31  * obtaining a copy of this software and associated documentation
32  * files (the "Software"), to deal in the Software without
33  * restriction, including without limitation the rights to use,
34  * copy, modify, merge, publish, distribute, sublicense, and/or sell
35  * copies of the Software, and to permit persons to whom the
36  * Software is furnished to do so, subject to the following
37  * conditions:
38  *
39  * The above copyright notice and this permission notice shall be
40  * included in all copies or substantial portions of the Software.
41  *
42  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
44  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
45  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
46  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
47  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
48  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
49  * OTHER DEALINGS IN THE SOFTWARE. */
50 
51 #pragma once
52 
53 #include <ColorBlock.h>
54 #include <Common.h>
55 #include <Image.h>
56 #include <Stream.h>
57 
67 };
68 
69 struct DDSCaps {
74 };
75 
77 struct DDSHeader10 {
83 };
84 
86 struct DDSHeader {
100 
101  /* Helper methods. */
102  DDSHeader();
103 
104  void setWidth(uint w);
105  void setHeight(uint h);
106  void setDepth(uint d);
107  void setMipmapCount(uint count);
108  void setTexture2D();
109  void setTexture3D();
110  void setTextureCube();
111  void setLinearSize(uint size);
112  void setPitch(uint pitch);
113  void setFourCC(uint8 c0, uint8 c1, uint8 c2, uint8 c3);
114  void setFormatCode(uint code);
115  void setSwizzleCode(uint8 c0, uint8 c1, uint8 c2, uint8 c3);
116  void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask);
117  void setDX10Format(uint format);
118  void setNormalFlag(bool b);
119  void setSrgbFlag(bool b);
120  void setHasAlphaFlag(bool b);
121  void setUserVersion(int version);
122 
123  /*void swapBytes();*/
124 
125  bool hasDX10Header() const;
126  uint signature() const;
127  uint toolVersion() const;
128  uint userVersion() const;
129  bool isNormalMap() const;
130  bool isSrgb() const;
131  bool hasAlpha() const;
132  uint d3d9Format() const;
133 };
134 
137  public:
138  DirectDrawSurface(unsigned char *mem, uint size);
139 
140  bool isValid() const;
141  bool isSupported() const;
142 
143  bool hasAlpha() const;
144 
145  uint mipmapCount() const;
146  uint fourCC() const;
147  uint width() const;
148  uint height() const;
149  uint depth() const;
150  bool isTexture1D() const;
151  bool isTexture2D() const;
152  bool isTexture3D() const;
153  bool isTextureCube() const;
154 
155  void setNormalFlag(bool b);
156  void setHasAlphaFlag(bool b);
157  void setUserVersion(int version);
158 
159  void mipmap(Image *img, uint f, uint m);
160  void *readData(uint &size);
161  // void mipmap(FloatImage *img, uint f, uint m);
162 
163  void printInfo() const;
164 
165  private:
166  uint blockSize() const;
167  uint faceSize() const;
168  uint mipmapSize(uint m) const;
169 
170  uint offset(uint f, uint m);
171 
172  void readLinearImage(Image *img);
173  void readBlockImage(Image *img);
174  void readBlock(ColorBlock *rgba);
175 
176  private:
177  Stream stream; /* Memory where DDS file resides. */
178  DDSHeader header;
179 };
180 
181 void mem_read(Stream &mem, DDSPixelFormat &pf);
182 void mem_read(Stream &mem, DDSCaps &caps);
183 void mem_read(Stream &mem, DDSHeader &header);
184 void mem_read(Stream &mem, DDSHeader10 &header);
unsigned int uint
Definition: BLI_sys_types.h:83
unsigned char uint8
Definition: Common.h:40
void mem_read(Stream &mem, DDSPixelFormat &pf)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
void mipmap(Image *img, uint f, uint m)
void * readData(uint &size)
void setUserVersion(int version)
void setHasAlphaFlag(bool b)
DirectDrawSurface(unsigned char *mem, uint size)
#define pf(_x, _i)
Prefetch 64.
Definition: gim_memory.h:48
int count
format
Definition: logImageCore.h:47
bool isNormalMap() const
DDSHeader10 header10
void setUserVersion(int version)
void setFormatCode(uint code)
void setDX10Format(uint format)
void setSwizzleCode(uint8 c0, uint8 c1, uint8 c2, uint8 c3)
void setHasAlphaFlag(bool b)
void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask)
void setMipmapCount(uint count)
void setNormalFlag(bool b)
DDSPixelFormat pf
uint userVersion() const
void setWidth(uint w)
void setHeight(uint h)
void setPitch(uint pitch)
bool hasDX10Header() const
void setDepth(uint d)
uint d3d9Format() const
bool isSrgb() const
void setFourCC(uint8 c0, uint8 c1, uint8 c2, uint8 c3)
bool hasAlpha() const
void setLinearSize(uint size)
uint signature() const
uint reserved[11]
uint toolVersion() const
void setSrgbFlag(bool b)
Definition: Stream.h:25