Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

image_Flash_mod.c

Go to the documentation of this file.
00001 /*
00002  *    gui - [gega user interface] the flexible solution for user interface problems
00003  *    Copyright (C) 2002  Gergely Gati
00004  *
00005  *    This program is free software; you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation; version 2 of the License.
00008  *
00009  *    This program is distributed in the hope that it will be useful,
00010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *    GNU General Public License for more details.
00013  *
00014  *    You should have received a copy of the GNU General Public License
00015  *    along with this program; if not, write to the Free Software
00016  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  *    Gergely Gati
00019  *      email:           g.gati@freemail.hu
00020  *      AIM screenname:  GatiGergely
00021  *      ICQ number:      93131690
00022  *
00023  */
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <sys/time.h>
00027 #include <time.h>
00028 #include <setjmp.h>
00029 
00030 #include <assert.h>
00031 #include <limits.h>
00032 #include <time.h>
00033 
00034 #define __IMAGE_MODULE
00035 
00036 #include "Bases.h"
00037 #include "Module.h"
00038 #include "debug.h"
00039 #include "Gui.h"
00040 #include "Memory.h"
00041 #include "Common.h"
00042 
00043 #ifndef __CYGWIN__
00044 struct timezone {
00045   int tz_minuteswest;
00046   int tz_dsttime;
00047 };
00048 
00049 struct timeval {
00050     long    tv_sec;
00051     long    tv_usec;
00052 };
00053 #endif
00054 
00055 #ifdef __CYGWIN__
00056 #ifndef UNIX
00057 #include <sys/reent.h>
00058 struct _reent *_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
00059 #endif
00060 #endif
00061 
00062 #include <jpeglib.h>
00063 
00064 
00065 static bases_Modules_t *api;
00066 VERSION("Flash.image_mod",1,0,"Gergely Gati","g.gati@freemail.hu");
00067 
00068 
00069 int gettimeofday(struct timeval *tv, struct timezone *tz)
00070 {
00071   struct glw_Time tm;
00072 
00073   api->glw_Call(GLW_GETTIME,TAG_GLW_TM,&tm,TAG_DONE);
00074   tv->tv_sec=tm.secs;
00075   tv->tv_usec=tm.millis;
00076   return(0);
00077 }
00078 
00079 /*
00080 void __assert(int exp)
00081 {
00082 }
00083 int setjmp(jmp_buf jb)
00084 {
00085   return(0);
00086 }
00087 */
00088 
00089 #include "images/image_Flash.h"
00090 #include <flash.h>
00091 
00092 
00093 typedef struct flash_CustomData_s
00094 {
00095   Image_t *img;
00096 } flash_CustomData_t;
00097 
00098 
00099 //static void getSwf(char *url, int level, void *client_data) {}
00100 //static void showUrl(char *url, char *target, void *client_data) {}
00101 
00102 
00103 
00104 // ez kitolti az image struktura hianyzo mezoit
00105 // ha az input struktura format mezoje ki van toltve,
00106 // es az nem "flash", akkor FALSE,
00107 // ha NULL akkor egy statikus "flash"-re allitja, ha
00108 // a data egy valid png-nek latszik.
00109 // kitolti a meret mezoket is.
00110 static int flash_ImgInit(Image_t *img, void (*update)(void *),void *userdata)
00111 {
00112   int ret=-1;
00113   flash_CustomData_t *cdata;
00114 
00115   if(img!=NULL)
00116   {
00117     if(img->iim.data[0]=='F'&&img->iim.data[1]=='W'&&img->iim.data[2]=='S')
00118     {
00119       if(NULL!=(cdata=mem_malloc(sizeof(flash_CustomData_t))))
00120       {
00121         img->formatdata=cdata;
00122         cdata->img=img;
00123         img->minwidth=8;
00124         img->minheight=8;
00125         img->maxwidth=IMAGE_MAXIMUM_SIZE;
00126         img->maxheight=IMAGE_MAXIMUM_SIZE;
00127         ret=0;
00128       }
00129     }
00130   }
00131 
00132   return(ret);
00133 }
00134 
00135 
00136 static void flash_ImgCleanUp(Image_t *img)
00137 {
00138   flash_CustomData_t *cdata;
00139 
00140   if(img!=NULL)
00141   {
00142     cdata=(flash_CustomData_t *)img->formatdata;
00143     if(img->formatdata!=NULL) mem_free(img->formatdata);
00144   }
00145 }
00146 
00147 
00148 // a dest memoriat a hivo prezentalja destsize
00149 // meretben, ha kicsi, hiba (-1)
00150 // a rendereles 32bitesen tortenik, az atlatszo
00151 // pixelek helyere 0xffffffff kerul
00152 static int flash_ImgRender(Image_t *img, u8 *dest, int destsize, int width, int height)
00153 {
00154   int ret=-1;
00155   int i,j,mx;
00156     FlashHandle flashHandle;
00157 //  struct FlashInfo fi;
00158   FlashDisplay fd;
00159 //  FlashEvent fe;
00160   struct timeval wd;
00161   long cmd;
00162   long wakeUp;
00163 //  long delay=0, z=1;
00164 
00165   if(img!=NULL&&img->formatdata!=NULL&&dest!=NULL&&destsize>=(width*height*4)&&
00166     width>=img->minwidth&&height>=img->minheight&&
00167     width<=img->maxwidth&&height<=img->maxheight)
00168   {
00169     if(0!=(flashHandle=FlashNew()))
00170     {
00171         FlashParse(flashHandle,0,(char *)img->iim.data,(long)img->iim.data_size);
00172 //      FlashGetInfo(flashHandle,&fi);
00173         fd.pixels=(char *)dest;
00174       fd.width=width;
00175       fd.height=height;
00176       fd.bpl=width*4;                // bytes/line
00177       fd.depth=32;
00178       fd.bpp=4;                     // bytes_per_pixel
00179       FlashSettings(flashHandle, PLAYER_LOOP);
00180       FlashGraphicInit(flashHandle,&fd);
00181 //      FlashSetGetUrlMethod(flashHandle,showUrl,0L);
00182 //      FlashSetGetSwfMethod(flashHandle,getSwf,0L);
00183       cmd=FLASH_WAKEUP;
00184       wakeUp=FlashExec(flashHandle,cmd,0,&wd);
00185 
00186 
00187       mx=width*height;
00188       for(i=j=0;i<mx;i++,j+=4)
00189       {
00190 
00191         dest[j+3]=dest[j];
00192         dest[j+2]=dest[j+1];
00193         dest[j+1]=dest[j+2];
00194         dest[j]=0;
00195       }
00196 
00197 //      fe.type=FeRefresh;
00198 //      FlashExec(flashHandle,FLASH_EVENT,&fe,&wd);
00199       ret=0;
00200 /*
00201         while(1)
00202         {
00203           if(delay<0) delay=20;
00204           if(fd.flash_refresh)
00205           {
00206               // copy 0,0,fd.width,fd.height (SOURCE: fd.pixels) TO SCREEN
00207               fd.flash_refresh=0;
00208           }
00209           if(wakeUp)
00210           {
00211             // wait delay millisecs
00212           }
00213           // zoom
00214           //FlashZoom(flashHandle,z);
00215 
00216           // when refresh needed:
00217           fe.type=FeRefresh;
00218           FlashExec(flashHandle,FLASH_EVENT,&fe,&wd);
00219 
00220           // default:
00221           fe.type=FeNone;
00222           FlashExec(flashHandle,FLASH_EVENT,&fe,&wd);
00223 
00224         // new delay calc
00225         gettimeofday(&now,0);
00226         delay=(wd.tv_sec-now.tv_sec)*1000+(wd.tv_usec-now.tv_usec)/1000;
00227       }
00228 */
00229         FlashClose(flashHandle);
00230     }
00231   }
00232 
00233   return(ret);
00234 }
00235 
00236 
00237 static int flash_PutImage(Image_t *img, u32 window, Rect_t *rect)
00238 {
00239   Vector_t buff;
00240 
00241   buff.size=(rect->width*rect->height*4)+1;
00242   if(NULL!=(buff.data=mem_malloc(buff.size)))
00243   {
00244     if(0==(flash_ImgRender(img,buff.data,buff.size,rect->width,rect->height)))
00245     {
00246       api->glw_Call(GLW_PUTIMAGE,TAG_GLW_WINDOW,window,TAG_GLW_PIXELS,&buff,TAG_GLW_CLIPRECT,rect,TAG_GLW_LEFT,rect->left,TAG_GLW_TOP,rect->top,TAG_GLW_WIDTH,rect->width,TAG_GLW_HEIGHT,rect->height,TAG_DONE);
00247     }
00248     mem_free(buff.data);
00249   }
00250   return(0);
00251 }
00252 
00253 
00254 static void flash_CleanUp(void)
00255 {
00256   debug_Begin();
00257   debug_End();
00258 }
00259 
00260 
00261 static int flash_Init(u32 module)
00262 {
00263   int ret=-1;
00264   ret=api->img_Call(IMG_REGISTERFORMATCODE,
00265                 TAG_IMG_NAME,(u32)"flash",
00266                 TAG_IMG_IMG_INIT,(u32)flash_ImgInit,
00267                 TAG_IMG_IMG_RENDER,(u32)flash_ImgRender,
00268                 TAG_IMG_IMG_PUTIMAGE,(u32)flash_PutImage,
00269                 TAG_IMG_IMG_CLEAN,(u32)flash_ImgCleanUp,
00270                 TAG_IMG_CLEANUP,(u32)flash_CleanUp,
00271                 TAG_IMG_MODULE,module,
00272                 TAG_DONE);
00273   return(ret);
00274 }
00275 
00276 EXPORT int module_Init(u32 module, bases_Modules_t *bases)
00277 {
00278     api=bases;
00279     return(flash_Init(module));
00280 }
00281 

Generated on Tue Jan 7 12:11:22 2003 for THEGUI by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002