📄 gdkrgb.c
字号:
/* GDK - The GIMP Drawing Kit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *//* For more information on GdkRgb, see http://www.levien.com/gdkrgb/ Raph Levien <raph@acm.org> *//* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */#include <math.h>#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#define ENABLE_GRAYSCALE#ifdef GDK_RGB_STANDALONE/* Compiling as a standalone module (i.e. with Gtk 1.0) *//* gtk/gtk.h is already included in gdkrgbstub.c */#include "config.h"#include <gdk/gdkprivate.h>#else/* Compiling as a part of Gtk 1.1 or later */#include "../config.h"#include "gdk.h"#include "gdkprivate.h"#endif#include "gdkrgb.h"typedef struct _GdkRgbInfo GdkRgbInfo;typedef void (*GdkRgbConvFunc) (GdkImage *image, gint x0, gint y0, gint width, gint height, guchar *buf, int rowstride, gint x_align, gint y_align, GdkRgbCmap *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 _GdkRgbInfo{ GdkVisual *visual; GdkColormap *cmap; gulong *color_pixels; gulong *gray_pixels; gulong *reserved_pixels; guint nred_shades; guint ngreen_shades; guint nblue_shades; guint ngray_shades; guint nreserved; guint bpp; gint cmap_alloced; gdouble gamma; /* Generally, the stage buffer is used to convert 32bit RGB, gray, and indexed images into 24 bit packed RGB. */ guchar *stage_buf; GdkRgbCmap *gray_cmap; gboolean dith_default; gboolean bitmap; /* set true if in 1 bit per pixel mode */ GdkGC *own_gc; /* Convert functions */ GdkRgbConvFunc conv; GdkRgbConvFunc conv_d; GdkRgbConvFunc conv_32; GdkRgbConvFunc conv_32_d; GdkRgbConvFunc conv_gray; GdkRgbConvFunc conv_gray_d; GdkRgbConvFunc conv_indexed; GdkRgbConvFunc conv_indexed_d;};static gboolean gdk_rgb_install_cmap = FALSE;static gint gdk_rgb_min_colors = 5 * 5 * 5;static gboolean gdk_rgb_verbose = FALSE;#define IMAGE_WIDTH 256#define STAGE_ROWSTRIDE (IMAGE_WIDTH * 3)#define IMAGE_HEIGHT 64#define N_IMAGES 6static GdkRgbInfo *image_info = NULL;static GdkImage *static_image[N_IMAGES];static gint static_image_idx;static guchar *colorcube;static guchar *colorcube_d;static gintgdk_rgb_cmap_fail (const char *msg, GdkColormap *cmap, gulong *pixels){ gulong free_pixels[256]; gint n_free; gint i;#ifdef VERBOSE g_print ("%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) gdk_colors_free (cmap, free_pixels, n_free, 0); return 0;}static voidgdk_rgb_make_colorcube (gulong *pixels, gint nr, gint ng, gint nb){ guchar rt[16], gt[16], bt[16]; gint i; colorcube = g_new (guchar, 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 g_print ("%03x %02x %x %x %x\n", i, colorcube[i], rt[i >> 8], gt[(i >> 4) & 0x0f], bt[i & 0x0f]);#endif }}/* this is the colorcube suitable for dithering */static voidgdk_rgb_make_colorcube_d (gulong *pixels, gint nr, gint ng, gint nb){ gint r, g, b; gint i; colorcube_d = g_new (guchar, 512); for (i = 0; i < 512; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -