source: trunk/src/testing/app/yuv/yuv.cxx @ 4

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

Added modified SAGE sources

Line 
1/******************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 * Copyright (C) 2004 Electronic Visualization Laboratory,
4 * University of Illinois at Chicago
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 *  * Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *  * Redistributions in binary form must reproduce the above
14 *    copyright notice, this list of conditions and the following disclaimer
15 *    in the documentation and/or other materials provided with the distribution.
16 *  * Neither the name of the University of Illinois at Chicago nor
17 *    the names of its contributors may be used to endorse or promote
18 *    products derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * Direct questions, comments etc about SAGE to bijeong@evl.uic.edu
33 *****************************************************************************/
34
35#include <stdio.h>
36#include <math.h>
37#include <stdlib.h>
38
39// headers for SAGE
40#include "sail.h"
41#include "misc.h"
42
43//
44// Streams a YUV buffer (or an image)
45//    ./yuv 0 width height fps filename
46//
47
48int main(int argc, char *argv[])
49{
50        double t1, t2, fps;
51        char *fn;
52        void *pixels = NULL;
53        sail sageInf; // sail object
54        int nodeID;
55
56        if (argc < 2)
57                nodeID = 0;
58        else
59                nodeID = atoi(argv[1]);
60                 
61        int resX = 400, resY = 400;
62        if (argc >= 4) {
63                resX = atoi(argv[2]);
64                resY = atoi(argv[3]);   
65        }       
66        double rate = 10.0;
67        if (argc >= 5) {
68                rate = atof(argv[4]);
69        }       
70        if (argc >= 6) {
71                fn = strdup(argv[5]);
72                FILE *f = fopen(fn, "r");
73                pixels = malloc(resX*resY*2);
74                memset(pixels, 0, resX*resY*2);
75                int nb = fread(pixels, 1, resX*resY*2, f);
76                fclose(f);
77        }       
78       
79        std::cout << std::endl << "ResX = " << resX << "  ResY = " << resY << std::endl;
80
81        sailConfig scfg;
82        scfg.init("yuv.conf");
83        scfg.setAppName("yuv");
84        scfg.rank = nodeID;
85                       
86        scfg.resX = resX;
87        scfg.resY = resY;
88
89        sageRect renderImageMap;
90        renderImageMap.left = 0.0;
91        renderImageMap.right = 1.0;
92        renderImageMap.bottom = 0.0;
93        renderImageMap.top = 1.0;
94
95        scfg.imageMap = renderImageMap;
96        scfg.pixFmt = PIXFMT_YUV;
97        scfg.rowOrd = TOP_TO_BOTTOM;
98        scfg.master = true;
99        scfg.nwID = 1;
100                         
101        sageInf.init(scfg);     
102        std::cout << "sail initialized " << std::endl;
103       
104        void *buffer = sageInf.getBuffer();
105        unsigned char color = 200;
106       
107        while(1) {
108                t1 = sage::getTime();
109                if (pixels)
110                        memcpy(buffer, pixels, resX*resY*2);
111                else
112                        memset(buffer, color, resX*resY*2);
113                sageInf.swapBuffer();
114                buffer = sageInf.getBuffer();
115                color = (color + 1) % 256;     
116                sageMessage msg;
117                if (sageInf.checkMsg(msg, false) > 0) {
118                        switch (msg.getCode()) {
119                                 case APP_QUIT : {
120                                        sageInf.shutdown();
121                                        exit(0);
122                                        break;
123                                }
124                        }       
125                }
126                t2 = sage::getTime();
127                fps = (1000000.0/(t2-t1));
128                if (fps > rate) {
129                        sage::usleep( (1000000.0/rate) - (t2-t1)  );
130                }
131        }
132       
133        return 0;
134}
Note: See TracBrowser for help on using the repository browser.