?? gdk-pixbuf-xlibrgb.c
字號:
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "MPL"); you may not use this file except in * compliance with the MPL. You may obtain a copy of the MPL at * http://www.mozilla.org/MPL/ * * Software distributed under the MPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the MPL * for the specific language governing rights and limitations under the * MPL. * * Alternatively, the contents of this file may be used under the * terms of the GNU Library General Public License (the "LGPL"), in * which case the provisions of the LGPL are applicable instead of * those above. If you wish to allow use of your version of this file * only under the terms of the LGPL and not to allow others to use * your version of this file under the MPL, indicate your decision by * deleting the provisions above and replace them with the notice and * other provisions required by the LGPL. If you do not delete the * provisions above, a recipient may use your version of this file * under either the MPL or the LGPL. *//* * This code is derived from GdkRgb. * For more information on GdkRgb, see http://www.levien.com/gdkrgb/ * Raph Levien <raph@acm.org> *//* Ported by Christopher Blizzard to Xlib. With permission from the * original authors and the copyright holders of this file, the * contents of this file are also redistributable under the terms of * the Mozilla Public license. For information about the Mozilla * Public License, please see the license information at * http://www.mozilla.org/MPL/ *//* This code is copyright the following authors: * Raph Levien <raph@acm.org> * Manish Singh <manish@gtk.org> * Tim Janik <timj@gtk.org> * Peter Mattis <petm@xcf.berkeley.edu> * Spencer Kimball <spencer@xcf.berkeley.edu> * Josh MacDonald <jmacd@xcf.berkeley.edu> * Christopher Blizzard <blizzard@redhat.com> * Owen Taylor <otaylor@redhat.com> * Shawn T. Amundson <amundson@gtk.org>*/#if HAVE_CONFIG_H# include <config.h># if STDC_HEADERS# include <stdio.h># include <stdlib.h># include <string.h># endif#else# include <stdio.h># include <stdlib.h>#endif#include <math.h>#define ENABLE_GRAYSCALE/* include this before so that we can get endian definitions if they are there... */#include "gdk-pixbuf-xlibrgb.h"#ifndef MIN#define MIN(a, b) (((a) < (b)) ? (a) : (b))#endif#ifndef MAX#define MAX(a, b) (((a) > (b)) ? (a) : (b))#endiftypedef enum { LSB_FIRST, MSB_FIRST} ByteOrder;typedef struct _XlibRgbInfo XlibRgbInfo;typedef void (*XlibRgbConvFunc) (XImage *image, int ax, int ay, int width, int height, unsigned char *buf, int rowstride, int x_align, int y_align, XlibRgbCmap *cmap);/* Some of these fields should go, as they're not being used at all. Globals should generally migrate into here - it's very likely that we'll want to run more than one GdkRgbInfo context at the same time (i.e. some but not all windows have privately installed colormaps). */struct _XlibRgbInfo{ Display *display; Screen *screen; int screen_num; XVisualInfo *x_visual_info; Colormap cmap; XColor *cmap_colors; Visual *default_visualid; Colormap default_colormap; unsigned long *color_pixels; unsigned long *gray_pixels; unsigned long *reserved_pixels; unsigned long red_shift; unsigned long red_prec; unsigned long blue_shift; unsigned long blue_prec; unsigned long green_shift; unsigned long green_prec; unsigned int nred_shades; unsigned int ngreen_shades; unsigned int nblue_shades; unsigned int ngray_shades; unsigned int nreserved; unsigned int bpp; unsigned int cmap_alloced; double gamma_val; /* Generally, the stage buffer is used to convert 32bit RGB, gray, and indexed images into 24 bit packed RGB. */ unsigned char *stage_buf; XlibRgbCmap *gray_cmap; Bool dith_default; Bool bitmap; /* set true if in 1 bit per pixel mode */ GC own_gc; /* Convert functions */ XlibRgbConvFunc conv; XlibRgbConvFunc conv_d; XlibRgbConvFunc conv_32; XlibRgbConvFunc conv_32_d; XlibRgbConvFunc conv_gray; XlibRgbConvFunc conv_gray_d; XlibRgbConvFunc conv_indexed; XlibRgbConvFunc conv_indexed_d;};static Bool xlib_rgb_install_cmap = FALSE;static int xlib_rgb_min_colors = 5 * 5 * 5;static Bool xlib_rgb_verbose = FALSE;#define IMAGE_WIDTH 256#define STAGE_ROWSTRIDE (IMAGE_WIDTH * 3)#define IMAGE_HEIGHT 64#define N_IMAGES 6static XlibRgbInfo *image_info = NULL;static XImage *static_image[N_IMAGES];static int static_image_idx;static unsigned char *colorcube;static unsigned char *colorcube_d;static unsigned longxlib_get_prec_from_mask(unsigned long val){ unsigned long retval = 0; unsigned int cur_bit = 0; /* walk through the number, incrementing the value if the bit in question is set. */ while (cur_bit < (sizeof(unsigned long) * 8)) { if ((val >> cur_bit) & 0x1) { retval++; } cur_bit++; } return retval;}static unsigned longxlib_get_shift_from_mask(unsigned long val){ unsigned long cur_bit = 0; /* walk through the number, looking for the first 1 */ while (cur_bit < (sizeof(unsigned long) * 8)) { if ((val >> cur_bit) & 0x1) { return cur_bit; } cur_bit++; } return cur_bit;}static intxlib_rgb_cmap_fail (const char *msg, Colormap cmap, unsigned long *pixels){ unsigned long free_pixels[256]; int n_free; int i;#ifdef VERBOSE printf ("%s", msg);#endif n_free = 0; for (i = 0; i < 256; i++) if (pixels[i] < 256) free_pixels[n_free++] = pixels[i]; if (n_free) XFreeColors(image_info->display, cmap, free_pixels, n_free, 0); return 0;}static voidxlib_rgb_make_colorcube (unsigned long *pixels, int nr, int ng, int nb){ unsigned char rt[16], gt[16], bt[16]; int i; colorcube = malloc(sizeof(unsigned char) * 4096); memset(colorcube, 0, (sizeof(unsigned char) * 4096)); for (i = 0; i < 16; i++) { rt[i] = ng * nb * ((i * 17 * (nr - 1) + 128) >> 8); gt[i] = nb * ((i * 17 * (ng - 1) + 128) >> 8); bt[i] = ((i * 17 * (nb - 1) + 128) >> 8); } for (i = 0; i < 4096; i++) { colorcube[i] = pixels[rt[i >> 8] + gt[(i >> 4) & 0x0f] + bt[i & 0x0f]];#ifdef VERBOSE printf ("%03x %02x %x %x %x\n", i, colorcube[i], rt[i >> 8], gt[(i >> 4) & 0x0f], bt[i & 0x0f]);#endif }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -