1 | /****************************************************************************** |
---|
2 | * Fast DXT - a realtime DXT compression tool |
---|
3 | * |
---|
4 | * Author : Luc Renambot |
---|
5 | * |
---|
6 | * Copyright (C) 2007 Electronic Visualization Laboratory, |
---|
7 | * University of Illinois at Chicago |
---|
8 | * |
---|
9 | * All rights reserved. |
---|
10 | * |
---|
11 | * Redistribution and use in source and binary forms, with or without |
---|
12 | * modification, are permitted provided that the following conditions are met: |
---|
13 | * |
---|
14 | * * Redistributions of source code must retain the above copyright |
---|
15 | * notice, this list of conditions and the following disclaimer. |
---|
16 | * * Redistributions in binary form must reproduce the above |
---|
17 | * copyright notice, this list of conditions and the following disclaimer |
---|
18 | * in the documentation and/or other materials provided with the distribution. |
---|
19 | * * Neither the name of the University of Illinois at Chicago nor |
---|
20 | * the names of its contributors may be used to endorse or promote |
---|
21 | * products derived from this software without specific prior written permission. |
---|
22 | * |
---|
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
34 | * |
---|
35 | * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/ |
---|
36 | * |
---|
37 | *****************************************************************************/ |
---|
38 | |
---|
39 | // |
---|
40 | // Usage: ./2dxt width height type rawfile dxtfile |
---|
41 | // |
---|
42 | |
---|
43 | #define NUMTHREAD 2 |
---|
44 | |
---|
45 | #include "libdxt.h" |
---|
46 | |
---|
47 | int |
---|
48 | main(int argc, char** argv) |
---|
49 | { |
---|
50 | byte *in; |
---|
51 | byte *out; |
---|
52 | int nbbytes; |
---|
53 | |
---|
54 | if (argc != 6) |
---|
55 | { |
---|
56 | fprintf(stderr, "Usage: ./2dxt width height type rawfile dxtfile\n"); |
---|
57 | exit(0); |
---|
58 | } |
---|
59 | // Initialize some timing functions and else |
---|
60 | aInitialize(); |
---|
61 | |
---|
62 | /* |
---|
63 | Read an image. |
---|
64 | */ |
---|
65 | unsigned long width = atoi(argv[1]); |
---|
66 | unsigned long height = atoi(argv[2]); |
---|
67 | |
---|
68 | int format = 1; |
---|
69 | format = atoi(argv[3]); |
---|
70 | |
---|
71 | in = (byte*)memalign(16, width*height*4); |
---|
72 | memset(in, 0, width*height*4); |
---|
73 | |
---|
74 | FILE *f=fopen(argv[4], "rb"); |
---|
75 | int res=(int)fread(in, 1, width*height*4, f); |
---|
76 | fclose(f); |
---|
77 | |
---|
78 | out = (byte*)memalign(16, width*height*4); |
---|
79 | memset(out, 0, width*height*4); |
---|
80 | |
---|
81 | fprintf(stderr, "Converting to raw: %ldx%ld\n", width, height); |
---|
82 | |
---|
83 | double t1, t2; |
---|
84 | t1 = aTime(); |
---|
85 | nbbytes = 0; |
---|
86 | switch (format) { |
---|
87 | case 1: |
---|
88 | nbbytes = CompressDXT(in, out, width, height, FORMAT_DXT1, NUMTHREAD); |
---|
89 | fprintf(stderr, "Converted to DXT1: from %d bytes to %ld bytes\n", |
---|
90 | width*height*4, nbbytes); |
---|
91 | break; |
---|
92 | case 5: |
---|
93 | nbbytes = CompressDXT(in, out, width, height, FORMAT_DXT5, NUMTHREAD); |
---|
94 | fprintf(stderr, "Converted to DXT5: from %d bytes to %ld bytes\n", |
---|
95 | width*height*4, nbbytes); |
---|
96 | break; |
---|
97 | case 6: |
---|
98 | nbbytes = CompressDXT(in, out, width, height, FORMAT_DXT5YCOCG, NUMTHREAD); |
---|
99 | fprintf(stderr, "Converted to DXT5-YCoCg: from %d bytes to %ld bytes\n", |
---|
100 | width*height*4, nbbytes); |
---|
101 | break; |
---|
102 | } |
---|
103 | t2 = aTime(); |
---|
104 | |
---|
105 | fprintf(stderr, "Time %.2f sec, Freq %.2f Hz\n", |
---|
106 | t2-t1, 1.0/(t2-t1) ); |
---|
107 | fprintf(stderr, "MP/sec %.2f\n", |
---|
108 | ((double)(width*height)) / ((t2-t1)*1000000.0) ); |
---|
109 | |
---|
110 | FILE *g=fopen(argv[5], "wb+"); |
---|
111 | fwrite(&width, 4, 1, g); |
---|
112 | fwrite(&height, 4, 1, g); |
---|
113 | int res2=(int)fwrite(out, 1, nbbytes, g); |
---|
114 | fclose(g); |
---|
115 | |
---|
116 | memfree(in); |
---|
117 | memfree(out); |
---|
118 | |
---|
119 | return 0; |
---|
120 | } |
---|
121 | |
---|