#include <gtk/gtk.h>#include <limits.h>#include <sys/time.h>

Go to the source code of this file.
Defines | |
| #define | ARRAYSIZE(ARR) (sizeof(ARR)/sizeof(ARR[0])) |
| #define | HTMLCOLOR_LEN sizeof("#000000") |
Enumerations | |
| enum | HW_COLOR { COLOR_WHITE = 0, COLOR_LIGHT_GRAY = 1, COLOR_DARK_GRAY = 2, COLOR_BLACK = 3 } |
| enum | IMGTYPE { TYPE_BMP = 1, TYPE_PNG, TYPE_JPG, TYPE_INVALID } |
Functions | |
| int | Util_GdkColorFromHWCOLOR (GdkColor *pGdkColor, HW_COLOR iHwColor) |
| HW_COLOR | Util_HWCOLORFromGdkColor () |
| int | Util_GdkColorFromHtmlColor (GdkColor *pGdkColor, const char *sHtmlColor) |
| int | Util_HtmlColorFromGdkColor (char *sHtmlColor, int iSize, const GdkColor *pGdkColor) |
| gboolean | FileExist (const char *filename) |
| gboolean | FileExist2 (const char *filename, const char *dir) |
| int | FileDel (const char *filename) |
| int | FileMove (const char *sDestFile, const char *sSrcFile) |
| int | CreateDir (const char *sPath) |
| void | GetFileNameAndDir (char *sFileName, int iNameSize, char *sDir, int iDirSize, const char *sFullName) |
| char * | GetFileNameFromFullName (char *sFileName, int iSize, const char *sFullName) |
| char * | GetDirFromFullName (char *sDir, int iSize, const char *sFullName) |
| int | GetStrFromTime (char *sTime, int iSize, time_t iTime) |
| gboolean | isStrEmpty (const char *s) |
| int | util_loadImage (GdkPixbuf **buf, const char *filename) |
| int | util_loadImage_bysize (GdkPixbuf **buf, const char *filename, int width, int height) |
| int | util_savePixbuf (GdkPixbuf *pixbuf, char *filename, IMGTYPE filetype) |
| int | util_saveImage (GdkPixmap *pixmap, char *filename, IMGTYPE filetype) |
| #define ARRAYSIZE | ( | ARR | ) | (sizeof(ARR)/sizeof(ARR[0])) |
Copyright (C) 2005-2008 iRex Technologies B.V. All rights reserved.
Definition at line 39 of file ScribbleUtils.h.
| #define HTMLCOLOR_LEN sizeof("#000000") |
Definition at line 49 of file ScribbleUtils.h.
| enum HW_COLOR |
Definition at line 42 of file ScribbleUtils.h.
00042 { 00043 COLOR_WHITE=0, 00044 COLOR_LIGHT_GRAY=1, 00045 COLOR_DARK_GRAY=2,//in select clor or pen size 00046 COLOR_BLACK=3, 00047 }HW_COLOR;//hardware color,not gdb color set.
| enum IMGTYPE |
Definition at line 100 of file ScribbleUtils.h.
00101 { 00102 TYPE_BMP=1, 00103 TYPE_PNG, 00104 TYPE_JPG, 00105 TYPE_INVALID, 00106 } IMGTYPE;
| int CreateDir | ( | const char * | sPath | ) |
| int FileDel | ( | const char * | filename | ) |
| gboolean FileExist | ( | const char * | filename | ) |
Definition at line 134 of file ScribbleUtils.c.
00135 { 00136 struct stat buf; 00137 00138 if(NULL==filename) return FALSE; 00139 00140 return ( 0==stat(filename, &buf) ); 00141 }
| gboolean FileExist2 | ( | const char * | filename, | |
| const char * | dir | |||
| ) |
Definition at line 144 of file ScribbleUtils.c.
00145 { 00146 if(NULL==filename && NULL==dir) return FALSE; 00147 00148 char sFullPathName[512]; 00149 memset(sFullPathName,0,sizeof(sFullPathName)); 00150 snprintf(sFullPathName,sizeof(sFullPathName), 00151 "%s%s",dir,filename); 00152 00153 return FileExist(sFullPathName); 00154 }

| int FileMove | ( | const char * | sDestFile, | |
| const char * | sSrcFile | |||
| ) |
Definition at line 163 of file ScribbleUtils.c.
00164 { 00165 if( NULL==sDestFile || NULL==sSrcFile ) return -1; 00166 if( FileExist(sDestFile) ) 00167 { 00168 if( 0!=FileDel(sDestFile) ) 00169 { 00170 SB_ERRORPRINTF("del [%s] fail\n",sDestFile); 00171 return -1;//delete bakfile 00172 } 00173 } 00174 if( 0!=rename(sSrcFile,sDestFile) ) 00175 { 00176 SB_ERRORPRINTF("\nrename [%s]\nto[%s] fail\n",sSrcFile,sDestFile); 00177 return -1;//delete bakfile 00178 } 00179 00180 return 0; 00181 }

| char* GetDirFromFullName | ( | char * | sDir, | |
| int | iSize, | |||
| const char * | sFullName | |||
| ) |
Definition at line 233 of file ScribbleUtils.c.
00234 { 00235 char sFileName[512+1]; 00236 GetFileNameAndDir(sFileName,sizeof(sFileName),sDir,iSize,sFullName); 00237 return sDir; 00238 }

| void GetFileNameAndDir | ( | char * | sFileName, | |
| int | iNameSize, | |||
| char * | sDir, | |||
| int | iDirSize, | |||
| const char * | sFullName | |||
| ) |
Definition at line 189 of file ScribbleUtils.c.
00192 { 00193 int iLen=strlen(sFullName); 00194 int iDestLen=0; 00195 SB_FMPRINTF("__fullname=%s\n",sFullName); 00196 for(iDestLen=0;iDestLen<iLen;iDestLen++) 00197 { 00198 if(sFullName[iLen-1-iDestLen] == '/') 00199 break; 00200 } 00201 //fetch dir 00202 memset(sDir,0,iDirSize); 00203 if(iDestLen==iLen) //no path char 00204 { 00205 strcpy(sDir,"./");//current directory 00206 } 00207 else 00208 { 00209 strncpy(sDir,sFullName,iLen-iDestLen);//keep last"/" 00210 } 00211 00212 if(iDestLen>0) 00213 { 00214 if(iDestLen>iDirSize-1) iDestLen=iDirSize-1; 00215 strncpy(sFileName,sFullName+iLen-iDestLen,iDestLen); 00216 } 00217 00218 sFileName[iDestLen]=0; 00219 SB_FMPRINTF("\n__dir=%s,filename=%s\n",sDir,sFileName); 00220 }
| char* GetFileNameFromFullName | ( | char * | sFileName, | |
| int | iSize, | |||
| const char * | sFullName | |||
| ) |
Definition at line 223 of file ScribbleUtils.c.
00225 { 00226 char sDir[512+1]; 00227 GetFileNameAndDir(sFileName,iSize,sDir,sizeof(sDir),sFullName); 00228 return sFileName; 00229 }

| int GetStrFromTime | ( | char * | sTime, | |
| int | iSize, | |||
| time_t | iTime | |||
| ) |
Definition at line 243 of file ScribbleUtils.c.
00244 { 00245 struct tm *tmp; 00246 tmp = (struct tm *)localtime(&iTime); 00247 if ( NULL==tmp ) 00248 { 00249 SB_ERRORPRINTF("error get localtime"); 00250 return -1; 00251 } 00252 memset(sTime,0,sizeof(iSize)); 00253 /* 00254 printf("time is:%02d,%02d,%02d,%02d,%2d,%02d\n", 00255 tmp->tm_sec, // Seconds. [0-60] (1 leap second) 00256 tmp->tm_min, // Minutes. [0-59] 00257 tmp->tm_hour, // Hours. [0-23] 00258 tmp->tm_mday, // Day. [1-31] 00259 tmp->tm_mon, // Month. [0-11] 00260 tmp->tm_year-100); //year-1900 00261 */ 00262 if (strftime(sTime, iSize, "%Y-%m-%d__%H-%M-%S", tmp) == 0) 00263 { 00264 SB_ERRORPRINTF("strftime returned 0"); 00265 return -1; 00266 } 00267 //SB_LOGPRINTF("time str:%s\n",sTime); 00268 return 0; 00269 }
| gboolean isStrEmpty | ( | const char * | s | ) |
Definition at line 274 of file ScribbleUtils.c.
00275 { 00276 if ( NULL==s ) return TRUE; 00277 00278 int i; 00279 00280 for( i=0; i<strlen(s); i++ ) 00281 { 00282 if( ' '!=s[i] ) return FALSE;//find a meaningful char. 00283 } 00284 return TRUE; 00285 }
| int Util_GdkColorFromHtmlColor | ( | GdkColor * | pGdkColor, | |
| const char * | sHtmlColor | |||
| ) |
Definition at line 94 of file ScribbleUtils.c.
00095 { 00096 if( NULL==pGdkColor || NULL==sHtmlColor) 00097 { 00098 return -1; 00099 } 00100 if( '#'!=sHtmlColor[0] && strlen(sHtmlColor)!=HTMLCOLOR_LEN ) 00101 { 00102 return -1; 00103 } 00104 00105 unsigned int rgbValue; 00106 sscanf(sHtmlColor+1,"%x",&rgbValue); 00107 //printf("color=%s,rgbvalue=%08x\n",sHtmlColor,rgbValue); 00108 00109 //first compute the max-255 color,then transform to max-0xffff. 00110 pGdkColor->red= GET_GDKCOLOR( (rgbValue>>16)& 0xff ); 00111 pGdkColor->green= GET_GDKCOLOR( (rgbValue&0xff00)>>8 ); 00112 pGdkColor->blue= GET_GDKCOLOR( rgbValue & 0x00ff ); 00113 00114 return 0; 00115 }
| int Util_GdkColorFromHWCOLOR | ( | GdkColor * | pGdkColor, | |
| HW_COLOR | iHwColor | |||
| ) |
Definition at line 52 of file ScribbleUtils.c.
00053 { 00054 if(iHwColor<0 || iHwColor>3) iHwColor=COLOR_BLACK; 00055 00056 if( NULL==pGdkColor) return -1; 00057 00058 pGdkColor->red=pGdkColor->green=pGdkColor->blue 00059 =COLORVALUE[iHwColor]; 00060 return 0; 00061 }
| int Util_HtmlColorFromGdkColor | ( | char * | sHtmlColor, | |
| int | iSize, | |||
| const GdkColor * | pGdkColor | |||
| ) |
Definition at line 118 of file ScribbleUtils.c.
00119 { 00120 if( NULL==pGdkColor || NULL==sHtmlColor || iSize<(HTMLCOLOR_LEN+1) ) 00121 { 00122 return -1; 00123 } 00124 00125 unsigned int rgbValue= (GET_256COLOR(pGdkColor->red) & 0xff)<<16; 00126 rgbValue |= (GET_256COLOR(pGdkColor->green) &0xff)<<8; 00127 rgbValue |= GET_256COLOR(pGdkColor->blue) & 0xff; 00128 00129 snprintf(sHtmlColor,iSize,"#%06x",rgbValue); 00130 00131 return 0; 00132 }
| HW_COLOR Util_HWCOLORFromGdkColor | ( | ) |
| int util_loadImage | ( | GdkPixbuf ** | buf, | |
| const char * | filename | |||
| ) |
Definition at line 306 of file ScribbleUtils.c.
00307 { 00308 GError *error = NULL; 00309 00310 SB_FMPRINTF("__Loading(%s)...\n",filename); 00311 (*buf) = gdk_pixbuf_new_from_file(filename, &error); 00312 if ((*buf)==NULL) 00313 { 00314 SB_ERRORPRINTF("Error loading bitmap(%s)\n", filename); 00315 if( NULL!= error ) 00316 { 00317 SB_ERRORPRINTF("Error msg\n(%s)\n",error->message); 00318 } 00319 return -1; 00320 } 00321 //dumpPixbufInfo(*buf); 00322 SB_FMPRINTF("__Loaded...\n"); 00323 return 0; 00324 }
| int util_loadImage_bysize | ( | GdkPixbuf ** | buf, | |
| const char * | filename, | |||
| int | width, | |||
| int | height | |||
| ) |
Definition at line 327 of file ScribbleUtils.c.
00328 { 00329 int w, h; 00330 GdkPixbufFormat* format; 00331 GError *error = NULL; 00332 00333 format = gdk_pixbuf_get_file_info(filename, &w, &h); 00334 if (format) 00335 { 00336 SB_FMPRINTF("__Loading(%s)...\n",filename); 00337 if ((w <= width) && (h <= height)) 00338 { 00339 (*buf) = gdk_pixbuf_new_from_file_at_size(filename, w, h, &error); 00340 } 00341 else 00342 { 00343 (*buf) = gdk_pixbuf_new_from_file_at_size(filename, width, height, &error); 00344 } 00345 if ((*buf)==NULL) 00346 { 00347 SB_ERRORPRINTF("Error loading bitmap\n(%s)\n", filename); 00348 if( NULL!= error ) 00349 { 00350 SB_ERRORPRINTF("Error msg\n(%s)\n",error->message); 00351 } 00352 return -1; 00353 } 00354 //dumpPixbufInfo(*buf); 00355 SB_FMPRINTF("__Loaded...\n"); 00356 } 00357 else 00358 { 00359 SB_ERRORPRINTF("unknow image format of %s", filename); 00360 } 00361 return 0; 00362 }
| int util_saveImage | ( | GdkPixmap * | pixmap, | |
| char * | filename, | |||
| IMGTYPE | filetype | |||
| ) |
Definition at line 396 of file ScribbleUtils.c.
00399 { 00400 GdkPixbuf *pixbuf; 00401 00402 SB_TIMEDISPLAY("__Saving-->\n%s\n",filename); 00403 gdk_threads_enter(); 00404 pixbuf = gdk_pixbuf_get_from_drawable(NULL,(GdkDrawable *)pixmap, 00405 NULL,0,0,0,0,-1,-1); 00406 gdk_flush();//make sure all x command has sent to X server. 00407 gdk_threads_leave(); 00408 int iRet=util_savePixbuf(pixbuf,filename,filetype); 00409 00410 if(pixbuf) 00411 { 00412 g_object_unref(pixbuf); 00413 } 00414 return iRet; 00415 }

| int util_savePixbuf | ( | GdkPixbuf * | pixbuf, | |
| char * | filename, | |||
| IMGTYPE | filetype | |||
| ) |
Definition at line 379 of file ScribbleUtils.c.
00382 { 00383 GError *error = NULL; 00384 //dumpPixbufInfo(pixbuf); 00385 SB_TIMEDISPLAY("--start save \n%s\n",filename); 00386 if (!gdk_pixbuf_save(pixbuf, filename,getFileExtension(filetype), &error, NULL)) 00387 { 00388 SB_ERRORPRINTF("Error saving image.msg(%s)\n",error->message); 00389 return -1; 00390 } 00391 SB_TIMEDISPLAY("__Saved Done\n"); 00392 return 0; 00393 }

1.5.6