#include <string.h>
#include <stdint.h>
#include <getopt.h>
-
-#include "s2tc_compressor.h"
+#include <algorithm>
#include "s2tc_common.h"
+extern "C"
+{
+#include "txc_dxtn.h"
+};
+
/* START stuff that originates from image.c in DarkPlaces */
+/*
+ Thu Jul 14 21:58:02 CEST 2011
+ 21:25:25 @divVerent | LordHavoc: http://paste.pocoo.org/show/438804/
+ 21:25:31 @divVerent | can I have this code under a MIT-style license?
+ 21:59:58 @LordHavoc | divVerent: yeah, have them under any license you want
+ 22:00:11 @LordHavoc | divVerent: my attitude toward licenses is generally "WTFPL would be preferably if I could use it" :P
+ 22:04:01 @divVerent | LordHavoc: okay, thanks
+*/
+
int image_width, image_height;
typedef struct _TargaHeader
fclose(f);
return buf;
}
-/* end of darkplaces stuff */
+/* END of darkplaces stuff */
uint32_t LittleLong(uint32_t w)
{
"%s \n"
" [-i infile.tga]\n"
" [-o outfile.dds]\n"
- " [-t {DXT1|DXT3|DXT5}]\n"
- " [-r randomcount]\n"
- " [-c {RGB|YUV|SRGB|SRGB_MIXED|LAB|AVG|WAVG|NORMALMAP}]\n",
+ " [-t {DXT1|DXT3|DXT5}]\n",
me);
return 1;
}
int main(int argc, char **argv)
{
- int x, y;
unsigned char *pic, *picdata;
int piclen;
const char *fourcc;
- int blocksize, alpharange;
- DxtMode dxt = DXT1;
- ColorDistMode cd = RGB;
- int nrandom = 0;
+ int blocksize;
+ GLenum dxt = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
const char *infile = NULL, *outfile = NULL;
FILE *outfh;
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;
- else
- return usage(argv[0]);
- break;
- case 'r':
- nrandom = atoi(optarg);
- 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;
+ dxt = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
else
return usage(argv[0]);
break;
}
pic = LoadTGA_BGRA(picdata, piclen);
+ for(int x = 0; x < image_width*image_height; ++x)
+ std::swap(pic[4*x], pic[4*x+2]);
+
int mipcount = 0;
while(image_width >= (1 << mipcount) || image_height >= (1 << mipcount))
++mipcount;
switch(dxt)
{
- case DXT1:
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
blocksize = 8;
- alpharange = 1;
fourcc = "DXT1";
break;
- case DXT3:
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
blocksize = 16;
- alpharange = 15;
fourcc = "DXT3";
break;
default:
- case DXT5:
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
blocksize = 16;
- alpharange = 255;
fourcc = "DXT5";
break;
}
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, alpharange);
- for(y = 0; y < image_height; y += 4)
- for(x = 0; x < image_width; x += 4)
- {
- unsigned char block[16];
- s2tc_encode_block(block, opic + (x + y * image_width) * 4, image_width, min(4, image_width - x), min(4, image_height - y), dxt, cd, 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);