include $(wildcard *.d)
-s2tc: s2tc.o s2tc_compressor.o
+s2tc: s2tc.o libtxc_dxtn.so
$(CXX) $(LDFLAGS) -o $@ $+
-s2tc_decompress: s2tc_decompress.o s2tc_libtxc_dxtn.o s2tc_compressor.o
+s2tc_decompress: s2tc_decompress.o libtxc_dxtn.so
$(CXX) $(LDFLAGS) -o $@ $+
libtxc_dxtn.so: s2tc_libtxc_dxtn.o s2tc_compressor.o
- $(CXX) $(LDFLAGS) -shared -o $@ $+
+ $(CXX) $(LDFLAGS) -shared -Wl,-soname=./libtxc_dxtn.so -o $@ $+
clean:
$(RM) *.o s2tc libtxc_dxtn.so
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);
#ifdef __cplusplus
}
#include <string.h>
#include <stdint.h>
#include <getopt.h>
-
-#include "s2tc_compressor.h"
+#include "libtxc_dxtn.h"
#include "s2tc_common.h"
/* START stuff that originates from image.c in DarkPlaces */
int piclen;
const char *fourcc;
int blocksize, alphabits;
- DxtMode dxt = DXT1;
- ColorDistMode cd = RGB;
- int nrandom = 0;
+ GLenum dxt = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
const char *infile = NULL, *outfile = NULL;
FILE *outfh;
+ char buf[80];
int opt;
while((opt = getopt(argc, argv, "i:o:t:r:c:")) != -1)
break;
case 't':
if(!strcasecmp(optarg, "DXT1"))
- dxt = DXT1;
+ dxt = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
else if(!strcasecmp(optarg, "DXT3"))
- dxt = DXT3;
+ dxt = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
else if(!strcasecmp(optarg, "DXT5"))
- dxt = DXT5;
+ dxt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
else
return usage(argv[0]);
break;
case 'r':
- nrandom = atoi(optarg);
+ snprintf(buf, sizeof(buf), "S2TC_RANDOM_COLORS=%d", atoi(optarg));
+ buf[sizeof(buf)-1] = 0;
+ putenv(buf);
break;
case 'c':
- if(!strcasecmp(optarg, "RGB"))
- cd = RGB;
- else if(!strcasecmp(optarg, "YUV"))
- cd = YUV;
- else if(!strcasecmp(optarg, "SRGB"))
- cd = SRGB;
- else if(!strcasecmp(optarg, "SRGB_MIXED"))
- cd = SRGB_MIXED;
- else if(!strcasecmp(optarg, "LAB"))
- cd = LAB;
- else if(!strcasecmp(optarg, "AVG"))
- cd = AVG;
- else if(!strcasecmp(optarg, "WAVG"))
- cd = WAVG;
- else if(!strcasecmp(optarg, "NORMALMAP"))
- cd = NORMALMAP;
- else
- return usage(argv[0]);
+ snprintf(buf, sizeof(buf), "S2TC_COLORDIST_MODE=%s", optarg);
+ buf[sizeof(buf)-1] = 0;
+ putenv(buf);
break;
default:
return usage(argv[0]);
switch(dxt)
{
- case DXT1:
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
blocksize = 8;
alphabits = 1;
fourcc = "DXT1";
break;
- case DXT3:
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
blocksize = 16;
alphabits = 4;
fourcc = "DXT3";
break;
default:
- case DXT5:
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
blocksize = 16;
alphabits = 8;
fourcc = "DXT5";
fwrite(&zero, 4, 1, outfh);
}
- unsigned char *opic = (unsigned char *) malloc(image_width * image_height * 4);
for(;;)
{
- rgb565_image(opic, pic, image_width, image_height, 4, 1, alphabits);
- s2tc_encode_block_func_t encode_block = s2tc_encode_block_func(dxt, cd, nrandom);
- for(y = 0; y < image_height; y += 4)
- for(x = 0; x < image_width; x += 4)
- {
- unsigned char block[16];
- encode_block(block, opic + (x + y * image_width) * 4, image_width, min(4, image_width - x), min(4, image_height - y), nrandom);
- fwrite(block, blocksize, 1, outfh);
- }
+ int blocks_w = (image_width + 3) / 4;
+ int blocks_h = (image_height + 3) / 4;
+ GLubyte *obuf = (GLubyte *) malloc(blocksize * blocks_w * blocks_h);
+ tx_compress_dxtn(4, image_width, image_height, pic, dxt, obuf, blocks_w * blocksize);
+ fwrite(obuf, blocksize * blocks_w * blocks_h, 1, outfh);
+ free(obuf);
if(image_width == 1 && image_height == 1)
break;
Image_MipReduce32(pic, pic, &image_width, &image_height, 1, 1);
#include "libtxc_dxtn.h"
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include "s2tc_compressor.h"
void fetch_2d_texel_rgb_dxt1(GLint srcRowStride, const GLubyte *pixdata,
GLint dstRowDiff;
unsigned char *rgba = (unsigned char *) malloc(width * height * 4);
unsigned char *srcaddr;
+ DxtMode dxt;
switch (destFormat) {
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ dxt = DXT1;
rgb565_image(rgba, srcPixData, width, height, srccomps, 0, 1);
break;
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ dxt = DXT3;
rgb565_image(rgba, srcPixData, width, height, srccomps, 0, 4);
break;
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ dxt = DXT5;
rgb565_image(rgba, srcPixData, width, height, srccomps, 0, 8);
break;
default:
return;
}
- s2tc_encode_block_func_t encode_block;
+ ColorDistMode cd = WAVG;
+ int nrandom = -1;
+ {
+ const char *v = getenv("S2TC_COLORDIST_MODE");
+ if(v)
+ {
+ if(!strcasecmp(v, "RGB"))
+ cd = RGB;
+ else if(!strcasecmp(v, "YUV"))
+ cd = YUV;
+ else if(!strcasecmp(v, "SRGB"))
+ cd = SRGB;
+ else if(!strcasecmp(v, "SRGB_MIXED"))
+ cd = SRGB_MIXED;
+ else if(!strcasecmp(v, "LAB"))
+ cd = LAB;
+ else if(!strcasecmp(v, "AVG"))
+ cd = AVG;
+ else if(!strcasecmp(v, "WAVG"))
+ cd = WAVG;
+ else if(!strcasecmp(v, "NORMALMAP"))
+ cd = NORMALMAP;
+ else
+ fprintf(stderr, "Invalid color dist mode: %s\n", v);
+ }
+ }
+ {
+ const char *v = getenv("S2TC_RANDOM_COLORS");
+ if(v)
+ nrandom = atoi(v);
+ }
+
+ s2tc_encode_block_func_t encode_block = s2tc_encode_block_func(dxt, cd, nrandom);
switch (destFormat) {
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
dstRowDiff = dstRowStride >= (width * 2) ? dstRowStride - (((width + 3) & ~3) * 2) : 0;
/* fprintf(stderr, "dxt1 tex width %d tex height %d dstRowStride %d\n",
width, height, dstRowStride); */
- encode_block = s2tc_encode_block_func(DXT1, WAVG, -1);
for (j = 0; j < height; j += 4) {
if (height > j + 3) numypixels = 4;
else numypixels = height - j;
dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0;
/* fprintf(stderr, "dxt3 tex width %d tex height %d dstRowStride %d\n",
width, height, dstRowStride); */
- encode_block = s2tc_encode_block_func(DXT3, WAVG, -1);
for (j = 0; j < height; j += 4) {
if (height > j + 3) numypixels = 4;
else numypixels = height - j;
dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0;
/* fprintf(stderr, "dxt5 tex width %d tex height %d dstRowStride %d\n",
width, height, dstRowStride); */
- encode_block = s2tc_encode_block_func(DXT5, WAVG, -1);
for (j = 0; j < height; j += 4) {
if (height > j + 3) numypixels = 4;
else numypixels = height - j;