ReactOS 0.4.15-dev-7834-g00c4b3d
txc_dxtn.h File Reference
#include <GL/gl.h>
Include dependency graph for txc_dxtn.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define UBYTE_TO_CHAN(b)   (b)
 
#define CHAN_MAX   255
 
#define RCOMP   0
 
#define GCOMP   1
 
#define BCOMP   2
 
#define ACOMP   3
 

Typedefs

typedef GLubyte GLchan
 

Functions

void fetch_2d_texel_rgb_dxt1 (GLint srcRowStride, const GLubyte *pixdata, GLint i, GLint j, GLvoid *texel)
 
void fetch_2d_texel_rgba_dxt1 (GLint srcRowStride, const GLubyte *pixdata, GLint i, GLint j, GLvoid *texel)
 
void fetch_2d_texel_rgba_dxt3 (GLint srcRowStride, const GLubyte *pixdata, GLint i, GLint j, GLvoid *texel)
 
void fetch_2d_texel_rgba_dxt5 (GLint srcRowStride, const GLubyte *pixdata, GLint i, GLint j, GLvoid *texel)
 
void tx_compress_dxtn (GLint srccomps, GLint width, GLint height, const GLubyte *srcPixData, GLenum destformat, GLubyte *dest, GLint dstRowStride)
 

Macro Definition Documentation

◆ ACOMP

#define ACOMP   3

Definition at line 36 of file txc_dxtn.h.

◆ BCOMP

#define BCOMP   2

Definition at line 35 of file txc_dxtn.h.

◆ CHAN_MAX

#define CHAN_MAX   255

Definition at line 32 of file txc_dxtn.h.

◆ GCOMP

#define GCOMP   1

Definition at line 34 of file txc_dxtn.h.

◆ RCOMP

#define RCOMP   0

Definition at line 33 of file txc_dxtn.h.

◆ UBYTE_TO_CHAN

#define UBYTE_TO_CHAN (   b)    (b)

Definition at line 31 of file txc_dxtn.h.

Typedef Documentation

◆ GLchan

typedef GLubyte GLchan

Definition at line 30 of file txc_dxtn.h.

Function Documentation

◆ fetch_2d_texel_rgb_dxt1()

void fetch_2d_texel_rgb_dxt1 ( GLint  srcRowStride,
const GLubyte pixdata,
GLint  i,
GLint  j,
GLvoid texel 
)

Definition at line 97 of file txc_fetch_dxtn.c.

99{
100 /* Extract the (i,j) pixel from pixdata and return it
101 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
102 */
103
104 const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8);
105 dxt135_decode_imageblock(blksrc, (i&3), (j&3), 0, texel);
106}
static void dxt135_decode_imageblock(const GLubyte *img_block_src, GLint i, GLint j, GLuint dxt_type, GLvoid *texel)
unsigned char GLubyte
Definition: gl.h:157
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static const unsigned char pixdata[]
Definition: surface.c:101

◆ fetch_2d_texel_rgba_dxt1()

void fetch_2d_texel_rgba_dxt1 ( GLint  srcRowStride,
const GLubyte pixdata,
GLint  i,
GLint  j,
GLvoid texel 
)

Definition at line 109 of file txc_fetch_dxtn.c.

111{
112 /* Extract the (i,j) pixel from pixdata and return it
113 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
114 */
115
116 const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8);
117 dxt135_decode_imageblock(blksrc, (i&3), (j&3), 1, texel);
118}

Referenced by D3DXLoadSurfaceFromMemory(), and wined3d_dxtn_init().

◆ fetch_2d_texel_rgba_dxt3()

void fetch_2d_texel_rgba_dxt3 ( GLint  srcRowStride,
const GLubyte pixdata,
GLint  i,
GLint  j,
GLvoid texel 
)

Definition at line 120 of file txc_fetch_dxtn.c.

121 {
122
123 /* Extract the (i,j) pixel from pixdata and return it
124 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
125 */
126
127 GLchan *rgba = (GLchan *) texel;
128 const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 16);
129#if 0
130 /* Simple 32bit version. */
131/* that's pretty brain-dead for a single pixel, isn't it? */
132 const GLubyte bit_pos = 4 * ((j&3) * 4 + (i&3));
133 const GLuint alpha_low = blksrc[0] | (blksrc[1] << 8) | (blksrc[2] << 16) | (blksrc[3] << 24);
134 const GLuint alpha_high = blksrc[4] | (blksrc[5] << 8) | (blksrc[6] << 16) | (blksrc[7] << 24);
135
136 dxt135_decode_imageblock(blksrc + 8, (i&3), (j&3), 2, texel);
137 if (bit_pos < 32)
138 rgba[ACOMP] = UBYTE_TO_CHAN( (GLubyte)(EXP4TO8((alpha_low >> bit_pos) & 15)) );
139 else
140 rgba[ACOMP] = UBYTE_TO_CHAN( (GLubyte)(EXP4TO8((alpha_high >> (bit_pos - 32)) & 15)) );
141#endif
142#if 1
143/* TODO test this! */
144 const GLubyte anibble = (blksrc[((j&3) * 4 + (i&3)) / 2] >> (4 * (i&1))) & 0xf;
145 dxt135_decode_imageblock(blksrc + 8, (i&3), (j&3), 2, texel);
146 rgba[ACOMP] = UBYTE_TO_CHAN( (GLubyte)(EXP4TO8(anibble)) );
147#endif
148
149}
#define ACOMP
Definition: txc_dxtn.h:36
GLubyte GLchan
Definition: txc_dxtn.h:30
#define UBYTE_TO_CHAN(b)
Definition: txc_dxtn.h:31
#define EXP4TO8(col)
unsigned int GLuint
Definition: gl.h:159

Referenced by D3DXLoadSurfaceFromMemory(), and wined3d_dxtn_init().

◆ fetch_2d_texel_rgba_dxt5()

void fetch_2d_texel_rgba_dxt5 ( GLint  srcRowStride,
const GLubyte pixdata,
GLint  i,
GLint  j,
GLvoid texel 
)

Definition at line 151 of file txc_fetch_dxtn.c.

152 {
153
154 /* Extract the (i,j) pixel from pixdata and return it
155 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
156 */
157
158 GLchan *rgba = (GLchan *) texel;
159 const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 16);
160 const GLubyte alpha0 = blksrc[0];
161 const GLubyte alpha1 = blksrc[1];
162#if 0
163 const GLubyte bit_pos = 3 * ((j&3) * 4 + (i&3));
164 /* simple 32bit version */
165 const GLuint bits_low = blksrc[2] | (blksrc[3] << 8) | (blksrc[4] << 16) | (blksrc[5] << 24);
166 const GLuint bits_high = blksrc[6] | (blksrc[7] << 8);
168
169 if (bit_pos < 30)
170 code = (GLubyte) ((bits_low >> bit_pos) & 7);
171 else if (bit_pos == 30)
172 code = (GLubyte) ((bits_low >> 30) & 3) | ((bits_high << 2) & 4);
173 else
174 code = (GLubyte) ((bits_high >> (bit_pos - 32)) & 7);
175#endif
176#if 1
177/* TODO test this! */
178 const GLubyte bit_pos = ((j&3) * 4 + (i&3)) * 3;
179 const GLubyte acodelow = blksrc[2 + bit_pos / 8];
180 const GLubyte acodehigh = blksrc[3 + bit_pos / 8];
181 const GLubyte code = (acodelow >> (bit_pos & 0x7) |
182 (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7;
183#endif
184 dxt135_decode_imageblock(blksrc + 8, (i&3), (j&3), 2, texel);
185#if 0
186 if (alpha0 > alpha1) {
187 switch (code) {
188 case 0:
189 rgba[ACOMP] = UBYTE_TO_CHAN( alpha0 );
190 break;
191 case 1:
192 rgba[ACOMP] = UBYTE_TO_CHAN( alpha1 );
193 break;
194 case 2:
195 case 3:
196 case 4:
197 case 5:
198 case 6:
199 case 7:
200 rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7) );
201 break;
202 }
203 }
204 else {
205 switch (code) {
206 case 0:
207 rgba[ACOMP] = UBYTE_TO_CHAN( alpha0 );
208 break;
209 case 1:
210 rgba[ACOMP] = UBYTE_TO_CHAN( alpha1 );
211 break;
212 case 2:
213 case 3:
214 case 4:
215 case 5:
216 rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5) );
217 break;
218 case 6:
219 rgba[ACOMP] = 0;
220 break;
221 case 7:
222 rgba[ACOMP] = CHAN_MAX;
223 break;
224 }
225 }
226#endif
227/* not sure. Which version is faster? */
228#if 1
229/* TODO test this */
230 if (code == 0)
231 rgba[ACOMP] = UBYTE_TO_CHAN( alpha0 );
232 else if (code == 1)
233 rgba[ACOMP] = UBYTE_TO_CHAN( alpha1 );
234 else if (alpha0 > alpha1)
235 rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7) );
236 else if (code < 6)
237 rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5) );
238 else if (code == 6)
239 rgba[ACOMP] = 0;
240 else
241 rgba[ACOMP] = CHAN_MAX;
242#endif
243}
#define CHAN_MAX
Definition: txc_dxtn.h:32
Definition: inflate.c:139

Referenced by D3DXLoadSurfaceFromMemory(), and wined3d_dxtn_init().

◆ tx_compress_dxtn()

void tx_compress_dxtn ( GLint  srccomps,
GLint  width,
GLint  height,
const GLubyte srcPixData,
GLenum  destformat,
GLubyte dest,
GLint  dstRowStride 
)

Definition at line 758 of file txc_compress_dxtn.c.

760{
761 GLubyte *blkaddr = dest;
762 GLubyte srcpixels[4][4][4];
763 const GLchan *srcaddr = srcPixData;
764 GLint numxpixels, numypixels;
765 GLint i, j;
766 GLint dstRowDiff;
767
768 switch (destFormat) {
771 /* hmm we used to get called without dstRowStride... */
772 dstRowDiff = dstRowStride >= (width * 2) ? dstRowStride - (((width + 3) & ~3) * 2) : 0;
773/* fprintf(stderr, "dxt1 tex width %d tex height %d dstRowStride %d\n",
774 width, height, dstRowStride); */
775 for (j = 0; j < height; j += 4) {
776 if (height > j + 3) numypixels = 4;
777 else numypixels = height - j;
778 srcaddr = srcPixData + j * width * srccomps;
779 for (i = 0; i < width; i += 4) {
780 if (width > i + 3) numxpixels = 4;
781 else numxpixels = width - i;
782 extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
783 encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat);
784 srcaddr += srccomps * numxpixels;
785 blkaddr += 8;
786 }
787 blkaddr += dstRowDiff;
788 }
789 break;
791 dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0;
792/* fprintf(stderr, "dxt3 tex width %d tex height %d dstRowStride %d\n",
793 width, height, dstRowStride); */
794 for (j = 0; j < height; j += 4) {
795 if (height > j + 3) numypixels = 4;
796 else numypixels = height - j;
797 srcaddr = srcPixData + j * width * srccomps;
798 for (i = 0; i < width; i += 4) {
799 if (width > i + 3) numxpixels = 4;
800 else numxpixels = width - i;
801 extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
802 *blkaddr++ = (srcpixels[0][0][3] >> 4) | (srcpixels[0][1][3] & 0xf0);
803 *blkaddr++ = (srcpixels[0][2][3] >> 4) | (srcpixels[0][3][3] & 0xf0);
804 *blkaddr++ = (srcpixels[1][0][3] >> 4) | (srcpixels[1][1][3] & 0xf0);
805 *blkaddr++ = (srcpixels[1][2][3] >> 4) | (srcpixels[1][3][3] & 0xf0);
806 *blkaddr++ = (srcpixels[2][0][3] >> 4) | (srcpixels[2][1][3] & 0xf0);
807 *blkaddr++ = (srcpixels[2][2][3] >> 4) | (srcpixels[2][3][3] & 0xf0);
808 *blkaddr++ = (srcpixels[3][0][3] >> 4) | (srcpixels[3][1][3] & 0xf0);
809 *blkaddr++ = (srcpixels[3][2][3] >> 4) | (srcpixels[3][3][3] & 0xf0);
810 encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat);
811 srcaddr += srccomps * numxpixels;
812 blkaddr += 8;
813 }
814 blkaddr += dstRowDiff;
815 }
816 break;
818 dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0;
819/* fprintf(stderr, "dxt5 tex width %d tex height %d dstRowStride %d\n",
820 width, height, dstRowStride); */
821 for (j = 0; j < height; j += 4) {
822 if (height > j + 3) numypixels = 4;
823 else numypixels = height - j;
824 srcaddr = srcPixData + j * width * srccomps;
825 for (i = 0; i < width; i += 4) {
826 if (width > i + 3) numxpixels = 4;
827 else numxpixels = width - i;
828 extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
829 encodedxt5alpha(blkaddr, srcpixels, numxpixels, numypixels);
830 encodedxtcolorblockfaster(blkaddr + 8, srcpixels, numxpixels, numypixels, destFormat);
831 srcaddr += srccomps * numxpixels;
832 blkaddr += 16;
833 }
834 blkaddr += dstRowDiff;
835 }
836 break;
837 default:
838 fprintf(stderr, "libdxtn: Bad dstFormat %d in tx_compress_dxtn\n", destFormat);
839 return;
840 }
841}
static void encodedxtcolorblockfaster(GLubyte *blkaddr, GLubyte srccolors[4][4][4], GLint numxpixels, GLint numypixels, GLuint type)
static void encodedxt5alpha(GLubyte *blkaddr, GLubyte srccolors[4][4][4], GLint numxpixels, GLint numypixels)
static void extractsrccolors(GLubyte srcpixels[4][4][4], const GLchan *srcaddr, GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps)
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
int GLint
Definition: gl.h:156
GLint GLint GLsizei width
Definition: gl.h:1546
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
Definition: glext.h:3492
#define GL_COMPRESSED_RGB_S3TC_DXT1_EXT
Definition: glext.h:3489
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
Definition: glext.h:3491
#define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
Definition: glext.h:3490
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static char * dest
Definition: rtl.c:135