From 4fbc8764b4c147e545590055eeef85ba00531b96 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Fri, 3 Sep 2004 00:06:21 +0000 Subject: [PATCH] libgimpbase/Makefile.am libgimpbase/gimpchecks.[ch] added 2004-09-03 Sven Neumann * libgimpbase/Makefile.am * libgimpbase/gimpchecks.[ch] added gimp_checks_get_shades(). * app/base/temp-buf.c * app/display/gimpdisplayshell-render.c * libgimpwidgets/gimppreviewarea.c: use the new function instead of replicating these numbers in three different places. --- ChangeLog | 10 +++++ app/base/temp-buf.c | 39 ++++--------------- app/display/gimpdisplayshell-render.c | 27 +++++-------- devel-docs/ChangeLog | 7 ++++ devel-docs/libgimpbase/libgimpbase-docs.sgml | 1 + .../libgimpbase/libgimpbase-sections.txt | 5 +++ devel-docs/libgimpbase/tmpl/gimpchecks.sgml | 28 +++++++++++++ .../libgimpwidgets/tmpl/gimppreviewarea.sgml | 10 +++++ libgimpbase/Makefile.am | 3 ++ libgimpbase/gimpbase.def | 1 + libgimpbase/gimpbase.h | 1 + libgimpbase/gimpchecks.h | 29 ++++++++++++++ libgimpwidgets/gimppreviewarea.c | 24 +----------- 13 files changed, 114 insertions(+), 71 deletions(-) create mode 100644 devel-docs/libgimpbase/tmpl/gimpchecks.sgml create mode 100644 libgimpbase/gimpchecks.h diff --git a/ChangeLog b/ChangeLog index 10f77196c3..d8443f3e7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-09-03 Sven Neumann + + * libgimpbase/Makefile.am + * libgimpbase/gimpchecks.[ch] added gimp_checks_get_shades(). + + * app/base/temp-buf.c + * app/display/gimpdisplayshell-render.c + * libgimpwidgets/gimppreviewarea.c: use the new function instead + of replicating these numbers in three different places. + 2004-09-03 DindinX * plug-ins/gimpressionist/*.c: made the code much more readable by diff --git a/app/base/temp-buf.c b/app/base/temp-buf.c index 797bc8a13c..4ce49c15e2 100644 --- a/app/base/temp-buf.c +++ b/app/base/temp-buf.c @@ -244,8 +244,8 @@ temp_buf_new_check (gint width, guchar *data; guchar check_shift = 0; guchar check_mod = 0; - guchar fg_color = 0; - guchar bg_color = 0; + guchar check_light = 0; + guchar check_dark = 0; gint x, y; g_return_val_if_fail (width > 0 && height > 0, NULL); @@ -266,40 +266,15 @@ temp_buf_new_check (gint width, break; } - switch (check_type) - { - case GIMP_CHECK_TYPE_LIGHT_CHECKS: - fg_color = 204; - bg_color = 255; - break; - case GIMP_CHECK_TYPE_GRAY_CHECKS: - fg_color = 102; - bg_color = 153; - break; - case GIMP_CHECK_TYPE_DARK_CHECKS: - fg_color = 0; - bg_color = 51; - break; - case GIMP_CHECK_TYPE_WHITE_ONLY: - fg_color = 255; - bg_color = 255; - break; - case GIMP_CHECK_TYPE_GRAY_ONLY: - fg_color = 127; - bg_color = 127; - break; - case GIMP_CHECK_TYPE_BLACK_ONLY: - fg_color = 0; - bg_color = 0; - } + gimp_checks_get_shades (check_type, &check_light, &check_dark); newbuf = temp_buf_new (width, height, 3, 0, 0, NULL); data = temp_buf_data (newbuf); for (y = 0; y < height; y++) { - guchar dark = y >> check_shift; - guchar color = (dark & 0x1) ? bg_color : fg_color; + guchar check_dark = y >> check_shift; + guchar color = (check_dark & 0x1) ? check_light : check_dark; for (x = 0; x < width; x++) { @@ -309,8 +284,8 @@ temp_buf_new_check (gint width, if (((x + 1) & check_mod) == 0) { - dark += 1; - color = (dark & 0x1) ? bg_color : fg_color; + check_dark += 1; + color = (check_dark & 0x1) ? check_light : check_dark; } } } diff --git a/app/display/gimpdisplayshell-render.c b/app/display/gimpdisplayshell-render.c index 298027b39a..9b4ce0b392 100644 --- a/app/display/gimpdisplayshell-render.c +++ b/app/display/gimpdisplayshell-render.c @@ -23,6 +23,7 @@ #include +#include "libgimpbase/gimpbase.h" #include "libgimpwidgets/gimpwidgets.h" #include "display-types.h" @@ -88,16 +89,6 @@ static guint tile_shift = 0; static guint check_mod = 0; static guint check_shift = 0; -static const guchar check_combos[6][2] = -{ - { 204, 255 }, /* LIGHT_CHECKS */ - { 153, 102 }, /* GRAY_CHECKS */ - { 0, 51 }, /* DARK_CHECKS */ - { 255, 255 }, /* WHITE_ONLY */ - { 127, 127 }, /* GRAY_ONLY */ - { 0, 0 } /* BLACK_ONLY */ -}; - void render_init (Gimp *gimp) @@ -180,6 +171,7 @@ render_setup_notify (gpointer config, { GimpCheckType check_type; GimpCheckSize check_size; + guchar light, dark; gint i, j; g_object_get (config, @@ -206,16 +198,17 @@ render_setup_notify (gpointer config, if (! render_blend_white) render_blend_white = g_new (guchar, 65536); + gimp_checks_get_shades (check_type, &light, &dark); + for (i = 0; i < 256; i++) for (j = 0; j < 256; j++) { - render_blend_dark_check [(i << 8) + j] = (guchar) - ((j * i + check_combos[check_type][0] * (255 - i)) / 255); - render_blend_light_check [(i << 8) + j] = (guchar) - ((j * i + check_combos[check_type][1] * (255 - i)) / 255); - - render_blend_white [(i << 8) + j] = (guchar) - ((j * i + 255 * (255 - i)) / 255); + render_blend_dark_check [(i << 8) + j] = + (guchar) ((j * i + dark * (255 - i)) / 255); + render_blend_light_check [(i << 8) + j] = + (guchar) ((j * i + light * (255 - i)) / 255); + render_blend_white [(i << 8) + j] = + (guchar) ((j * i + 255 * (255 - i)) / 255); } switch (check_size) diff --git a/devel-docs/ChangeLog b/devel-docs/ChangeLog index 20973341fc..aca3068a5e 100644 --- a/devel-docs/ChangeLog +++ b/devel-docs/ChangeLog @@ -1,3 +1,10 @@ +2004-09-03 Sven Neumann + + * libgimpbase/libgimpbase-docs.sgml + * libgimpbase/libgimpbase-sections.txt + * libgimpbase/tmpl/gimpchecks.sgml + * libgimpwidgets/tmpl/gimppreviewarea.sgml: updated. + 2004-09-02 Sven Neumann * libgimpbase/libgimpbase-sections.txt diff --git a/devel-docs/libgimpbase/libgimpbase-docs.sgml b/devel-docs/libgimpbase/libgimpbase-docs.sgml index 7b035e78f8..30722f00a6 100644 --- a/devel-docs/libgimpbase/libgimpbase-docs.sgml +++ b/devel-docs/libgimpbase/libgimpbase-docs.sgml @@ -17,6 +17,7 @@ + diff --git a/devel-docs/libgimpbase/libgimpbase-sections.txt b/devel-docs/libgimpbase/libgimpbase-sections.txt index 46698ba0a9..1b1465620a 100644 --- a/devel-docs/libgimpbase/libgimpbase-sections.txt +++ b/devel-docs/libgimpbase/libgimpbase-sections.txt @@ -27,6 +27,11 @@ GIMP_TYPE_IMAGE_TYPE gimp_image_type_get_type +
+gimpchecks +gimp_checks_get_shades +
+
gimpenv gimp_directory diff --git a/devel-docs/libgimpbase/tmpl/gimpchecks.sgml b/devel-docs/libgimpbase/tmpl/gimpchecks.sgml new file mode 100644 index 0000000000..150495c755 --- /dev/null +++ b/devel-docs/libgimpbase/tmpl/gimpchecks.sgml @@ -0,0 +1,28 @@ + +gimpchecks + + + + + + + + + + + + + + + + + + + + + +@type: +@light: +@dark: + + diff --git a/devel-docs/libgimpwidgets/tmpl/gimppreviewarea.sgml b/devel-docs/libgimpwidgets/tmpl/gimppreviewarea.sgml index 5a5bcd340a..7cb69ba89f 100644 --- a/devel-docs/libgimpwidgets/tmpl/gimppreviewarea.sgml +++ b/devel-docs/libgimpwidgets/tmpl/gimppreviewarea.sgml @@ -20,6 +20,16 @@ GimpPreviewArea + + + + + + + + + + diff --git a/libgimpbase/Makefile.am b/libgimpbase/Makefile.am index 400add2ad2..441d17b721 100644 --- a/libgimpbase/Makefile.am +++ b/libgimpbase/Makefile.am @@ -76,6 +76,8 @@ libgimpbase_sources = \ \ gimpbase-private.c \ gimpbase-private.h \ + gimpchecks.c \ + gimpchecks.h \ gimpdatafiles.c \ gimpdatafiles.h \ gimpenv.c \ @@ -111,6 +113,7 @@ libgimpbaseinclude_HEADERS = \ gimplimits.h \ gimpversion.h \ \ + gimpchecks.h \ gimpdatafiles.h \ gimpenv.h \ gimpmemsize.h \ diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def index 32d6340301..f8e837bff6 100644 --- a/libgimpbase/gimpbase.def +++ b/libgimpbase/gimpbase.def @@ -2,6 +2,7 @@ EXPORTS _gp_params_destroy gimp_any_to_utf8 gimp_base_init + gimp_checks_get_shades gimp_check_size_get_type gimp_check_type_get_type gimp_data_directory diff --git a/libgimpbase/gimpbase.h b/libgimpbase/gimpbase.h index 8011c67ef0..73807b4ed0 100644 --- a/libgimpbase/gimpbase.h +++ b/libgimpbase/gimpbase.h @@ -23,6 +23,7 @@ #include +#include #include #include #include diff --git a/libgimpbase/gimpchecks.h b/libgimpbase/gimpchecks.h new file mode 100644 index 0000000000..ae071b4bd0 --- /dev/null +++ b/libgimpbase/gimpchecks.h @@ -0,0 +1,29 @@ +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser 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 Lesser 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. + */ + +#ifndef __GIMP_CHECKS_H__ +#define __GIMP_CHECKS_H__ + + +void gimp_checks_get_shades (GimpCheckType type, + guchar *light, + guchar *dark); + + +#endif /* __GIMP_CHECKS_H__ */ diff --git a/libgimpwidgets/gimppreviewarea.c b/libgimpwidgets/gimppreviewarea.c index 3cd5523b39..05ada843cb 100644 --- a/libgimpwidgets/gimppreviewarea.c +++ b/libgimpwidgets/gimppreviewarea.c @@ -262,26 +262,6 @@ gimp_preview_area_get_check_size (GimpPreviewArea *area) return (1 << (2 + area->check_size)); } -static void -gimp_preview_area_get_check_colors (GimpPreviewArea *area, - guchar *light, - guchar *dark) -{ - GimpCheckType type = CLAMP (area->check_type, 0, 5); - - const guchar check_colors[6][2] = - { - { 204, 255 }, /* LIGHT_CHECKS */ - { 153, 102 }, /* GRAY_CHECKS */ - { 0, 51 }, /* DARK_CHECKS */ - { 255, 255 }, /* WHITE_ONLY */ - { 127, 127 }, /* GRAY_ONLY */ - { 0, 0 } /* BLACK_ONLY */ - }; - - *light = check_colors[type][0]; - *dark = check_colors[type][1]; -} /** @@ -391,8 +371,8 @@ gimp_preview_area_draw (GimpPreviewArea *area, area->buf = g_new (guchar, area->rowstride * area->height); } - size = gimp_preview_area_get_check_size (area); - gimp_preview_area_get_check_colors (area, &light, &dark); + size = 1 << (2 + area->check_size); + gimp_checks_get_shades (area->check_type, &light, &dark); #define CHECK_COLOR(area, row, col) \ (((((area)->offset_y + (row)) & size) ^ \