Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

dyimax.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: dyimax.c,v 1.2 2005/09/09 14:59:14 yougz Exp $ 00003 ************************************************************************** 00004 This software is governed by the CeCILL license under French law and 00005 abiding by the rules of distribution of free software. You can use, 00006 modify and/ or redistribute the software under the terms of the CeCILL 00007 license as circulated by CEA, CNRS and INRIA at the following URL 00008 "http://www.cecill.info". 00009 00010 As a counterpart to the access to the source code and rights to copy, 00011 modify and redistribute granted by the license, users are provided only 00012 with a limited warranty and the software's author, the holder of the 00013 economic rights, and the successive licensors have only limited 00014 liability. 00015 00016 In this respect, the user's attention is drawn to the risks associated 00017 with loading, using, modifying and/or developing or reproducing the 00018 software by the user in light of its specific status of free software, 00019 that may mean that it is complicated to manipulate, and that also 00020 therefore means that it is reserved for developers and experienced 00021 professionals having in-depth computer knowledge. Users are therefore 00022 encouraged to load and test the software's suitability as regards their 00023 requirements in conditions enabling the security of their systems and/or 00024 data to be ensured and, more generally, to use and operate it in the 00025 same conditions as regards security. 00026 00027 The fact that you are presently reading this means that you have had 00028 knowledge of the CeCILL license and that you accept its terms. 00029 00030 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00031 l'Image). All rights reserved. See License.txt for details. 00032 00033 Version 1.0 05/09/2005 00034 *************************************************************************/ 00035 00036 /************************************************************************* 00037 * 00038 * Description : Affichage d'une image dans une fenetre X ecran 24 bits 00039 * L'ancienne version (conservee dans DYIMAXOLD.C) marchait partout 00040 * sauf sous les LINUX 'actuels' 00041 * (probleme d'incompatibilite entre X11R5 et X11R6 ?) 00042 * De maniere tres goret, j'ai traite toute image 8 bits comme une image 24 bits 00043 * mon probleme etant d'avoir un affichage. 00044 * Sur les ecrans 8 bits, (SUN3, SUN4, et c'est tout) j'appele l'ancienne fonction. 00045 * 00046 **************************************************************************/ 00047 00048 #define DEBUG 0 00049 00050 #ifdef HAVE_X11 00051 00052 #include <string.h> // For memcpy 00053 #include <math.h> 00054 #include <stdio.h> 00055 #include <stdlib.h> 00056 #include "iderr.h" 00057 #include "idima.h" 00058 #include "idprint.h" 00059 00060 #include <X11/Xlib.h> 00061 #include <X11/Xutil.h> 00062 #include <X11/Xos.h> 00063 #include <X11/Xatom.h> 00064 00065 #define RGB24BITS_SW 4 00066 #define RGB24BITS_NW 5 00067 #define COLORS256_SW 2 00068 #define COLORS256_NW 3 00069 00070 00071 static Display *disp; 00072 static Visual *vis; 00073 static int screen_num; 00074 static Window win; 00075 00076 static XImage *xim=NULL; 00077 static GC gc; 00078 static XGCValues val; 00079 00080 static XEvent rep; 00081 static Colormap cm; 00082 00083 00084 static char * imm1; 00085 static int fdp[2]; 00086 static int fork_done=0; 00087 00088 static XVisualInfo vTemplate; 00089 static XVisualInfo *visualList; 00090 static int visualsMatched; 00091 static XSetWindowAttributes attributs; 00092 static unsigned long valuemask=0 /*,pixels[2048] */; 00093 static int num_visual; 00094 static PPIMAGE_UCHAR imUCHAR; 00095 static PPIMAGE_RGB imRGB; 00096 00097 /*void _IdImaDisplayColorOld(PPIMAGE_UCHAR , 00098 int , 00099 int , int , int , int , 00100 int , int , PSIGNAL_RGB); 00101 */ 00102 void _IdImaDisplayColor(PPIMAGE_UCHAR im, 00103 int display, // Displays in same window when even 00104 // and in newly created window when odd 00105 int x, int y, int nx, int ny, 00106 int ox, int oy, PSIGNAL_RGB pal) 00107 { 00108 int i,j,k,kkk=0; 00109 int lig,v; 00110 int FlagSameWindow=0; 00111 00112 if (!im) { 00113 IdErrPrintf("Pointeur image NULL !!\n"); 00114 return; 00115 } 00116 00117 FlagSameWindow=display&0x0001; 00118 00119 if(!FlagSameWindow) { /* si PAIR meme fenetre */ 00120 00121 if(!fork_done) { 00122 pipe(fdp); 00123 fork_done=1; 00124 fcntl(fdp[0],F_SETFL,O_NDELAY); 00125 00126 if(fork())return; 00127 00128 } else { 00129 switch(IdImaType(im)) { 00130 00131 case IMA_UCHAR: 00132 for(i=0;i<IdImaDimY(im);i++) 00133 write(fdp[1],im[i],IdImaDimX(im)); 00134 return; 00135 00136 case IMA_RGB: 00137 for(i=0;i<IdImaDimY(im);i++) 00138 write(fdp[1],im[i],IdImaDimX(im)*3); 00139 return; 00140 } 00141 } 00142 00143 } else { /* si IMPAIR nouvelle fenetre */ 00144 00145 if (fork()) 00146 return; 00147 } 00148 00149 if(!(disp=XOpenDisplay(0))) { 00150 IdPrintf("Pb de display (XOpenDisplay)\n"); 00151 return; 00152 } 00153 screen_num=DefaultScreen(disp); 00154 00155 00156 /**************************************************************************/ 00157 /* Affichage en d'une image RGB sur ecran 24 bits en TRUE-COLOR */ 00158 /**************************************************************************/ 00159 00160 vTemplate.depth=24; 00161 visualList=XGetVisualInfo(disp,VisualScreenMask | VisualDepthMask, 00162 &vTemplate,&visualsMatched); 00163 00164 if( visualsMatched == 0 ) { 00165 //im=eclate_24_8((PPIMAGE_RGB)im); 00166 00167 _IdImaDisplayColorOld( im, //juste pour continuer a afficher sur des ecrans 8 bits 00168 display, // sans se casser la tete 00169 x, y, nx, ny, 00170 ox, oy, pal); 00171 return; 00172 } else { 00173 while(visualList[num_visual].class != TrueColor ) { 00174 num_visual++; 00175 00176 if ( num_visual >= visualsMatched) { 00177 IdErrPrintf("Votre serveur ne permet pas d'afficher en TRUE_COLOR"); 00178 IdExit(1); 00179 } 00180 } 00181 } 00182 00183 cm = XCreateColormap(disp,RootWindow(disp,screen_num), 00184 visualList[num_visual].visual,AllocNone); 00185 attributs.colormap = cm; 00186 attributs.event_mask= ButtonPressMask | KeyPressMask | ExposureMask; 00187 attributs.background_pixel=BlackPixel(disp,screen_num); 00188 attributs.border_pixel=WhitePixel(disp,screen_num); 00189 vis=visualList[num_visual].visual; 00190 valuemask |= CWColormap; 00191 valuemask |= CWEventMask; 00192 valuemask |= CWBackPixel; 00193 valuemask |= CWBorderPixel; 00194 win=XCreateWindow(disp,RootWindow(disp,screen_num), 00195 0,0,IdImaDimX(im),IdImaDimY(im),50,vTemplate.depth, 00196 InputOutput,visualList[num_visual].visual,valuemask,&attributs); 00197 if(!win) IdErrPrintf("Erreur creation fenetre \n"); 00198 XSetWindowColormap(disp,win,cm); 00199 XClearWindow(disp,win); 00200 XStoreName(disp,win,IdGetFileName(im)); 00201 imm1=(char *)malloc(IdImaDimX(im)*IdImaDimY(im)*4); 00202 00203 00204 switch(IdImaType(im)) { 00205 00206 case IMA_RGB: 00207 imRGB=(PPIMAGE_RGB)im; 00208 00209 for(i=0,k=0;i<IdImaDimY(im);i++) 00210 for(j=0;j<IdImaDimX(im);j++,k+=4) { 00211 /* 00212 imm1[k] =0; 00213 imm1[k+1]=imRGB[i][j].b; 00214 imm1[k+2]=imRGB[i][j].g; 00215 imm1[k+3]=imRGB[i][j].r; 00216 */ 00217 imm1[k] =imRGB[i][j].b; 00218 imm1[k+1]=imRGB[i][j].g; 00219 imm1[k+2]=imRGB[i][j].r; 00220 imm1[k+3]=0; 00221 } 00222 00223 break; 00224 00225 case IMA_UCHAR: 00226 00227 imUCHAR=(PPIMAGE_UCHAR)im; 00228 if (!pal) 00229 for(i=0,k=0;i<IdImaDimY(im);i++) 00230 for(j=0;j<IdImaDimX(im);j++,k+=4) { 00231 imm1[k] = imm1[k+1] = imm1[k+2] = imUCHAR[i][j]; 00232 imm1[k+3]=0; 00233 } 00234 else 00235 for(i=0,k=0;i<IdImaDimY(im);i++) 00236 for(j=0;j<IdImaDimX(im);j++,k+=4) { 00237 00238 imm1[k] =pal[imUCHAR[i][j]].b; 00239 imm1[k+1]=pal[imUCHAR[i][j]].g; 00240 imm1[k+2]=pal[imUCHAR[i][j]].r; 00241 imm1[k+3]=0; 00242 } 00243 00244 break; 00245 00246 default: 00247 00248 IdErrPrintf("type d'image (%04x) non autorise a l'affichage\n", 00249 IdImaType(im)); 00250 IdExit(1); 00251 00252 break; 00253 } 00254 00255 00256 xim=XCreateImage(disp,vis,24,ZPixmap,0,(char *)imm1, 00257 IdImaDimX(im),IdImaDimY(im),16,IdImaDimX(im)*4); 00258 if(!xim) 00259 IdErrPrintf("erreur creation image\n"); 00260 00261 00262 /*************************************************************************/ 00263 /* Partie commune affichage des images xim */ 00264 /*************************************************************************/ 00265 00266 gc=XCreateGC(disp,win,(GCForeground|GCBackground),&val); 00267 00268 XMapWindow(disp,win); 00269 XSelectInput(disp,win,ButtonPressMask | KeyPressMask | ExposureMask); 00270 XPutImage(disp,win,gc,xim,0,0,0,0,IdImaDimX(im),IdImaDimY(im)); 00271 lig=0; 00272 while(1) 00273 { 00274 if( XEventsQueued(disp,QueuedAfterFlush) || display) { 00275 00276 XNextEvent(disp,&rep); 00277 switch(rep.type) { 00278 case ButtonPress: 00279 if( rep.xbutton.button == 1) { 00280 XPutImage(disp,win,gc,xim,0,0,0, 00281 0,IdImaDimX(im),IdImaDimY(im)); 00282 XFreeGC(disp,gc); 00283 XCloseDisplay(disp); 00284 IdExit(0); 00285 } 00286 break; 00287 00288 case Expose: 00289 XPutImage(disp,win,gc,xim,0,0, 00290 0,0,IdImaDimX(im),IdImaDimY(im)); 00291 break; 00292 00293 case KeyPress: 00294 XPutImage(disp,win,gc,xim,0,0, 00295 0,0,IdImaDimX(im),IdImaDimY(im)); 00296 break; 00297 } 00298 } else { 00299 switch (IdImaType(im)) { 00300 00301 00302 case IMA_UCHAR : 00303 /*---------------*/ 00304 00305 if( (v=read(fdp[0],im[lig],IdImaDimX(im))) != -1) { 00306 00307 if(v) { 00308 00309 for(j=0;j<IdImaDimX(im);j++,kkk+=4) { 00310 00311 imm1[kkk] = imm1[kkk+1] = imm1[kkk+2] = imUCHAR[lig][j]; 00312 imm1[kkk+3]=0; 00313 } 00314 lig++; 00315 } 00316 if(lig==IdImaDimY(im)) { 00317 00318 lig=0; 00319 kkk=0; 00320 XPutImage(disp,win,gc,xim,0,0,0,0, 00321 IdImaDimX(im),IdImaDimY(im)); 00322 } 00323 } /* fin if v=read(fdp... */ 00324 00325 break; 00326 00327 00328 case IMA_RGB: 00329 /*-------------*/ 00330 00331 if( (v=read(fdp[0],im[lig],IdImaDimX(im)*3)) != -1) { 00332 00333 if(v) { 00334 00335 for(j=0;j<IdImaDimX(im);j++,kkk+=4) { 00336 00337 /* 00338 imm1[kkk] =0; 00339 imm1[kkk+1]=imRGB[lig][j].b; 00340 imm1[kkk+2]=imRGB[lig][j].g; 00341 imm1[kkk+3]=imRGB[lig][j].r; 00342 */ 00343 00344 imm1[kkk] =imRGB[lig][j].b; 00345 imm1[kkk+1]=imRGB[lig][j].g; 00346 imm1[kkk+2]=imRGB[lig][j].r; 00347 imm1[kkk+3]=0; 00348 } 00349 lig++; 00350 } 00351 if(lig==IdImaDimY(im)) { 00352 00353 lig=0; 00354 kkk=0; 00355 00356 XPutImage(disp,win,gc,xim,0,0,0,0, 00357 IdImaDimX(im),IdImaDimY(im)); 00358 } 00359 } /* fin if v=read(fdp... */ 00360 00361 break; 00362 00363 } /* fin Switch */ 00364 00365 } 00366 } 00367 } 00368 00369 #else /* HAVE_X11 */ 00370 #include "idima.h" 00371 /* Here we put dummy functions to satisfy filters programs compilation 00372 * even when X11 is not available 00373 */ 00374 void _IdImaDisplayColor(PPIMAGE_UCHAR im, 00375 int display, 00376 int x, int y, int nx, int ny, 00377 int ox, int oy, PSIGNAL_RGB pal) 00378 {} 00379 #endif /* HAVE_X11 */

Generated on Wed Oct 19 09:28:33 2005 for SIMRI3D by doxygen 1.3.7