OSDN Git Service

s2tc_compress: add a -l option to specify the library to load
[android-x86/external-s2tc.git] / s2tc_libtxc_dxtn.cpp
index 35dce98..fa296a7 100644 (file)
@@ -1,3 +1,26 @@
+/*
+ * Copyright (C) 2011  Rudolf Polzer   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * RUDOLF POLZER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#define S2TC_LICENSE_IDENTIFIER s2tc_libtxc_dxtn_license
+#include "s2tc_license.h"
+
 extern "C"
 {
 #include "txc_dxtn.h"
@@ -130,29 +153,24 @@ void tx_compress_dxtn(GLint srccomps, GLint width, GLint height,
        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:
-                       free(rgba);
-                       fprintf(stderr, "libdxtn: Bad dstFormat %d in tx_compress_dxtn\n", destformat);
-                       return;
-       }
-
        ColorDistMode cd = WAVG;
        int nrandom = -1;
        RefinementMode refine = REFINE_ALWAYS;
+       DitherMode dither = DITHER_SIMPLE;
+       {
+               const char *v = getenv("S2TC_DITHER_MODE");
+               if(v)
+               {
+                       if(!strcasecmp(v, "NONE"))
+                               dither = DITHER_NONE;
+                       else if(!strcasecmp(v, "SIMPLE"))
+                               dither = DITHER_SIMPLE;
+                       else if(!strcasecmp(v, "FLOYDSTEINBERG"))
+                               dither = DITHER_FLOYDSTEINBERG;
+                       else
+                               fprintf(stderr, "Invalid dither mode: %s\n", v);
+               }
+       }
        {
                const char *v = getenv("S2TC_COLORDIST_MODE");
                if(v)
@@ -199,6 +217,26 @@ void tx_compress_dxtn(GLint srccomps, GLint width, GLint height,
                }
        }
 
+       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, dither);
+                       break;
+               case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+                       dxt = DXT3;
+                       rgb565_image(rgba, srcPixData, width, height, srccomps, 0, 4, dither);
+                       break;
+               case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+                       dxt = DXT5;
+                       rgb565_image(rgba, srcPixData, width, height, srccomps, 0, 8, dither);
+                       break;
+               default:
+                       free(rgba);
+                       fprintf(stderr, "libdxtn: Bad dstFormat %d in tx_compress_dxtn\n", destformat);
+                       return;
+       }
+
        s2tc_encode_block_func_t encode_block = s2tc_encode_block_func(dxt, cd, nrandom, refine);
        switch (destformat) {
                case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: