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 | #include "dxt.h" |
---|
40 | #include "util.h" |
---|
41 | |
---|
42 | #if defined(__APPLE__) |
---|
43 | #define memalign(x,y) malloc((y)) |
---|
44 | #else |
---|
45 | #include <malloc.h> |
---|
46 | #endif |
---|
47 | |
---|
48 | int |
---|
49 | main(int argc, char** argv) |
---|
50 | { |
---|
51 | ALIGN16( byte *in ); |
---|
52 | ALIGN16( byte *out); |
---|
53 | double t1, t2; |
---|
54 | int nbbytes; |
---|
55 | |
---|
56 | // Initialize some timing functions and else |
---|
57 | aInitialize(); |
---|
58 | |
---|
59 | /* |
---|
60 | Read an image. |
---|
61 | */ |
---|
62 | unsigned long width = atoi(argv[1]); |
---|
63 | unsigned long height = atoi(argv[2]); |
---|
64 | |
---|
65 | in = (byte*)memalign(16, width*height*4); |
---|
66 | memset(in, 0, width*height*4); |
---|
67 | |
---|
68 | FILE *f=fopen(argv[3], "rb"); |
---|
69 | fread(in, 1, width*height*4, f); |
---|
70 | fclose(f); |
---|
71 | |
---|
72 | out = (byte*)memalign(16, width*height*4); |
---|
73 | memset(out, 0, width*height*4); |
---|
74 | |
---|
75 | fprintf(stderr, "Converting to raw: %ldx%ld\n", width, height); |
---|
76 | |
---|
77 | t1 = aTime(); |
---|
78 | for (int k=0;k<100;k++) |
---|
79 | { |
---|
80 | CompressImageDXT1( in, out, width, height, nbbytes); |
---|
81 | } |
---|
82 | t2 = aTime(); |
---|
83 | |
---|
84 | fprintf(stderr, "Converted to DXT: %d byte, compression %ld\n", |
---|
85 | nbbytes, (width*height*4) / (nbbytes)); |
---|
86 | fprintf(stderr, "Time %.2f sec, Single %.2f sec, Freq %.2f Hz\n", |
---|
87 | t2-t1, (t2-t1)/100.0, 100.0/(t2-t1) ); |
---|
88 | fprintf(stderr, "MP/sec %.2f\n", |
---|
89 | ((double)(width*height)) / ((t2-t1)*10000.0) ); |
---|
90 | |
---|
91 | #if 1 |
---|
92 | FILE *g=fopen("out.dxt", "wb+"); |
---|
93 | fwrite(&width, 4, 1, g); |
---|
94 | fwrite(&height, 4, 1, g); |
---|
95 | //nbbytes = width * height * 4 / 4; //DXT5 |
---|
96 | nbbytes = width * height * 3 / 6; // DXT1 |
---|
97 | fwrite(out, 1, nbbytes, g); |
---|
98 | fclose(g); |
---|
99 | #endif |
---|
100 | |
---|
101 | memfree(in); |
---|
102 | memfree(out); |
---|
103 | |
---|
104 | return 0; |
---|
105 | } |
---|