Permalink
Browse files

minor error handling in bmp.c

more complex fill combining types
  • Loading branch information...
1 parent 27d9683 commit efdc2568ee6be1b2922fd89f9d0d371ddcd7aec4 Tony Cook committed Sep 9, 2001
Showing with 1,202 additions and 126 deletions.
  1. +18 −2 Imager.pm
  2. +62 −1 Imager.xs
  3. +5 −1 MANIFEST
  4. +4 −0 bmp.c
  5. +97 −3 color.c
  6. +44 −12 draw.c
  7. +579 −47 fills.c
  8. +51 −31 filters.c
  9. +27 −3 image.h
  10. +2 −0 imagei.h
  11. +158 −15 lib/Imager/Fill.pm
  12. +84 −1 t/t15color.t
  13. +67 −6 t/t20fill.t
  14. +2 −2 t/t61filters.t
  15. +2 −2 testimg/gimpgrad
View
@@ -290,6 +290,21 @@ BEGIN {
random => 2,
circle => 3,
},
+ combine => {
+ none => 0,
+ normal => 1,
+ multiply => 2, mult => 2,
+ dissolve => 3,
+ add => 4,
+ subtract => 5, sub => 5,
+ diff => 6,
+ lighten => 7,
+ darken => 8,
+ hue => 9,
+ sat => 10,
+ value => 11,
+ color => 12,
+ },
},
defaults => { ftype => 0, repeat => 0, combine => 0,
super_sample => 0, ssample_param => 4,
@@ -2960,7 +2975,7 @@ source.
bumpmap bump elevation(0) lightx lighty st(2)
contrast intensity
conv coef
- fountain xa ya xb yb ftype(linear) repeat(none) combine(0)
+ fountain xa ya xb yb ftype(linear) repeat(none) combine(none)
super_sample(none) ssample_param(4) segments(see below)
gaussian stddev
gradgen xo yo colors dist
@@ -3080,7 +3095,8 @@ for a linear fill).
By default the fill simply overwrites the whole image (unless you have
parts of the range 0 through 1 that aren't covered by a segment), if
any segments of your fill have any transparency, you can set the
-I<combine> option to 1 to have the fill combined with the existing pixels.
+I<combine> option to 'normal' to have the fill combined with the
+existing pixels. See the description of I<combine> in L<Imager/Fill>.
If your fill has sharp edges, for example between steps if you use
repeat set to 'triangle', you may see some aliased or ragged edges.
View
@@ -543,7 +543,26 @@ ICL_rgba(cl)
PUSHs(sv_2mortal(newSVnv(cl->rgba.b)));
PUSHs(sv_2mortal(newSVnv(cl->rgba.a)));
-
+Imager::Color
+i_hsv_to_rgb(c)
+ Imager::Color c
+ CODE:
+ RETVAL = mymalloc(sizeof(i_color));
+ *RETVAL = *c;
+ i_hsv_to_rgb(RETVAL);
+ OUTPUT:
+ RETVAL
+
+Imager::Color
+i_rgb_to_hsv(c)
+ Imager::Color c
+ CODE:
+ RETVAL = mymalloc(sizeof(i_color));
+ *RETVAL = *c;
+ i_rgb_to_hsv(RETVAL);
+ OUTPUT:
+ RETVAL
+
MODULE = Imager PACKAGE = Imager::Color::Float PREFIX=ICLF_
@@ -586,6 +605,27 @@ ICLF_set_internal(cl,r,g,b,a)
EXTEND(SP, 1);
PUSHs(ST(0));
+Imager::Color::Float
+i_hsv_to_rgb(c)
+ Imager::Color::Float c
+ CODE:
+ RETVAL = mymalloc(sizeof(i_fcolor));
+ *RETVAL = *c;
+ i_hsv_to_rgbf(RETVAL);
+ OUTPUT:
+ RETVAL
+
+Imager::Color::Float
+i_rgb_to_hsv(c)
+ Imager::Color::Float c
+ CODE:
+ RETVAL = mymalloc(sizeof(i_fcolor));
+ *RETVAL = *c;
+ i_rgb_to_hsvf(RETVAL);
+ OUTPUT:
+ RETVAL
+
+
MODULE = Imager PACKAGE = Imager::ImgRaw PREFIX = IIM_
Imager::ImgRaw
@@ -3095,3 +3135,24 @@ i_new_fill_hatch(fg, bg, combine, hatch, cust_hatch, dx, dy)
OUTPUT:
RETVAL
+Imager::FillHandle
+i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy)
+ Imager::Color::Float fg
+ Imager::Color::Float bg
+ int combine
+ int hatch
+ int dx
+ int dy
+ PREINIT:
+ unsigned char *cust_hatch;
+ STRLEN len;
+ CODE:
+ if (SvOK(ST(4))) {
+ cust_hatch = SvPV(ST(4), len);
+ }
+ else
+ cust_hatch = NULL;
+ RETVAL = i_new_fill_hatchf(fg, bg, combine, hatch, cust_hatch, dx, dy);
+ OUTPUT:
+ RETVAL
+
View
@@ -4,7 +4,7 @@ Imager.xs
MANIFEST
README
Makefile.PL
-bmp.c
+bmp.c Reading and writing Windows BMP files
color.c Color translation and handling
conv.c
convert.c
@@ -55,6 +55,7 @@ lib/Imager/Color.pm
lib/Imager/Color/Float.pm
lib/Imager/Expr.pm
lib/Imager/Expr/Assem.pm
+lib/Imager/Fill.pm
lib/Imager/Font.pm
lib/Imager/Font/Type1.pm
lib/Imager/Font/Truetype.pm
@@ -78,6 +79,7 @@ t/t105gif.t
t/t106tiff.t
t/t107bmp.t
t/t15color.t
+t/t20fill.t Tests fills
t/t30t1font.t
t/t35ttfont.t
t/t36oofont.t
@@ -94,6 +96,8 @@ t/t60dyntest.t
t/t61filters.t
t/t65crop.t
t/t66paste.t
+t/t67convert.t
+t/t68map.t
t/t69rubthru.t
t/t70newgif.t
t/t75polyaa.t
View
4 bmp.c
@@ -142,6 +142,10 @@ i_readbmp_wiol(io_glue *ig) {
case 16:
im = read_direct_bmp(ig, xsize, ysize, bit_count, clr_used, compression);
break;
+
+ default:
+ i_push_errorf(0, "unknown bit count for BMP file (%d)", bit_count);
+ return NULL;
}
/* store the resolution */
View
100 color.c
@@ -1,4 +1,5 @@
#include "image.h"
+#include <math.h>
/*
=head1 NAME
@@ -19,6 +20,9 @@ A collection of utility functions for converting between color spaces.
#define EPSILON (1e-8)
+#define my_max(a, b) ((a) < (b) ? (b) : (a))
+#define my_min(a, b) ((a) > (b) ? (b) : (a))
+
/*
=item i_rgb2hsvf(&color)
@@ -33,8 +37,8 @@ void i_rgb_to_hsvf(i_fcolor *color) {
double temp;
double Cr, Cg, Cb;
- v = max(max(color->rgb.r, color->rgb.g), color->rgb.b);
- temp = min(min(color->rgb.r, color->rgb.g), color->rgb.b);
+ v = my_max(my_max(color->rgb.r, color->rgb.g), color->rgb.b);
+ temp = my_min(my_min(color->rgb.r, color->rgb.g), color->rgb.b);
if (v < EPSILON)
s = 0;
else
@@ -61,6 +65,47 @@ void i_rgb_to_hsvf(i_fcolor *color) {
}
/*
+=item i_rgb2hsv(&color)
+
+Converts the first 3 channels of color into hue, saturation and value.
+
+Each value is scaled into the range 0 to 255.
+
+=cut
+*/
+void i_rgb_to_hsv(i_color *color) {
+ double h, s, v;
+ double temp;
+ double Cr, Cg, Cb;
+
+ v = my_max(my_max(color->rgb.r, color->rgb.g), color->rgb.b);
+ temp = my_min(my_min(color->rgb.r, color->rgb.g), color->rgb.b);
+ if (v == 0)
+ s = 0;
+ else
+ s = (v-temp)*255/v;
+ if (s == 0)
+ h = 0;
+ else {
+ Cr = (v - color->rgb.r)/(v-temp);
+ Cg = (v - color->rgb.g)/(v-temp);
+ Cb = (v - color->rgb.b)/(v-temp);
+ if (color->rgb.r == v)
+ h = Cb - Cg;
+ else if (color->rgb.g == v)
+ h = 2 + Cr - Cb;
+ else if (color->rgb.b == v)
+ h = 4 + Cg - Cr;
+ h = h * 60.0;
+ if (h < 0)
+ h += 360;
+ }
+ color->channel[0] = h * 255 / 360.0;
+ color->channel[1] = s;
+ color->channel[2] = v;
+}
+
+/*
=item i_hsv_to_rgbf(&color)
Convert a HSV value to an RGB value, each value ranges from 0 to 1.
@@ -81,7 +126,7 @@ void i_hsv_to_rgbf(i_fcolor *color) {
int i;
double f, m, n, k;
h = fmod(h, 1.0) * 6;
- i = h;
+ i = floor(h);
f = h - i;
m = v * (1 - s);
n = v * (1 - s * f);
@@ -110,6 +155,55 @@ void i_hsv_to_rgbf(i_fcolor *color) {
}
/*
+=item i_hsv_to_rgb(&color)
+
+Convert a HSV value to an RGB value, each value ranges from 0 to 1.
+
+=cut
+*/
+
+void i_hsv_to_rgb(i_color *color) {
+ double h = color->channel[0];
+ double s = color->channel[1];
+ double v = color->channel[2];
+
+ if (color->channel[1] == 0) {
+ /* ignore h in this case */
+ color->rgb.r = color->rgb.g = color->rgb.b = v;
+ }
+ else {
+ int i;
+ double f, m, n, k;
+ h = h / 255.0 * 6;
+ i = h;
+ f = h - i;
+ m = v * (255 - s) / 255;
+ n = v * (255 - s * f) / 255;
+ k = v * (255 - s * (1 - f)) / 255;
+ switch (i) {
+ case 0:
+ color->rgb.r = v; color->rgb.g = k; color->rgb.b = m;
+ break;
+ case 1:
+ color->rgb.r = n; color->rgb.g = v; color->rgb.b = m;
+ break;
+ case 2:
+ color->rgb.r = m; color->rgb.g = v; color->rgb.b = k;
+ break;
+ case 3:
+ color->rgb.r = m; color->rgb.g = n; color->rgb.b = v;
+ break;
+ case 4:
+ color->rgb.r = k; color->rgb.g = m; color->rgb.b = v;
+ break;
+ case 5:
+ color->rgb.r = v; color->rgb.g = m; color->rgb.b = n;
+ break;
+ }
+ }
+}
+
+/*
=back
=head1 AUTHOR
Oops, something went wrong.

0 comments on commit efdc256

Please sign in to comment.