1 /* 2 Copyright (c) 2019 Timur Gafarov 3 4 Boost Software License - Version 1.0 - August 17th, 2003 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 */ 27 28 module dagon.graphics.compressedimage; 29 30 import std.stdio; 31 32 import dlib.core.memory; 33 import dlib.image.color; 34 import dlib.image.image; 35 36 enum CompressedImageFormat 37 { 38 S3TC_RGB_DXT1, 39 S3TC_RGBA_DXT3, 40 S3TC_RGBA_DXT5, 41 42 RGTC1_R, 43 RGTC1_R_S, 44 RGTC2_RG, 45 RGTC2_RG_S, 46 47 BPTC_RGBA_UNORM, 48 BPTC_SRGBA_UNORM, 49 BPTC_RGB_SF, 50 BPTC_RGB_UF 51 } 52 53 class CompressedImage: SuperImage 54 { 55 uint _width; 56 uint _height; 57 CompressedImageFormat _compressedImageFormat; 58 uint _mipMapLevels; 59 size_t _bufferSize; 60 ubyte[] _data; 61 62 this(uint w, uint h, CompressedImageFormat format, uint mipmaps, size_t bufferSize) 63 { 64 _width = w; 65 _height = h; 66 _compressedImageFormat = format; 67 _mipMapLevels = mipmaps; 68 _bufferSize = bufferSize; 69 _data = New!(ubyte[])(_bufferSize); 70 } 71 72 ~this() 73 { 74 if (data.length) 75 Delete(_data); 76 } 77 78 void free() 79 { 80 Delete(this); 81 } 82 83 @property uint width() 84 { 85 return _width; 86 } 87 88 @property uint height() 89 { 90 return _height; 91 } 92 93 @property uint bitDepth() 94 { 95 return 0; 96 } 97 98 @property uint channels() 99 { 100 return 0; 101 } 102 103 @property uint pixelSize() 104 { 105 return 0; 106 } 107 108 @property uint pixelFormat() 109 { 110 return PixelFormat.RGBA8; 111 } 112 113 @property CompressedImageFormat compressedFormat() 114 { 115 return _compressedImageFormat; 116 } 117 118 @property uint mipMapLevels() 119 { 120 return _mipMapLevels; 121 } 122 123 @property ubyte[] data() 124 { 125 return _data; 126 } 127 128 @property SuperImage dup() 129 { 130 auto res = New!CompressedImage(_width, _height, _compressedImageFormat, _mipMapLevels, _bufferSize); 131 res.data[] = data[]; 132 return res; 133 } 134 135 SuperImage createSameFormat(uint w, uint h) 136 { 137 return null; 138 } 139 140 Color4f opIndex(int x, int y) 141 { 142 return Color4f(0.0f, 0.0f, 0.0f, 0.0f); 143 } 144 145 Color4f opIndexAssign(Color4f c, int x, int y) 146 { 147 return Color4f(0.0f, 0.0f, 0.0f, 0.0f); 148 } 149 }