4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
35 #include "imgreg_manager.h"
38 #include "fcgi_stdio.h"
39 #define logstream FCGI_stdout
41 #define FCGI_stdout stdout
42 #define FCGI_stderr stderr
43 #define logstream stderr
46 imgreg_param_t map_viewin2imgreg( const int fx, const int fy,
47 const int rx, const int ry,
48 const int rw, const int rh,
49 const int XOsiz, const int YOsiz,
50 const int Xsiz, const int Ysiz,
51 const int numOfreslev)
53 imgreg_param_t imgreg;
65 find_level( numOfreslev, &imgreg.level, &imgreg.fx, &imgreg.fy, &imgreg.xosiz, &imgreg.yosiz, &xmax, &ymax);
67 if( rx == -1 || ry == -1){
72 imgreg.ox = rx*imgreg.fx/fx;
73 imgreg.oy = ry*imgreg.fy/fy;
76 if( rw == -1 || rh == -1){
77 imgreg.sx = imgreg.fx;
78 imgreg.sy = imgreg.fy;
81 px = (int)ceil((double)((rx+rw)*imgreg.fx)/(double)fx);
82 py = (int)ceil((double)((ry+rh)*imgreg.fy)/(double)fy);
89 imgreg.sx = px - imgreg.ox;
90 imgreg.sy = py - imgreg.oy;
93 if( fx != imgreg.fx || fy != imgreg.fy)
94 fprintf( FCGI_stdout, "JPIP-fsiz: %d,%d\r\n", imgreg.fx, imgreg.fy);
96 if( rw != imgreg.sx || rh != imgreg.sy)
97 fprintf( FCGI_stdout, "JPIP-rsiz: %d,%d\r\n", imgreg.sx, imgreg.sy);
99 if( rx != imgreg.ox || ry != imgreg.oy)
100 fprintf( FCGI_stdout, "JPIP-roff: %d,%d\r\n", imgreg.ox, imgreg.oy);
105 void find_level( int maxlev, int *lev, int *fx, int *fy, int *xmin, int *ymin, int *xmax, int *ymax)
107 int xwidth = *xmax - *xmin;
108 int ywidth = *ymax - *ymin;
110 /* Find smaller frame size for now (i.e. assume "round-down"). */
111 if ((*fx < 1 && xwidth != 0) || (*fy < 1 && ywidth != 0)){
112 fprintf( FCGI_stderr, "Frame size must be strictly positive");
115 else if( *lev < maxlev-1 && ( *fx < xwidth || *fy < ywidth)) {
116 /* Simulate the ceil function. */
117 *xmin = (int)ceil((double)*xmin/(double)2.0);
118 *ymin = (int)ceil((double)*ymin/(double)2.0);
119 *xmax = (int)ceil((double)*xmax/(double)2.0);
120 *ymax = (int)ceil((double)*ymax/(double)2.0);
123 find_level ( maxlev, lev, fx, fy, xmin, ymin, xmax, ymax);
130 int comp_decomplev( int fw, int fh, int Xsiz, int Ysiz)
133 int xmin, xmax, ymin, ymax;
140 find_level( 1000, &level, &fw, &fh, &xmin, &ymin, &xmax, &ymax);
142 assert( level >= 0 );
146 void print_imgreg( imgreg_param_t imgreg)
149 fprintf( logstream, "codestream image region:\n");
150 fprintf( logstream, "\t fsiz: %d, %d\n", imgreg.fx, imgreg.fy);
151 fprintf( logstream, "\t roff: %d, %d\n", imgreg.ox, imgreg.oy);
152 fprintf( logstream, "\t rsiz: %d, %d\n", imgreg.sx, imgreg.sy);
153 fprintf( logstream, "\t level: %d\n", imgreg.level);