00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00081
00082
00083
00084
00085
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
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
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
00149
00150
00151
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
00158 FlashDisplay fd;
00159
00160 struct timeval wd;
00161 long cmd;
00162 long wakeUp;
00163
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
00173 fd.pixels=(char *)dest;
00174 fd.width=width;
00175 fd.height=height;
00176 fd.bpl=width*4;
00177 fd.depth=32;
00178 fd.bpp=4;
00179 FlashSettings(flashHandle, PLAYER_LOOP);
00180 FlashGraphicInit(flashHandle,&fd);
00181
00182
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
00198
00199 ret=0;
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
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