Bool setupColormap(ModeInfo * mi, int *colors, Bool * truecolor, unsigned long *red_mask, unsigned long *blue_mask, unsigned long *green_mask) { /* how many colours are there altogether? */ *colors = MI_NPIXELS(mi); if (*colors > MI_COLORMAP_SIZE(mi)) { *colors = MI_COLORMAP_SIZE(mi); } if (*colors < 2) *colors = 2; *truecolor = (MI_VISUALCLASS(mi) == TrueColor); *red_mask = MI_RED_MASK(mi); *green_mask = MI_GREEN_MASK(mi); *blue_mask = MI_BLUE_MASK(mi); return !fixedColors(mi); }
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 */ }