Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DirectDrawSurface.h « dds « intern « imbuf « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ac7f893fdddc3f1c56b0e6292c0d12bb040def3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/** \file
 * \ingroup imbdds
 */

/*
 * This file is based on a similar file from the NVIDIA texture tools
 * (http://nvidia-texture-tools.googlecode.com/)
 *
 * Original license from NVIDIA follows.
 */

// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#pragma once

#include <ColorBlock.h>
#include <Common.h>
#include <Image.h>
#include <Stream.h>

struct DDSPixelFormat {
  uint size;
  uint flags;
  uint fourcc;
  uint bitcount;
  uint rmask;
  uint gmask;
  uint bmask;
  uint amask;
};

struct DDSCaps {
  uint caps1;
  uint caps2;
  uint caps3;
  uint caps4;
};

/// DDS file header for DX10.
struct DDSHeader10 {
  uint dxgiFormat;
  uint resourceDimension;
  uint miscFlag;
  uint arraySize;
  uint reserved;
};

/// DDS file header.
struct DDSHeader {
  uint fourcc;
  uint size;
  uint flags;
  uint height;
  uint width;
  uint pitch;
  uint depth;
  uint mipmapcount;
  uint reserved[11];
  DDSPixelFormat pf;
  DDSCaps caps;
  uint notused;
  DDSHeader10 header10;

  // Helper methods.
  DDSHeader();

  void setWidth(uint w);
  void setHeight(uint h);
  void setDepth(uint d);
  void setMipmapCount(uint count);
  void setTexture2D();
  void setTexture3D();
  void setTextureCube();
  void setLinearSize(uint size);
  void setPitch(uint pitch);
  void setFourCC(uint8 c0, uint8 c1, uint8 c2, uint8 c3);
  void setFormatCode(uint code);
  void setSwizzleCode(uint8 c0, uint8 c1, uint8 c2, uint8 c3);
  void setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask);
  void setDX10Format(uint format);
  void setNormalFlag(bool b);
  void setSrgbFlag(bool b);
  void setHasAlphaFlag(bool b);
  void setUserVersion(int version);

  /*void swapBytes();*/

  bool hasDX10Header() const;
  uint signature() const;
  uint toolVersion() const;
  uint userVersion() const;
  bool isNormalMap() const;
  bool isSrgb() const;
  bool hasAlpha() const;
  uint d3d9Format() const;
};

/// DirectDraw Surface. (DDS)
class DirectDrawSurface {
 public:
  DirectDrawSurface(unsigned char *mem, uint size);
  ~DirectDrawSurface();

  bool isValid() const;
  bool isSupported() const;

  bool hasAlpha() const;

  uint mipmapCount() const;
  uint fourCC() const;
  uint width() const;
  uint height() const;
  uint depth() const;
  bool isTexture1D() const;
  bool isTexture2D() const;
  bool isTexture3D() const;
  bool isTextureCube() const;

  void setNormalFlag(bool b);
  void setHasAlphaFlag(bool b);
  void setUserVersion(int version);

  void mipmap(Image *img, uint f, uint m);
  void *readData(uint &size);
  //  void mipmap(FloatImage *img, uint f, uint m);

  void printInfo() const;

 private:
  uint blockSize() const;
  uint faceSize() const;
  uint mipmapSize(uint m) const;

  uint offset(uint f, uint m);

  void readLinearImage(Image *img);
  void readBlockImage(Image *img);
  void readBlock(ColorBlock *rgba);

 private:
  Stream stream;  // memory where DDS file resides
  DDSHeader header;
};

void mem_read(Stream &mem, DDSPixelFormat &pf);
void mem_read(Stream &mem, DDSCaps &caps);
void mem_read(Stream &mem, DDSHeader &header);
void mem_read(Stream &mem, DDSHeader10 &header);