Blender  V3.3
DirectDrawSurface.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 /*
8  * This file is based on a similar file from the NVIDIA texture tools
9  * (http://nvidia-texture-tools.googlecode.com/)
10  *
11  * Original license from NVIDIA follows.
12  */
13 
14 /* Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
15  *
16  * Permission is hereby granted, free of charge, to any person
17  * obtaining a copy of this software and associated documentation
18  * files (the "Software"), to deal in the Software without
19  * restriction, including without limitation the rights to use,
20  * copy, modify, merge, publish, distribute, sublicense, and/or sell
21  * copies of the Software, and to permit persons to whom the
22  * Software is furnished to do so, subject to the following
23  * conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  * OTHER DEALINGS IN THE SOFTWARE. */
36 
37 #pragma once
38 
39 #include <ColorBlock.h>
40 #include <Common.h>
41 #include <Image.h>
42 #include <Stream.h>
43 
53 };
54 
55 struct DDSCaps {
60 };
61 
63 struct DDSHeader10 {
69 };
70 
72 struct DDSHeader {
86 
87  /* Helper methods. */
88  DDSHeader();
89 
90  void setWidth(uint w);
91  void setHeight(uint h);
92  void setDepth(uint d);
94  void setTexture2D();
95  void setTexture3D();
96  void setTextureCube();
97  void setLinearSize(uint size);
98  void setPitch(uint pitch);
99  void setFourCC(uint8 c0, uint8 c1, uint8 c2, uint8 c3);
100  void setFormatCode(uint code);
101  void setSwizzleCode(uint8 c0, uint8 c1, uint8 c2, uint8 c3);
102  void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask);
103  void setDX10Format(uint format);
104  void setNormalFlag(bool b);
105  void setSrgbFlag(bool b);
106  void setHasAlphaFlag(bool b);
107  void setUserVersion(int version);
108 
109  // void swapBytes();
110 
111  bool hasDX10Header() const;
112  uint signature() const;
113  uint toolVersion() const;
114  uint userVersion() const;
115  bool isNormalMap() const;
116  bool isSrgb() const;
117  bool hasAlpha() const;
118  uint d3d9Format() const;
119 };
120 
123  public:
124  DirectDrawSurface(unsigned char *mem, uint size);
125 
126  bool isValid() const;
127  bool isSupported() const;
128 
129  bool hasAlpha() const;
130 
131  uint mipmapCount() const;
132  uint fourCC() const;
133  uint width() const;
134  uint height() const;
135  uint depth() const;
136  bool isTexture1D() const;
137  bool isTexture2D() const;
138  bool isTexture3D() const;
139  bool isTextureCube() const;
140 
141  void setNormalFlag(bool b);
142  void setHasAlphaFlag(bool b);
143  void setUserVersion(int version);
144 
145  void mipmap(Image *img, uint f, uint m);
150  void *readData(uint &size);
151  // void mipmap(FloatImage *img, uint f, uint m);
152 
153  void printInfo() const;
154 
155  private:
156  uint blockSize() const;
157  uint faceSize() const;
158  uint mipmapSize(uint m) const;
159 
160  uint offset(uint f, uint m);
161 
162  void readLinearImage(Image *img);
163  void readBlockImage(Image *img);
164  void readBlock(ColorBlock *rgba);
165 
166  private:
168  Stream stream;
169  DDSHeader header;
170 };
171 
172 void mem_read(Stream &mem, DDSPixelFormat &pf);
173 void mem_read(Stream &mem, DDSCaps &caps);
174 void mem_read(Stream &mem, DDSHeader &header);
175 void mem_read(Stream &mem, DDSHeader10 &header);
unsigned int uint
Definition: BLI_sys_types.h:67
unsigned char uint8
Definition: Common.h:26
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:38
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken rgba("rgba", pxr::TfToken::Immortal)
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:11