int read_pixmap_file(Display *display, int screen, char *filename, XImage **xi, int *width, int *height) { XpmAttributes attr; XImage *xireturn; attr.valuemask = 0; attr.bitmap_format=ZPixmap; /* instead of XYPixmap */ attr.valuemask |= XpmBitmapFormat; attr.valuemask |= XpmSize; /* we want feedback on width,height */ attr.valuemask |= XpmCharsPerPixel; /* and cpp */ attr.valuemask |= XpmReturnPixels; /* and pixels, npixels */ attr.valuemask |= XpmReturnAllocPixels; /* and alloc_pixels, nalloc_pixels */ attr.exactColors = False; attr.valuemask |= XpmExactColors; /* we don't want exact colors*/ attr.closeness = 30000; attr.valuemask |= XpmCloseness; /* we specify closeness*/ attr.alloc_close_colors = False; attr.valuemask |= XpmAllocCloseColors; /* we don't allocate close colors*/ XpmReadFileToImage(display,filename,xi,&xireturn, &attr ); *width= (*xi)->width; *height=(*xi)->height; #ifdef DEBUG fprintf(stderr,"image file:%s\n",filename); fprintf(stderr,"\twidth:%d\theight:%d\tcpp:%d\n",attr.width,attr.height,attr.cpp); fprintf(stderr,"\tused/alloc'ed color pixels:%d/%d\n",attr.npixels,attr.nalloc_pixels); #endif return 0; }
int read_pixmap_file(Display *display, int screen, char *filename, XImage **xi, int *width, int *height) { XpmAttributes attr; XImage *xireturn; char * real_filename; int status; attr.valuemask = 0; attr.bitmap_format=ZPixmap; /* instead of XYPixmap */ attr.valuemask |= XpmBitmapFormat; attr.valuemask |= XpmSize; /* we want feedback on width,height */ attr.valuemask |= XpmCharsPerPixel; /* and cpp */ attr.valuemask |= XpmReturnPixels; /* and pixels, npixels */ attr.valuemask |= XpmReturnAllocPixels; /* and alloc_pixels, nalloc_pixels */ attr.exactColors = False; attr.valuemask |= XpmExactColors; /* we don't want exact colors*/ attr.closeness = 30000; attr.valuemask |= XpmCloseness; /* we specify closeness*/ attr.alloc_close_colors = False; attr.valuemask |= XpmAllocCloseColors; /* we don't allocate close colors*/ if (file_exists(filename)) { real_filename = filename; } else { real_filename = halloc (strlen(filename)+4, "read_pixmap_file"); sprintf(real_filename, "%s.gz", filename); if (!file_exists (real_filename)) { sprintf(real_filename, "%s.Z", filename); } } status=XpmReadFileToImage(display,real_filename,xi,&xireturn, &attr ); if (status != XpmSuccess) { fprintf(stderr, "read_pixmap_file: unable to open %s\n", filename); exit (1); } *width= (*xi)->width; *height=(*xi)->height; #ifdef DEBUG fprintf(stderr,"image file:%s\n",filename); fprintf(stderr,"\twidth:%d\theight:%d\tcpp:%d\n",attr.width,attr.height,attr.cpp); fprintf(stderr,"\tused/alloc'ed color pixels:%d/%d\n",attr.npixels,attr.nalloc_pixels); #endif return 0; }
void load_icon(Display *d) { int e; XpmAttributes attr; XImage *image,*mask; /* rd xpm to ximage */ attr.valuemask = XpmDepth | XpmBitmapFormat; attr.depth = 32; attr.bitmap_format = ZPixmap; e=XpmReadFileToImage(d,"important.xpm",&image,&mask,&attr); if(e==XpmSuccess) { fprintf(stderr,"xpm read OK\n"); } else return; uint len = image->width * image->height; unsigned long *data = malloc((len+2)*sizeof(unsigned long)); data[0]=image->width; data[1]=image->height; unsigned x,y, bit; uint8_t *m=(void*)mask->data; uint32_t *src = (void*)image->data; unsigned long *dst = data+2; for( y=0; y<image->height; y++ ) { bit = 1; for( x = 0; x < image->width; x++ ) { if( *m & bit ) *dst = *src | (0xffUL << 24); else *dst = *src; if( bit == 128 ) { bit=1; m++; } else bit <<= 1; dst++; src++; } } #if 0 unsigned i; for(i=0;i<len;i++) data[2+i] = (((uint32_t*)image->data)[i]) | (0xffUL << 24); #endif len += 2; icon_length = len; icon_data = data; XDestroyImage(image); XDestroyImage(mask); }
void VlcPlugin::showToolbar() { const NPWindow& window = getWindow(); Window control = getControlWindow(); Window video = getVideoWindow(); Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display; unsigned int i_height = 0, i_width = BTN_SPACE; /* load icons */ if( !p_btnPlay ) XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm", &p_btnPlay, NULL, NULL); if( p_btnPlay ) { i_height = __MAX( i_height, p_btnPlay->height ); } if( !p_btnPause ) XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm", &p_btnPause, NULL, NULL); if( p_btnPause ) { i_height = __MAX( i_height, p_btnPause->height ); } i_width += __MAX( p_btnPause->width, p_btnPlay->width ); if( !p_btnStop ) XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm", &p_btnStop, NULL, NULL ); if( p_btnStop ) { i_height = __MAX( i_height, p_btnStop->height ); i_width += BTN_SPACE + p_btnStop->width; } if( !p_timeline ) XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm", &p_timeline, NULL, NULL); if( p_timeline ) { i_height = __MAX( i_height, p_timeline->height ); i_width += BTN_SPACE + p_timeline->width; } if( !p_btnTime ) XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm", &p_btnTime, NULL, NULL); if( p_btnTime ) { i_height = __MAX( i_height, p_btnTime->height ); i_width += BTN_SPACE + p_btnTime->width; } if( !p_btnFullscreen ) XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm", &p_btnFullscreen, NULL, NULL); if( p_btnFullscreen ) { i_height = __MAX( i_height, p_btnFullscreen->height ); i_width += BTN_SPACE + p_btnFullscreen->width; } if( !p_btnMute ) XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm", &p_btnMute, NULL, NULL); if( p_btnMute ) { i_height = __MAX( i_height, p_btnMute->height ); } if( !p_btnUnmute ) XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm", &p_btnUnmute, NULL, NULL); if( p_btnUnmute ) { i_height = __MAX( i_height, p_btnUnmute->height ); } i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width ); setToolbarSize( i_width, i_height ); if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline || !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute ) fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH ); /* reset panels position and size */ /* XXX use i_width */ XResizeWindow( p_display, video, window.width, window.height - i_height); XMoveWindow( p_display, control, 0, window.height - i_height ); XResizeWindow( p_display, control, window.width, i_height -1); b_toolbar = 1; /* says toolbar is now shown */ redrawToolbar(); }
int load_xpm_image(char *file, FILE *fp, Display *disp, struct Image **simg, unsigned short iattr) { int comment=0, quote=0, w, h, cols, cpp, i=0, ret, depth; char c=' ', pc, line[30]; struct Image *img=NULL; XpmAttributes attr; depth = DefaultDepth(disp, DefaultScreen(disp)); // Check for the maximum image dimension supported while(!feof(fp)) { pc = c; c = getc(fp); if(!quote) { if(pc=='/' && c=='*') comment = 1; else if(pc=='*' && c=='/' && comment) comment = 0; } if(!comment) { if(!quote && c=='"') { quote = 1; i = 0; continue; } else if(quote && c=='"') { line[i] = 0; quote = 0; // Get the image dimension, colors and chars/pixel sscanf(line, "%d %d %d %d", &w, &h, &cols, &cpp); if(cols>65000 || cpp>5) return EBADIMG; if(w*h > MAX_WIDTH*MAX_HEIGHT) return EBIGIMG; // Create a node img = (struct Image*)malloc(sizeof(struct Image)); img->delay = 0; img->x = img->y = 0; img->width = w; img->height = h; img->next = NULL; img->img = img->mimg = NULL; break; } if(quote) { line[i++] = c; } } } memset(&attr, 0x00, sizeof(XpmAttributes)); attr.valuemask |= XpmRGBCloseness; attr.closeness = 80000; attr.red_closeness = 40000; attr.green_closeness = 40000; attr.blue_closeness = 40000; if(iattr & SHAPE_MASK) { ret = XpmReadFileToImage(disp, file, &img->img, &img->mimg, &attr); } else { ret = XpmReadFileToImage(disp, file, &img->img, NULL, &attr); } if(ret==XpmFileInvalid) { free(img); return EBADIMG; } if(ret==XpmNoMemory) { free(img); return ENOMEMR; } if(ret==XpmOpenFailed || ret==XpmColorFailed) { free(img); return ENOSUPP; } // Add the Image node to the list _pimg_imglst_add(simg, img); return 0; }
void getImage(ModeInfo * mi, XImage ** logo, int default_width, int default_height, unsigned char *default_bits, #ifdef HAVE_XPM int default_xpm, char **name, #endif int *graphics_format, Colormap * ncm, unsigned long *black) { Display *display = MI_DISPLAY(mi); static char *bitmap_local = (char *) NULL; #ifndef STANDALONE #ifdef HAVE_XPM XpmAttributes attrib; #endif #if 0 /* This probably works best in most cases but for random mode used with random selection of a file it will fail often. */ *ncm = None; #else if (!fixedColors(mi)) *ncm = XCreateColormap(display, MI_WINDOW(mi), MI_VISUAL(mi), AllocNone); else *ncm = None; #endif #ifdef HAVE_XPM attrib.visual = MI_VISUAL(mi); if (*ncm == None) { attrib.colormap = MI_COLORMAP(mi); } else { attrib.colormap = *ncm; } attrib.depth = MI_DEPTH(mi); attrib.valuemask = XpmVisual | XpmColormap | XpmDepth; #endif #endif /* !STANDALONE */ *graphics_format = 0; if (bitmap_local != NULL) { free(bitmap_local); bitmap_local = (char *) NULL; } if (MI_BITMAP(mi) && strlen(MI_BITMAP(mi))) { #ifdef STANDALONE bitmap_local = MI_BITMAP(mi); #else if ((bitmap_local = (char *) malloc(256)) == NULL) { (void) fprintf(stderr , "no memory for \"%s\"\n" , MI_BITMAP(mi)); return; } (void) strncpy(bitmap_local, MI_BITMAP(mi), 256); #if HAVE_DIRENT_H getRandomFile(MI_BITMAP(mi), bitmap_local); #endif #endif /* STANDALONE */ } if (bitmap_local && strlen(bitmap_local)) { #if defined( USE_MAGICK ) && !defined( STANDALONE ) if ( readable( bitmap_local ) ) { if ( MI_NPIXELS( mi ) > 2 ) { Colormap magick_colormap; if (*ncm == None) { magick_colormap = MI_COLORMAP(mi); } else { magick_colormap = *ncm; } if ( MagickSuccess == MagickFileToImage( mi , bitmap_local , logo , magick_colormap ) ) { *graphics_format = IS_MAGICKFILE; *black = GetColor(mi, MI_BLACK_PIXEL(mi)); (void) GetColor(mi, MI_WHITE_PIXEL(mi)); (void) GetColor(mi, MI_BG_PIXEL(mi)); (void) GetColor(mi, MI_FG_PIXEL(mi)); } } } else { (void) fprintf(stderr , "could not read file \"%s\"\n" , bitmap_local); } #else # ifndef STANDALONE if (readable(bitmap_local)) { if (MI_NPIXELS(mi) > 2) { Colormap ras_colormap; if (*ncm == None) { ras_colormap = MI_COLORMAP(mi); } else { ras_colormap = *ncm; } if (RasterSuccess == RasterFileToImage(mi, bitmap_local, logo , ras_colormap )) { *graphics_format = IS_RASTERFILE; *black = GetColor(mi, MI_BLACK_PIXEL(mi)); (void) GetColor(mi, MI_WHITE_PIXEL(mi)); (void) GetColor(mi, MI_BG_PIXEL(mi)); (void) GetColor(mi, MI_FG_PIXEL(mi)); } } } else { (void) fprintf(stderr, "could not read file \"%s\"\n", bitmap_local); } #ifdef HAVE_XPM #ifndef USE_MONOXPM if (MI_NPIXELS(mi) > 2) #endif { if (*graphics_format <= 0) { if (*ncm != None) reserveColors(mi, *ncm, black); if (XpmSuccess == XpmReadFileToImage(display, bitmap_local, logo, (XImage **) NULL, &attrib)) *graphics_format = IS_XPMFILE; } } #endif #endif /* !STANDALONE */ if (*graphics_format <= 0) { if (!blogo.data) { if (BitmapSuccess == XbmReadFileToImage(bitmap_local, &blogo.width, &blogo.height, (unsigned char **) &blogo.data)) { blogo.bytes_per_line = (blogo.width + 7) / 8; *graphics_format = IS_XBMFILE; *logo = &blogo; } } else { *graphics_format = IS_XBMDONE; *logo = &blogo; } } #endif if (*graphics_format <= 0 && MI_IS_VERBOSE(mi)) (void) fprintf(stderr, "\"%s\" is in an unrecognized format or not compatible with screen\n", bitmap_local); } #ifndef STANDALONE #ifdef HAVE_XPM if (*graphics_format <= 0 && ((MI_IS_FULLRANDOM(mi)) ? LRAND() & 1: default_xpm)) #ifndef USE_MONOXPM if (MI_NPIXELS(mi) > 2) #endif if (XpmSuccess == XpmCreateImageFromData(display, name, logo, (XImage **) NULL, &attrib)) *graphics_format = IS_XPM; #endif #endif /* STANDALONE */ if (*graphics_format <= 0) { if (!blogo.data) { blogo.data = (char *) default_bits; blogo.width = default_width; blogo.height = default_height; blogo.bytes_per_line = (blogo.width + 7) / 8; *graphics_format = IS_XBM; } else *graphics_format = IS_XBMDONE; *logo = &blogo; } #ifndef STANDALONE /* Come back later */ if (*ncm != None && *graphics_format != IS_RASTERFILE && *graphics_format != IS_XPMFILE && *graphics_format != IS_XPM && *graphics_format != IS_MAGICKFILE) { XFreeColormap(display, *ncm); *ncm = None; } #endif /* STANDALONE */ /* Come back later */ }
/* **************************************************************** * Lê o arquivo XPM, gerando uma XImage * **************************************************************** */ XImage * load_XPM_file (FILE *fp, int image_number, Display *dpy, XStandardColormap *xstdcmap, IMAGE *ip) { XImage *ximage, *shapeimage; XWindowAttributes root_attr; XpmAttributes attr; int val; Window root; if (image_number != 1) { msg ("Arquivo XPM \"%s\" tem apenas uma imagem", ip->i_name); return (NULL); } root = RootWindow (dpy, DefaultScreen (dpy)); XGetWindowAttributes (dpy, root, &root_attr); attr.colormap = root_attr.colormap; attr.valuemask = XpmInfos | XpmReturnPixels | XpmColormap; fclose (fp); val = XpmReadFileToImage (dpy, (char *)ip->i_name, &ximage, &shapeimage, &attr); switch (val) { case XpmSuccess: break; case XpmOpenFailed: msg ("*Não consegui abrir \"%s\"", ip->i_name); break; case XpmColorFailed: msg ("Impossível alocar as cores pedidas"); break; case XpmFileInvalid: msg ("Formato inválido do arquivo \"%s\"", ip->i_name); break; case XpmColorError: msg ("Especificação de cor inválida em \"%s\"", ip->i_name); break; case XpmNoMemory: msg ("*Memória insuficiente"); break; } /* * Epílogo. */ if (ip != NULL) { ip->i_width = attr.width; ip->i_height = attr.height; ip->i_ncolors = attr.ncolors; } if (val != XpmSuccess) ximage = NULL; return (ximage); } /* end load_XPM_file */