Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

image_Pvf_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 <math.h>
00027 
00028 #define __IMAGE_MODULE
00029 
00030 #include "Bases.h"
00031 #include "Module.h"
00032 #include "Gui.h"
00033 #include "Common.h"
00034 #include "debug.h"
00035 #include "Memory.h"
00036 #include "macros.h"
00037 
00038 #include "images/image_Pvf.h"
00039 
00040 
00041 //#define TOSCR(c,w)         ((c*w)/32767)
00042 #define TOSCR(c,w)           (((c)*(w))>>15)
00043 #define PUTPIXEL(cdata,x,y)  (cdata->pixels[(y)*cdata->width+(x)]=cdata->curr_col)
00044 #define PUTPIXELD(cdata,x,y) api->glw_Call(GLW_DRAWPIXEL,TAG_GLW_WINDOW,cdata->window,TAG_GLW_X,cdata->left+(x),TAG_GLW_Y,cdata->top+(y),TAG_DONE)
00045 
00046 struct pvf_anchor
00047 {
00048   u16 x;
00049   u16 y;
00050 };
00051 
00052 typedef struct pvf_CustomData_s
00053 {
00054   Image_t *img;
00055   u32 *pixels;
00056   u32 window;
00057   int width;
00058   int height;
00059   int left;
00060   int top;
00061   int curr_x;
00062   int curr_y;
00063   u32 curr_col;
00064   u32 curr_cl2;
00065   struct pvf_anchor anchors[256];
00066 } pvf_CustomData_t;
00067 
00068 
00069 struct pvf_command
00070 {
00071   char *name;
00072   int (*execute)(pvf_CustomData_t *cdata, u8 *param);
00073   int len;
00074 };
00075 
00076 
00077 static int pvf_cnop(pvf_CustomData_t *cdata, u8 *param);
00078 static int pvf_cset(pvf_CustomData_t *cdata, u8 *param);
00079 static int pvf_ccol(pvf_CustomData_t *cdata, u8 *param);
00080 static int pvf_cmov(pvf_CustomData_t *cdata, u8 *param);
00081 static int pvf_clin(pvf_CustomData_t *cdata, u8 *param);
00082 static int pvf_crec(pvf_CustomData_t *cdata, u8 *param);
00083 static int pvf_ccir(pvf_CustomData_t *cdata, u8 *param);
00084 static int pvf_cfil(pvf_CustomData_t *cdata, u8 *param);
00085 static int pvf_chln(pvf_CustomData_t *cdata, u8 *param);
00086 static int pvf_cvln(pvf_CustomData_t *cdata, u8 *param);
00087 
00088 #define    pvf_dnop pvf_cnop
00089 #define    pvf_dset pvf_cset
00090 static int pvf_dcol(pvf_CustomData_t *cdata, u8 *param);
00091 #define    pvf_dmov pvf_cmov
00092 static int pvf_dlin(pvf_CustomData_t *cdata, u8 *param);
00093 static int pvf_drec(pvf_CustomData_t *cdata, u8 *param);
00094 static int pvf_dcir(pvf_CustomData_t *cdata, u8 *param);
00095 static int pvf_dfil(pvf_CustomData_t *cdata, u8 *param);
00096 static int pvf_dhln(pvf_CustomData_t *cdata, u8 *param);
00097 static int pvf_dvln(pvf_CustomData_t *cdata, u8 *param);
00098 
00099 #define COMMAND_COUNT 10
00100 
00101 static bases_Modules_t *api;
00102 VERSION("Pvf.image_mod",1,0,"Gergely Gati","g.gati@freemail.hu");
00103 
00104 
00105 struct pvf_command commandsN[]=
00106 {
00107   {"nop",pvf_cnop,1},
00108   {"set",pvf_cset,6},
00109   {"col",pvf_ccol,5},
00110   {"mov",pvf_cmov,6},
00111   {"lin",pvf_clin,6},
00112   {"rec",pvf_crec,6},
00113   {"cir",pvf_ccir,4},
00114   {"fil",pvf_cfil,6},
00115   {"hln",pvf_chln,4},
00116   {"vln",pvf_cvln,4},
00117   {NULL,NULL}
00118 };
00119 
00120 struct pvf_command commandsD[]=
00121 {
00122   {"nop",pvf_dnop,1},
00123   {"set",pvf_dset,6},
00124   {"col",pvf_dcol,5},
00125   {"mov",pvf_dmov,6},
00126   {"lin",pvf_dlin,6},
00127   {"rec",pvf_drec,6},
00128   {"cir",pvf_dcir,4},
00129   {"fil",pvf_dfil,6},
00130   {"hln",pvf_dhln,4},
00131   {"vln",pvf_dvln,4},
00132   {NULL,NULL}
00133 };
00134 
00135 
00136 static inline u8 getbyte(u8 *mem)
00137 {
00138   return(mem[0]);
00139 }
00140 static inline s16 getword(u8 *mem)
00141 {
00142   return(mem[0]<<8|mem[1]);
00143 }
00144 static inline u32 getlong(u8 *mem)
00145 {
00146   u32 ret;
00147   int a,r,g,b;
00148 
00149   a=*mem++;
00150   r=*mem++;
00151   g=*mem++;
00152   b=*mem;
00153   ret=a<<24;
00154   ret|=r<<16;
00155   ret|=g<<8;
00156   ret|=b;
00157 //  return(*((u32 *)mem));
00158   return(ret);
00159 }
00160 
00161 
00162 static int pvf_cnop(pvf_CustomData_t *cdata, u8 *param)
00163 {
00164   return(0);
00165 }
00166 static int pvf_cset(pvf_CustomData_t *cdata, u8 *param)
00167 {
00168   u16 x,y;
00169   int i;
00170 
00171   debug_Begin();
00172 
00173   x=getword(param);
00174   y=getword(param+2);
00175   i=(int)getbyte(param+4);
00176   cdata->anchors[i].x=TOSCR(x,cdata->width);
00177   cdata->anchors[i].y=TOSCR(y,cdata->height);
00178 
00179   debug_End();
00180 
00181   return(0);
00182 }
00183 static int pvf_ccol(pvf_CustomData_t *cdata, u8 *param)
00184 {
00185   cdata->curr_col=api->glw_Call(GLW_NTOHL2,TAG_GLW_VALUE,getlong(param),TAG_DONE);
00186 //  printf("col: 0x%02x%02x%02x%02x\n",(u8)cdata->curr_col>>24,(u8)(cdata->curr_col>>16)&0xff,(u8)(cdata->curr_col>>8)&0xff,(u8)cdata->curr_col&0xff);
00187   return(0);
00188 }
00189 static int pvf_cmov(pvf_CustomData_t *cdata, u8 *param)
00190 {
00191   int i;
00192 
00193   cdata->curr_x=(int)getword(param);
00194   cdata->curr_y=(int)getword(param+2);
00195   if(0!=(i=(int)getbyte(param+4)))
00196   {
00197     cdata->curr_x+=cdata->anchors[i].x;
00198     cdata->curr_y+=cdata->anchors[i].y;
00199     if(cdata->curr_x>cdata->width) cdata->curr_x=cdata->width;
00200     else if(cdata->curr_x<0) cdata->curr_x=0;
00201     if(cdata->curr_y>cdata->height) cdata->curr_y=cdata->height;
00202     else if(cdata->curr_y<0) cdata->curr_y=0;
00203   }
00204   else
00205   {
00206     cdata->curr_x=TOSCR(cdata->curr_x,cdata->width);
00207     cdata->curr_y=TOSCR(cdata->curr_y,cdata->height);
00208   }
00209   return(0);
00210 }
00211 static int pvf_clin(pvf_CustomData_t *cdata, u8 *param)
00212 {
00213   int deltax,deltay;
00214   int x1,y1,x2,y2;
00215   int xinc1,xinc2,yinc1,yinc2;
00216   int den,num,numadd,numpixels;
00217   int curpixel,x,y,i;
00218 
00219   x1=cdata->curr_x;
00220   y1=cdata->curr_y;
00221   x2=(int)getword(param);
00222   y2=(int)getword(param+2);
00223   if(0!=(i=(int)getbyte(param+4)))
00224   {
00225     x2+=cdata->anchors[i].x;
00226     y2+=cdata->anchors[i].y;
00227     if(x2>cdata->width) x2=cdata->width;
00228     else if(x2<0) x2=0;
00229     if(y2>cdata->height) y2=cdata->height;
00230     else if(y2<0) y2=0;
00231   }
00232   else
00233   {
00234     x2=TOSCR(x2,cdata->width);
00235     y2=TOSCR(y2,cdata->height);
00236   }
00237   deltax=abs(x2-x1);
00238   deltay=abs(y2-y1);
00239   x=x1;
00240   y=y1;
00241   if(x2>=x1) xinc1=xinc2=1;
00242   else xinc1=xinc2=-1;
00243   if(y2>=y1) yinc1=yinc2=1;
00244   else yinc1=yinc2=-1;
00245   if(deltax>=deltay)
00246   {
00247     xinc1=yinc2=0;
00248     numpixels=den=deltax;
00249     num=deltax>>1;
00250     numadd=deltay;
00251   }
00252   else
00253   {
00254     xinc2=yinc1=0;
00255     numpixels=den=deltay;
00256     num=deltay>>1;
00257     numadd=deltax;
00258   }
00259   for(curpixel=0;curpixel<=numpixels;curpixel++)
00260   {
00261     PUTPIXEL(cdata,x,y);
00262     num+=numadd;
00263     if(num>=den)
00264     {
00265       num-=den;
00266       x+=xinc1;
00267       y+=yinc1;
00268     }
00269     x+=xinc2;
00270     y+=yinc2;
00271   }
00272   cdata->curr_x=x2;
00273   cdata->curr_y=y2;
00274   return(0);
00275 }
00276 static int pvf_crec(pvf_CustomData_t *cdata, u8 *param)
00277 {
00278   int x2,y2,x1,y1,x,y,ymn,xmn,ymx,xmx,i;
00279 
00280   x1=cdata->curr_x;
00281   y1=cdata->curr_y;
00282   x2=(int)getword(param);
00283   y2=(int)getword(param+2);
00284   if(0!=(i=(int)getbyte(param+4)))
00285   {
00286     x2+=cdata->anchors[i].x;
00287     y2+=cdata->anchors[i].y;
00288     if(x2>cdata->width) x2=cdata->width;
00289     else if(x2<0) x2=0;
00290     if(y2>cdata->height) y2=cdata->height;
00291     else if(y2<0) y2=0;
00292   }
00293   else
00294   {
00295     x2=TOSCR(x2,cdata->width);
00296     y2=TOSCR(y2,cdata->height);
00297   }
00298   cdata->curr_x=x2;
00299   cdata->curr_y=y2;
00300   xmx=max(x1,x2);
00301   ymx=max(y1,y2);
00302   xmn=min(x1,x2);
00303   ymn=min(y1,y2);
00304   for(x=xmn,y=ymn;y<ymx;y++) PUTPIXEL(cdata,x,y);
00305   for(x=xmx,y=ymn;y<ymx;y++) PUTPIXEL(cdata,x,y);
00306   for(x=xmn,y=ymn;x<xmx;x++) PUTPIXEL(cdata,x,y);
00307   for(x=xmn,y=ymx;x<xmx;x++) PUTPIXEL(cdata,x,y);
00308   return(0);
00309 }
00310 static int pvf_ccir(pvf_CustomData_t *cdata, u8 *param)
00311 {
00312   int xc,yc,x,y,r2,r;
00313 
00314   r=TOSCR((int)getword(param),min(cdata->width,cdata->height)>>1);
00315   xc=cdata->curr_x;
00316   yc=cdata->curr_y;
00317   r2=r*r;
00318   PUTPIXEL(cdata,xc,yc+r);    // jobb szel
00319   PUTPIXEL(cdata,xc,yc-r);    // bal szel
00320   PUTPIXEL(cdata,xc+r,yc);    // also szel
00321   PUTPIXEL(cdata,xc-r,yc);    // felso szel
00322   y=r;
00323   x=1;
00324   y=(int)(sqrt(r2-1)+0.5);
00325   while(x<y)
00326   {
00327     PUTPIXEL(cdata,xc+x,yc+y);      // jobb also
00328     PUTPIXEL(cdata,xc+x,yc-y);      // jobb felso
00329     PUTPIXEL(cdata,xc-x,yc+y);      // bal also
00330     PUTPIXEL(cdata,xc-x,yc-y);      // bal felso
00331     PUTPIXEL(cdata,xc+y,yc+x);      // jobb kozepso-also
00332     PUTPIXEL(cdata,xc+y,yc-x);      // jobb kozepso-felso
00333     PUTPIXEL(cdata,xc-y,yc+x);      // bal kozepso-also
00334     PUTPIXEL(cdata,xc-y,yc-x);      // bal kozepso-felso
00335     x++;
00336     y=(int)(sqrt(r2-x*x)+0.5);
00337   }
00338   if(x==y)
00339   {
00340     PUTPIXEL(cdata,xc+x,yc+y);      // jobb also
00341     PUTPIXEL(cdata,xc+x,yc-y);      // jobb felso
00342     PUTPIXEL(cdata,xc-x,yc+y);      // bal also
00343     PUTPIXEL(cdata,xc-x,yc-y);      // bal felso
00344   }
00345   return(0);
00346 }
00347 static int pvf_cfil(pvf_CustomData_t *cdata, u8 *param)
00348 {
00349   int x2,y2,x1,y1,x,y,ym,xm,i;
00350 
00351   x1=cdata->curr_x;
00352   y1=cdata->curr_y;
00353   x2=(int)getword(param);
00354   y2=(int)getword(param+2);
00355   if(0!=(i=(int)getbyte(param+4)))
00356   {
00357     x2+=cdata->anchors[i].x;
00358     y2+=cdata->anchors[i].y;
00359     if(x2>cdata->width) x2=cdata->width;
00360     else if(x2<0) x2=0;
00361     if(y2>cdata->height) y2=cdata->height;
00362     else if(y2<0) y2=0;
00363   }
00364   else
00365   {
00366     x2=TOSCR(x2,cdata->width);
00367     y2=TOSCR(y2,cdata->height);
00368   }
00369   cdata->curr_x=x2;
00370   cdata->curr_y=y2;
00371   xm=max(x1,x2);
00372   ym=max(y1,y2);
00373   for(y=min(y1,y2);y<ym;y++)
00374     for(x=min(x1,x2);x<xm;x++)
00375       PUTPIXEL(cdata,x,y);
00376   return(0);
00377 }
00378 static int pvf_chln(pvf_CustomData_t *cdata, u8 *param)
00379 {
00380   int i,x,y,s,c;
00381 
00382   x=(int)getword(param);
00383   y=cdata->curr_y;
00384   if(0!=(i=(int)getbyte(param+2)))
00385   {
00386     x+=cdata->anchors[i].x;
00387     if(x>cdata->width) x=cdata->width;
00388     else if(x<0) x=0;
00389   }
00390   else x=TOSCR(x,cdata->width);
00391   c=x;
00392   if(x>cdata->curr_x) { s=x; x=cdata->curr_x; cdata->curr_x=s; }
00393   for(;x<=cdata->curr_x;x++) PUTPIXEL(cdata,x,y);
00394   cdata->curr_x=c;
00395   return(0);
00396 }
00397 static int pvf_cvln(pvf_CustomData_t *cdata, u8 *param)
00398 {
00399   int i,x,y,s,c;
00400 
00401   x=cdata->curr_x;
00402   y=(int)getword(param);
00403   if(0!=(i=(int)getbyte(param+2)))
00404   {
00405     y+=cdata->anchors[i].y;
00406     if(y>cdata->height) y=cdata->height;
00407     else if(y<0) y=0;
00408   }
00409   else y=TOSCR(y,cdata->height);
00410   c=y;
00411   if(y>cdata->curr_y) { s=y; y=cdata->curr_y; cdata->curr_y=s; }
00412   for(;y<=cdata->curr_y;y++) PUTPIXEL(cdata,x,y);
00413   cdata->curr_y=c;
00414   return(0);
00415 }
00416 
00417 
00419 
00420 
00421 static int pvf_dcol(pvf_CustomData_t *cdata, u8 *param)
00422 {
00423   u32 col;
00424 
00425   debug_Begin();
00426 
00427   col=getlong(param);
00428   cdata->curr_col=col;
00429 //  printf("col2: %08x == 0x%02x%02x%02x%02x\n",(int)cdata->curr_col,(u8)(cdata->curr_col>>24),(u8)(cdata->curr_col>>16)&0xff,(u8)(cdata->curr_col>>8)&0xff,(u8)cdata->curr_col&0xff);
00430   api->glw_Call(GLW_SETCOLOR,TAG_GLW_WINDOW,cdata->window,TAG_GLW_RGB,cdata->curr_col,TAG_DONE);
00431 
00432   debug_End();
00433 
00434   return(0);
00435 }
00436 
00437 
00438 static int pvf_dlin(pvf_CustomData_t *cdata, u8 *param)
00439 {
00440   int x1,y1,x2,y2;
00441   int i;
00442 
00443   debug_Begin();
00444 
00445   x1=cdata->curr_x;
00446   y1=cdata->curr_y;
00447   x2=(int)getword(param);
00448   y2=(int)getword(param+2);
00449   if(0!=(i=(int)getbyte(param+4)))
00450   {
00451     x2+=cdata->anchors[i].x;
00452     y2+=cdata->anchors[i].y;
00453     if(x2>cdata->width) x2=cdata->width;
00454     else if(x2<0) x2=0;
00455     if(y2>cdata->height) y2=cdata->height;
00456     else if(y2<0) y2=0;
00457   }
00458   else
00459   {
00460     x2=TOSCR(x2,cdata->width);
00461     y2=TOSCR(y2,cdata->height);
00462   }
00463   api->glw_Call(GLW_DRAWLINE,TAG_GLW_WINDOW,cdata->window,TAG_GLW_X1,x1+cdata->left,TAG_GLW_Y1,y1+cdata->top,TAG_GLW_X2,x2+cdata->left,TAG_GLW_Y2,y2+cdata->top,TAG_DONE);
00464   cdata->curr_x=x2;
00465   cdata->curr_y=y2;
00466 
00467   debug_End();
00468 
00469   return(0);
00470 }
00471 static int pvf_drec(pvf_CustomData_t *cdata, u8 *param)
00472 {
00473   int x2,y2,x1,y1,i;
00474 
00475   debug_Begin();
00476 
00477   x1=cdata->curr_x;
00478   y1=cdata->curr_y;
00479   x2=(int)getword(param);
00480   y2=(int)getword(param+2);
00481   if(0!=(i=(int)getbyte(param+4)))
00482   {
00483     x2+=cdata->anchors[i].x;
00484     y2+=cdata->anchors[i].y;
00485     if(x2>cdata->width) x2=cdata->width;
00486     else if(x2<0) x2=0;
00487     if(y2>cdata->height) y2=cdata->height;
00488     else if(y2<0) y2=0;
00489   }
00490   else
00491   {
00492     x2=TOSCR(x2,cdata->width);
00493     y2=TOSCR(y2,cdata->height);
00494   }
00495   if(x2-x1<0)
00496   {
00497     i=x2; x2=x1; x1=i;
00498     i=y2; y2=y1; y1=i;
00499   }
00500   api->glw_Call(GLW_DRAWRECT,TAG_GLW_WINDOW,cdata->window,TAG_GLW_LEFT,cdata->left+x1,TAG_GLW_TOP,cdata->top+y1,TAG_GLW_WIDTH,x2-x1,TAG_GLW_HEIGHT,y2-y1,TAG_DONE);
00501   cdata->curr_x=x2;
00502   cdata->curr_y=y2;
00503 
00504   debug_End();
00505 
00506   return(0);
00507 }
00508 static int pvf_dcir(pvf_CustomData_t *cdata, u8 *param)
00509 {
00510   int xc,yc,x,y,r2,r;
00511 
00512   debug_Begin();
00513 
00514   r=TOSCR((int)getword(param),min(cdata->width,cdata->height)>>1);
00515   xc=cdata->curr_x;
00516   yc=cdata->curr_y;
00517   r2=r*r;
00518   PUTPIXELD(cdata,xc,yc+r);    // jobb szel
00519   PUTPIXELD(cdata,xc,yc-r);    // bal szel
00520   PUTPIXELD(cdata,xc+r,yc);    // also szel
00521   PUTPIXELD(cdata,xc-r,yc);    // felso szel
00522   y=r;
00523   x=1;
00524   y=(int)(sqrt(r2-1)+0.5);
00525   while(x<y)
00526   {
00527     PUTPIXELD(cdata,xc+x,yc+y);      // jobb also
00528     PUTPIXELD(cdata,xc+x,yc-y);      // jobb felso
00529     PUTPIXELD(cdata,xc-x,yc+y);      // bal also
00530     PUTPIXELD(cdata,xc-x,yc-y);      // bal felso
00531     PUTPIXELD(cdata,xc+y,yc+x);      // jobb kozepso-also
00532     PUTPIXELD(cdata,xc+y,yc-x);      // jobb kozepso-felso
00533     PUTPIXELD(cdata,xc-y,yc+x);      // bal kozepso-also
00534     PUTPIXELD(cdata,xc-y,yc-x);      // bal kozepso-felso
00535     x++;
00536     y=(int)(sqrt(r2-x*x)+0.5);
00537   }
00538   if(x==y)
00539   {
00540     PUTPIXELD(cdata,xc+x,yc+y);      // jobb also
00541     PUTPIXELD(cdata,xc+x,yc-y);      // jobb felso
00542     PUTPIXELD(cdata,xc-x,yc+y);      // bal also
00543     PUTPIXELD(cdata,xc-x,yc-y);      // bal felso
00544   }
00545 
00546   debug_End();
00547 
00548   return(0);
00549 }
00550 static int pvf_dfil(pvf_CustomData_t *cdata, u8 *param)
00551 {
00552   int x2,y2,x1,y1,i;
00553 
00554   debug_Begin();
00555 
00556   x1=cdata->curr_x;
00557   y1=cdata->curr_y;
00558   x2=(int)getword(param);
00559   y2=(int)getword(param+2);
00560   if(0!=(i=(int)getbyte(param+4)))
00561   {
00562     x2+=cdata->anchors[i].x;
00563     y2+=cdata->anchors[i].y;
00564     if(x2>cdata->width) x2=cdata->width;
00565     else if(x2<0) x2=0;
00566     if(y2>cdata->height) y2=cdata->height;
00567     else if(y2<0) y2=0;
00568   }
00569   else
00570   {
00571     x2=TOSCR(x2,cdata->width);
00572     y2=TOSCR(y2,cdata->height);
00573   }
00574   if(x2-x1<0)
00575   {
00576     i=x2; x2=x1; x1=i;
00577     i=y2; y2=y1; y1=i;
00578   }
00579   api->glw_Call(GLW_DRAWFILLEDRECT,TAG_GLW_WINDOW,cdata->window,TAG_GLW_LEFT,cdata->left+x1,TAG_GLW_TOP,cdata->top+y1,TAG_GLW_WIDTH,x2-x1,TAG_GLW_HEIGHT,y2-y1,TAG_DONE);
00580 
00581   debug_End();
00582 
00583   return(0);
00584 }
00585 static int pvf_dhln(pvf_CustomData_t *cdata, u8 *param)
00586 {
00587   int i,x;
00588 
00589   debug_Begin();
00590 
00591   x=(int)getword(param);
00592 //printf("hln param1=%d\n",x);
00593   if(0!=(i=(int)getbyte(param+2)))
00594   {
00595     x+=cdata->anchors[i].x;
00596     if(x>cdata->width) x=cdata->width;
00597     else if(x<0) x=0;
00598 //printf("  hln param=%d\n",x);
00599   }
00600   else x=TOSCR(x,cdata->width);
00601   api->glw_Call(GLW_DRAWLINE,TAG_GLW_WINDOW,cdata->window,TAG_GLW_X1,cdata->curr_x+cdata->left,TAG_GLW_Y1,cdata->curr_y+cdata->top,TAG_GLW_X2,x+cdata->left,TAG_GLW_Y2,cdata->curr_y+cdata->top,TAG_DONE);
00602   cdata->curr_x=x;
00603 
00604   debug_End();
00605 
00606   return(0);
00607 }
00608 static int pvf_dvln(pvf_CustomData_t *cdata, u8 *param)
00609 {
00610   int i,y;
00611 
00612   debug_Begin();
00613 
00614   y=(int)getword(param);
00615   if(0!=(i=(int)getbyte(param+2)))
00616   {
00617     y+=cdata->anchors[i].y;
00618     if(y>cdata->height) y=cdata->height;
00619     else if(y<0) y=0;
00620   }
00621   else y=TOSCR(y,cdata->height);
00622   api->glw_Call(GLW_DRAWLINE,TAG_GLW_WINDOW,cdata->window,TAG_GLW_X1,cdata->curr_x+cdata->left,TAG_GLW_Y1,cdata->curr_y+cdata->top,TAG_GLW_X2,cdata->curr_x+cdata->left,TAG_GLW_Y2,y+cdata->top,TAG_DONE);
00623   cdata->curr_y=y;
00624 
00625   debug_End();
00626 
00627   return(0);
00628 }
00629 
00630 
00631 
00632 
00633 // ez kitolti az image struktura hianyzo mezoit
00634 // ha az input struktura format mezoje ki van toltve,
00635 // es az nem "pvf", akkor FALSE,
00636 // ha NULL akkor egy statikus "pvf"-re allitja, ha
00637 // a data egy valid pvf-nek latszik.
00638 // kitolti a meret mezoket is.
00639 static int pvf_ImgInit(Image_t *img, void (*update)(void *),void *userdata)
00640 {
00641   int ret=-1;
00642   pvf_CustomData_t *cdata;
00643 
00644   debug_Begin();
00645 
00646   if(img!=NULL)
00647   {
00648     if(img->iim.data[0]=='P'&&img->iim.data[1]=='V'&&img->iim.data[2]=='E'&&img->iim.data[3]=='C')
00649     {
00650       if(NULL!=(cdata=mem_calloc(1,sizeof(pvf_CustomData_t))))
00651       {
00652         img->formatdata=cdata;
00653         cdata->img=img;
00654         img->minwidth=1;
00655         img->maxwidth=IMAGE_MAXIMUM_SIZE;
00656         img->minheight=1;
00657         img->maxheight=IMAGE_MAXIMUM_SIZE;
00658         ret=0;
00659       }
00660     }
00661   }
00662 
00663   debug_End();
00664 
00665   return(ret);
00666 }
00667 
00668 
00669 static void pvf_ImgCleanUp(Image_t *img)
00670 {
00671   pvf_CustomData_t *cdata;
00672 
00673   debug_Begin();
00674 
00675   if(img!=NULL)
00676   {
00677     cdata=(pvf_CustomData_t *)img->formatdata;
00678     if(img->formatdata!=NULL) mem_free(img->formatdata);
00679   }
00680 
00681   debug_End();
00682 }
00683 
00684 
00685 // a dest memoriat a hivo prezentalja destsize
00686 // meretben, ha kicsi, hiba (-1)
00687 // a rendereles 32bitesen tortenik, az atlatszo
00688 // pixelek helyere 0xffffffff kerul
00689 static int pvf_ImgRender(Image_t *img, u8 *dest, int destsize, int width, int height)
00690 {
00691   pvf_CustomData_t *cdata;
00692   int i;
00693   struct pvf_command *commands;
00694 
00695   debug_Begin();
00696 
00697   if(img!=NULL&&img->formatdata!=NULL&&dest!=NULL&&destsize>=(width*height*4)&&
00698     width>=img->minwidth&&height>=img->minheight&&
00699     width<=img->maxwidth&&height<=img->maxheight)
00700   {
00701     cdata=(pvf_CustomData_t *)img->formatdata;
00702     cdata->pixels=(u32 *)dest;
00703     cdata->width=width;
00704     cdata->height=height;
00705     cdata->curr_x=cdata->curr_y=0;
00706     cdata->curr_col=0x00ffffff;
00707     cdata->anchors[1].x=0;          // topleft
00708     cdata->anchors[1].y=0;
00709     cdata->anchors[2].x=width;      // topright
00710     cdata->anchors[2].y=0;
00711     cdata->anchors[3].x=0;          // bottomleft
00712     cdata->anchors[3].y=height;
00713     cdata->anchors[4].x=width;      // bottomright
00714     cdata->anchors[4].y=height;
00715     cdata->anchors[5].x=width>>1;   // center
00716     cdata->anchors[5].y=height>>1;
00717     memset(dest,0xff,destsize);
00718     commands=commandsN;
00719     for(i=6;i<img->iim.data_size;)
00720     {
00721       if(img->iim.data[i]<=COMMAND_COUNT)
00722       {
00723         commands[img->iim.data[i]].execute(cdata,&img->iim.data[i+1]);
00724         i+=commands[img->iim.data[i]].len;
00725       }
00726       else printf("illegal command $%02x\n",img->iim.data[i++]);
00727     }
00728   }
00729 
00730   debug_End();
00731 
00732   return(0);
00733 }
00734 
00735 
00736 static void pvf_CleanUp(void)
00737 {
00738   debug_Begin();
00739   debug_End();
00740 }
00741 
00742 
00743 static int pvf_PutImage(Image_t *img, u32 window, Rect_t *rect)
00744 {
00745   int width,height;
00746   pvf_CustomData_t *cdata;
00747   int i;
00748   struct pvf_command *commands;
00749 
00750   debug_Begin();
00751 
00752   width=rect->width;
00753   height=rect->height;
00754   if(img!=NULL&&img->formatdata!=NULL&&
00755     width>=img->minwidth&&height>=img->minheight&&
00756     width<=img->maxwidth&&height<=img->maxheight)
00757   {
00758     cdata=(pvf_CustomData_t *)img->formatdata;
00759     cdata->width=width;
00760     cdata->height=height;
00761     cdata->window=window;
00762     cdata->left=rect->left;
00763     cdata->top=rect->top;
00764     cdata->curr_x=cdata->curr_y=0;
00765     cdata->curr_col=0x00ffffff;
00766     cdata->anchors[1].x=0;          // topleft
00767     cdata->anchors[1].y=0;
00768     cdata->anchors[2].x=width;      // topright
00769     cdata->anchors[2].y=0;
00770     cdata->anchors[3].x=0;          // bottomleft
00771     cdata->anchors[3].y=height;
00772     cdata->anchors[4].x=width;      // bottomright
00773     cdata->anchors[4].y=height;
00774     cdata->anchors[5].x=width>>1;   // center
00775     cdata->anchors[5].y=height>>1;
00776     commands=commandsD;
00777     for(i=6;i<img->iim.data_size;)
00778     {
00779       if(img->iim.data[i]<=COMMAND_COUNT)
00780       {
00781 //        debug_Message("execute: %s",commands[img->iim.data[i]].name);
00782         commands[img->iim.data[i]].execute(cdata,&img->iim.data[i+1]);
00783         i+=commands[img->iim.data[i]].len;
00784       }
00785       else printf("illegal command $%02x\n",img->iim.data[i++]);
00786     }
00787   }
00788 
00789   debug_End();
00790 
00791   return(0);
00792 }
00793 
00794 
00795 static int pvf_Init(u32 module)
00796 {
00797   int ret=-1;
00798   ret=api->img_Call(IMG_REGISTERFORMATCODE,
00799                 TAG_IMG_NAME,(u32)"pvf",
00800                 TAG_IMG_IMG_INIT,(u32)pvf_ImgInit,
00801                 TAG_IMG_IMG_RENDER,(u32)pvf_ImgRender,
00802                 TAG_IMG_IMG_PUTIMAGE,(u32)pvf_PutImage,
00803                 TAG_IMG_IMG_CLEAN,(u32)pvf_ImgCleanUp,
00804                 TAG_IMG_CLEANUP,(u32)pvf_CleanUp,
00805                 TAG_IMG_MODULE,module,
00806                 TAG_DONE);
00807   return(ret);
00808 }
00809 
00810 EXPORT int module_Init(u32 module, bases_Modules_t *bases)
00811 {
00812     api=bases;
00813     return(pvf_Init(module));
00814 }

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