[4] | 1 | /****************************************************************************** |
---|
| 2 | * Author : Byungil Jeong |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 2004 Electronic Visualization Laboratory, |
---|
| 5 | * University of Illinois at Chicago |
---|
| 6 | * |
---|
| 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright |
---|
| 13 | * notice, this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above |
---|
| 15 | * copyright notice, this list of conditions and the following disclaimer |
---|
| 16 | * in the documentation and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the University of Illinois at Chicago nor |
---|
| 18 | * the names of its contributors may be used to endorse or promote |
---|
| 19 | * products derived from this software without specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
---|
| 25 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
---|
| 26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
---|
| 27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
---|
| 28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
---|
| 29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
---|
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | * |
---|
| 33 | * Direct questions, comments etc about SAGE to bijeong@evl.uic.edu or |
---|
| 34 | * http://www.evl.uic.edu/cavern/forum/ |
---|
| 35 | * |
---|
| 36 | *****************************************************************************/ |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | //A simple test program that pushes DXT pixels to SAGE frame buffer |
---|
| 41 | //written by Luc Renambot |
---|
| 42 | //Feb 2007 |
---|
| 43 | |
---|
| 44 | #include <stdio.h> |
---|
| 45 | #include <math.h> |
---|
| 46 | #include <stdlib.h> |
---|
| 47 | #include "dxt.h" |
---|
| 48 | #include <wand/magick_wand.h> |
---|
| 49 | |
---|
| 50 | // headers for SAGE |
---|
| 51 | #include "sail.h" |
---|
| 52 | #include "misc.h" |
---|
| 53 | |
---|
| 54 | #define ThrowWandException(wand) \ |
---|
| 55 | { \ |
---|
| 56 | char \ |
---|
| 57 | *description; \ |
---|
| 58 | \ |
---|
| 59 | ExceptionType \ |
---|
| 60 | severity; \ |
---|
| 61 | \ |
---|
| 62 | description=MagickGetException(wand,&severity); \ |
---|
| 63 | (void) fprintf(stderr,"%s %s %ld %s\n",GetMagickModule(),description); \ |
---|
| 64 | description=(char *) MagickRelinquishMemory(description); \ |
---|
| 65 | exit(-1); \ |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | int main(int argc, char *argv[]) |
---|
| 70 | { |
---|
| 71 | sail sageInf; // sail object |
---|
| 72 | int nodeID; |
---|
| 73 | |
---|
| 74 | byte *in; |
---|
| 75 | int nbbytes; |
---|
| 76 | |
---|
| 77 | nodeID = 0; |
---|
| 78 | |
---|
| 79 | /* |
---|
| 80 | Read an image. |
---|
| 81 | */ |
---|
| 82 | MagickBooleanType status; |
---|
| 83 | MagickWand *magick_wand; |
---|
| 84 | |
---|
| 85 | int count = 1; |
---|
| 86 | int framenb = atoi(argv[2]); |
---|
| 87 | char fn[256]; |
---|
| 88 | |
---|
| 89 | memset(fn, 0, 256); |
---|
| 90 | sprintf(fn, "%s/%08d.tga", argv[1], count++); |
---|
| 91 | |
---|
| 92 | magick_wand=NewMagickWand(); |
---|
| 93 | status=MagickReadImage(magick_wand, fn); |
---|
| 94 | if (status == MagickFalse) |
---|
| 95 | ThrowWandException(magick_wand); |
---|
| 96 | |
---|
| 97 | unsigned long width = MagickGetImageWidth(magick_wand); |
---|
| 98 | unsigned long height = MagickGetImageHeight(magick_wand); |
---|
| 99 | |
---|
| 100 | int resX = width; |
---|
| 101 | int resY = height; |
---|
| 102 | |
---|
| 103 | std::cout << "File = " << argv[1] << std::endl; |
---|
| 104 | std::cout << std::endl << "ResX = " << resX << " ResY = " << resY << std::endl; |
---|
| 105 | |
---|
| 106 | in = (byte*)malloc(width*height*4); |
---|
| 107 | memset(in, 0, width*height*4); |
---|
| 108 | |
---|
| 109 | fprintf(stderr, "Converting to raw: %ldx%ld\n", width, height); |
---|
| 110 | MagickGetImagePixels(magick_wand, 0, 0, width, height, "RGBA", CharPixel, in); |
---|
| 111 | |
---|
| 112 | sailConfig scfg; |
---|
| 113 | scfg.init("dxt.conf"); |
---|
| 114 | scfg.setAppName("dxt"); |
---|
| 115 | scfg.rank = nodeID; |
---|
| 116 | |
---|
| 117 | scfg.resX = resX; |
---|
| 118 | scfg.resY = resY; |
---|
| 119 | |
---|
| 120 | sageRect renderImageMap; |
---|
| 121 | renderImageMap.left = 0.0; |
---|
| 122 | renderImageMap.right = 1.0; |
---|
| 123 | renderImageMap.bottom = 0.0; |
---|
| 124 | renderImageMap.top = 1.0; |
---|
| 125 | |
---|
| 126 | scfg.imageMap = renderImageMap; |
---|
| 127 | scfg.pixFmt = PIXFMT_DXT; |
---|
| 128 | //scfg.rowOrd = TOP_TO_BOTTOM; |
---|
| 129 | scfg.rowOrd = BOTTOM_TO_TOP; |
---|
| 130 | scfg.master = true; |
---|
| 131 | scfg.nwID = 1; |
---|
| 132 | |
---|
| 133 | sageInf.init(scfg); |
---|
| 134 | std::cout << "sail initialized " << std::endl; |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | void *buffer = sageInf.getBuffer(); |
---|
| 138 | nbbytes = 0; |
---|
| 139 | CompressImageDXT1( in, (byte*)buffer, width, height, nbbytes); |
---|
| 140 | |
---|
| 141 | sageInf.swapBuffer(); |
---|
| 142 | buffer = sageInf.getBuffer(); |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | while(1) { |
---|
| 146 | fprintf(stderr, "Frame %d\n", count); |
---|
| 147 | memset(fn, 0, 256); |
---|
| 148 | sprintf(fn, "%s/%08d.tga", argv[1], count); |
---|
| 149 | count = (count + 1) % framenb; |
---|
| 150 | if (count == 0) count = 1; |
---|
| 151 | |
---|
| 152 | MagickRemoveImage(magick_wand); |
---|
| 153 | status=MagickReadImage(magick_wand, fn); |
---|
| 154 | if (status == MagickFalse) |
---|
| 155 | ThrowWandException(magick_wand); |
---|
| 156 | MagickGetImagePixels(magick_wand, 0, 0, width, height, "RGBA", CharPixel, in); |
---|
| 157 | |
---|
| 158 | nbbytes = 0; |
---|
| 159 | CompressImageDXT1( in, (byte*)buffer, width, height, nbbytes); |
---|
| 160 | #if 0 |
---|
| 161 | memset(fn, 0, 256); |
---|
| 162 | sprintf(fn, "%s/%08d.dxt", argv[1], count); |
---|
| 163 | FILE *f=fopen(fn, "w+"); |
---|
| 164 | int res=fwrite(buffer, 1, nbbytes, f); |
---|
| 165 | fclose(f); |
---|
| 166 | #endif |
---|
| 167 | sageInf.swapBuffer(); |
---|
| 168 | buffer = sageInf.getBuffer(); |
---|
| 169 | |
---|
| 170 | sageMessage msg; |
---|
| 171 | if (sageInf.checkMsg(msg, false) > 0) { |
---|
| 172 | switch (msg.getCode()) { |
---|
| 173 | case APP_QUIT : { |
---|
| 174 | sageInf.shutdown(); |
---|
| 175 | exit(0); |
---|
| 176 | break; |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | magick_wand=DestroyMagickWand(magick_wand); |
---|
| 184 | MagickWandTerminus(); |
---|
| 185 | |
---|
| 186 | return 0; |
---|
| 187 | } |
---|