kodi
DDSImage.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "TextureFormats.h"
12 
13 #include <stdint.h>
14 #include <string>
15 
16 class CDDSImage
17 {
18 public:
19  CDDSImage();
20  CDDSImage(unsigned int width, unsigned int height, XB_FMT format);
21  ~CDDSImage();
22 
23  unsigned int GetWidth() const;
24  unsigned int GetHeight() const;
25  XB_FMT GetFormat() const;
26  unsigned int GetSize() const;
27  unsigned char *GetData() const;
28 
29  bool ReadFile(const std::string &file);
30 
31 private:
32  void Allocate(unsigned int width, unsigned int height, XB_FMT format);
33  static const char* GetFourCC(XB_FMT format);
34 
35  static unsigned int GetStorageRequirements(unsigned int width,
36  unsigned int height,
37  XB_FMT format);
38  enum {
39  ddsd_caps = 0x00000001,
40  ddsd_height = 0x00000002,
41  ddsd_width = 0x00000004,
42  ddsd_pitch = 0x00000008,
43  ddsd_pixelformat = 0x00001000,
44  ddsd_mipmapcount = 0x00020000,
45  ddsd_linearsize = 0x00080000,
46  ddsd_depth = 0x00800000
47  };
48 
49  enum {
50  ddpf_alphapixels = 0x00000001,
51  ddpf_fourcc = 0x00000004,
52  ddpf_rgb = 0x00000040
53  };
54 
55  enum {
56  ddscaps_complex = 0x00000008,
57  ddscaps_texture = 0x00001000,
58  ddscaps_mipmap = 0x00400000
59  };
60 
61  #pragma pack(push, 2)
62  typedef struct
63  {
64  uint32_t size;
65  uint32_t flags;
66  uint32_t fourcc;
67  uint32_t rgbBitCount;
68  uint32_t rBitMask;
69  uint32_t gBitMask;
70  uint32_t bBitMask;
71  uint32_t aBitMask;
72  } ddpixelformat;
73 
74 #define DDPF_ALPHAPIXELS 0x00000001
75 #define DDPF_ALPHA 0x00000002
76 #define DDPF_FOURCC 0x00000004
77 #define DDPF_RGB 0x00000040
78 #define DDPF_YUV 0x00000200
79 #define DDPF_LUMINANCE 0x00020000
80 
81  typedef struct
82  {
83  uint32_t flags1;
84  uint32_t flags2;
85  uint32_t reserved[2];
86  } ddcaps2;
87 
88  typedef struct
89  {
90  uint32_t size;
91  uint32_t flags;
92  uint32_t height;
93  uint32_t width;
94  uint32_t linearSize;
95  uint32_t depth;
96  uint32_t mipmapcount;
97  uint32_t reserved[11];
98  ddpixelformat pixelFormat;
99  ddcaps2 caps;
100  uint32_t reserved2;
101  } ddsurfacedesc2;
102  #pragma pack(pop)
103 
104  ddsurfacedesc2 m_desc;
105  unsigned char *m_data;
106 };
Definition: DDSImage.h:16