source: trunk/src/testing/app/ishare/FastDXT/example.cpp @ 4

Revision 4, 3.3 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

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