#define IMAGER_NO_CONTEXT
#include "imager.h"
#include "imageri.h"
+#include <assert.h>
/*
=head1 NAME
(C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
adjoining areas out of alignment, or to align the origin of a hatch
-with the the side of a filled area.
+with the side of a filled area.
=cut
*/
i_fill_t *
i_new_fill_hatch(const i_color *fg, const i_color *bg, int combine, int hatch,
const unsigned char *cust_hatch, i_img_dim dx, i_img_dim dy) {
+ assert(fg);
+ assert(bg);
return i_new_hatch_low(fg, bg, NULL, NULL, combine, hatch, cust_hatch,
dx, dy);
}
(C<dx>, C<dy>) are an offset into the hatch which can be used to hatch
adjoining areas out of alignment, or to align the origin of a hatch
-with the the side of a filled area.
+with the side of a filled area.
=cut
*/
i_fill_t *
i_new_fill_hatchf(const i_fcolor *fg, const i_fcolor *bg, int combine, int hatch,
const unsigned char *cust_hatch, i_img_dim dx, i_img_dim dy) {
+ assert(fg);
+ assert(bg);
return i_new_hatch_low(NULL, NULL, fg, bg, combine, hatch, cust_hatch,
dx, dy);
}
i_fill_hatch_t *fill = mymalloc(sizeof(i_fill_hatch_t)); /* checked 14jul05 tonyc */
*fill = hatch_fill_proto;
- /* Some Sun C didn't like the condition expressions that were here.
- See https://rt.cpan.org/Ticket/Display.html?id=21944
- */
- if (fg)
+ if (fg && bg) {
fill->fg = *fg;
- else
- fill->fg = fcolor_to_color(ffg);
- if (bg)
fill->bg = *bg;
- else
+ fill->ffg = color_to_fcolor(fg);
+ fill->fbg = color_to_fcolor(bg);
+ }
+ else if (ffg && fbg) {
+ fill->fg = fcolor_to_color(ffg);
fill->bg = fcolor_to_color(fbg);
- if (ffg)
fill->ffg = *ffg;
- else
- fill->ffg = color_to_fcolor(fg);
- if (fbg)
fill->fbg = *fbg;
- else
- fill->fbg = color_to_fcolor(bg);
+ }
+ else {
+ assert(0);
+ /* NOTREACHED */
+ }
+
if (combine) {
i_get_combine(combine, &fill->base.combine, &fill->base.combinef);
}
memcpy(fill->hatch, cust_hatch, 8);
}
else {
- if (hatch > sizeof(builtin_hatches)/sizeof(*builtin_hatches))
+ if (hatch >= sizeof(builtin_hatches)/sizeof(*builtin_hatches)
+ || hatch < 0) {
hatch = 0;
+ }
memcpy(fill->hatch, builtin_hatches[hatch], 8);
}
fill->dx = dx & 7;
The floating sample fill function for hatched fills.
-=back
+=cut
*/
static void
fill_hatchf(i_fill_t *fill, i_img_dim x, i_img_dim y, i_img_dim width,
pos -= floor(pos);
for (ch = 0; ch < channels; ++ch)
out.channel[ch] = (1-pos) * before.channel[ch] + pos * after.channel[ch];
- if (channels > 3 && out.channel[3])
- for (ch = 0; ch < channels; ++ch)
+ if (channels > 3 && out.channel[3]) {
+ for (ch = 0; ch < channels; ++ch) {
if (ch != 3) {
int temp = out.channel[ch] * 255 / out.channel[3];
if (temp > 255)
temp = 255;
out.channel[ch] = temp;
}
+ }
+ }
return out;
}
pos -= floor(pos);
for (ch = 0; ch < channels; ++ch)
out.channel[ch] = (1-pos) * before.channel[ch] + pos * after.channel[ch];
- if (out.channel[3])
- for (ch = 0; ch < channels; ++ch)
+ if (out.channel[3]) {
+ for (ch = 0; ch < channels; ++ch) {
if (ch != 3) {
int temp = out.channel[ch] / out.channel[3];
if (temp > 1.0)
temp = 1.0;
out.channel[ch] = temp;
}
+ }
+ }
return out;
}