franz's patches to support other color spaces :)
SVN revision: 4745
This commit is contained in:
parent
60e02c7594
commit
fee04bcdde
1
AUTHORS
1
AUTHORS
|
@ -19,3 +19,4 @@ Masa(Masahiko) Mori <masa@engr.sgi.com>
|
|||
Term (Lyle Kempler) <term@kempler.net>
|
||||
Adam Kisiel <kisiel@if.pw.edu.pl>
|
||||
Carsten Pfeiffer <carpdjih@sp.zrz.tu-berlin.de>
|
||||
Franz Marini <marini@pcmenelao.mi.infn.it>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.72 [en] (X11; U; Linux 2.2.16-3ext3 i686) [Netscape]">
|
||||
<meta name="Author" content="The Rasterman">
|
||||
<meta name="Author" content="The Rasterman & Lightman">
|
||||
<title>Imlib 2 - Documentation.</title>
|
||||
</head>
|
||||
<body text="#000000" bgcolor="#FFFFFF" link="#0000EF" vlink="#51188E" alink="#FFFF00">
|
||||
|
@ -843,6 +843,32 @@ the text direction has been set to IMLIB_TEXT_TO_ANGLE with imlib_context_set_di
|
|||
drawn when being rendered onto an image. Values for red, green, blue and
|
||||
alpha are between 0 and 255 - any other values have undefined results.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_cmya(int cyan,
|
||||
int magenta,
|
||||
int yellow,
|
||||
int alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>This sets the color in CMYA space. Values for cyan, magenta,
|
||||
yellow and alpha are between 0 and 255 - any other values have undefined results.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_hsva(float hue,
|
||||
float saturation,
|
||||
float value,
|
||||
int alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>This sets the color in HSVA space. Values for hue are between 0 and 360,
|
||||
values for saturation and value between 0 and 1, and values for alpha are between 0
|
||||
and 255 - any other values have undefined results.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_hlsa(float hue,
|
||||
float lightness,
|
||||
float saturation,
|
||||
int alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>This sets the color in HLSA space. Values for hue are between 0 and 360,
|
||||
values for lightness and saturation between 0 and 1, and values for alpha are
|
||||
between 0 and 255 - any other values have undefined results.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_range(Imlib_Color_Range color_range);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>This sets the current color range to use for rendering gradients.</blockquote>
|
||||
|
@ -938,6 +964,21 @@ is IMLIB_TEXT_TO_ANGLE.</blockquote>
|
|||
<blockquote>Returns the current color for rendering text, rectangles and
|
||||
lines.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_context_get_color_cmya(int *cyan, int *magenta, int *yellow, int *alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>Returns the current color for rendering text, rectangles and
|
||||
lines in CMYA space.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_context_get_color_hsva(float *hue, float *saturation, float *value, int *alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>Returns the current color for rendering text, rectangles and
|
||||
lines in HSVA space.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_context_get_color_hlsa(float *hue, float * lightness, float *saturation, int *alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>Returns the current color for rendering text, rectangles and
|
||||
lines in HLSA space.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>Imlib_Color *imlib_context_get_imlib_color(void);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>Returns the current color as a color struct. Do NOT free this
|
||||
|
@ -1762,6 +1803,17 @@ specified in the current image with a linear gradient of the current color
|
|||
range at an angle of angle degrees with 0 degrees being vertical from top
|
||||
to bottom going clockwise from there.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_image_fill_hsva_color_range_rectangle(int x,
|
||||
int y,
|
||||
int width,
|
||||
int height,
|
||||
double angle);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>This fills a rectangle of width and height at the x, y location
|
||||
specified in the current image with a linear gradient in HSVA color space of
|
||||
the current color range at an angle of angle degrees with 0 degrees being
|
||||
vertical from top to bottom going clockwise from there.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_image_query_pixel(int x,
|
||||
int y,
|
||||
Imlib_Color *color_return);</font></font></tt></b></pre>
|
||||
|
@ -1769,6 +1821,36 @@ to bottom going clockwise from there.</blockquote>
|
|||
<blockquote>This fills the color_return color structure with the color
|
||||
of the pixel in the current image that is at the x, y location specified.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_image_query_pixel_cmya(int x,
|
||||
int y,
|
||||
int *cyan,
|
||||
int *magenta,
|
||||
int *yellow,
|
||||
int *alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>This returns the CMYA color of the pixel in the current image
|
||||
that is at the x, y location specified.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_image_query_pixel_hsva(int x,
|
||||
int y,
|
||||
float *hue,
|
||||
float *saturation,
|
||||
float *value,
|
||||
int *alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>This returns the HSVA color of the pixel in the current image
|
||||
that is at the x, y location specified.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_image_query_pixel_hlsa(int x,
|
||||
int y,
|
||||
float *hue,
|
||||
float *lightness,
|
||||
float *saturation,
|
||||
int *alpha);</font></font></tt></b></pre>
|
||||
|
||||
<blockquote>This returns the HLSA color of the pixel in the current image
|
||||
that is at the x, y location specified.</blockquote>
|
||||
|
||||
<pre><b><tt><font color="#660000"><font size=+2>void imlib_image_attach_data_value(const char *key,
|
||||
void *data,
|
||||
int value,
|
||||
|
|
12
src/Imlib2.h
12
src/Imlib2.h
|
@ -120,6 +120,9 @@ extern "C"
|
|||
void imlib_context_set_direction(Imlib_Text_Direction direction);
|
||||
void imlib_context_set_angle(double angle);
|
||||
void imlib_context_set_color(int red, int green, int blue, int alpha);
|
||||
void imlib_context_set_color_hsva(float hue, float saturation, float value, int alpha);
|
||||
void imlib_context_set_color_hlsa(float hue, float lightness, float saturation, int alpha);
|
||||
void imlib_context_set_color_cmya(int cyan, int magenta, int yellow, int alpha);
|
||||
void imlib_context_set_color_range(Imlib_Color_Range color_range);
|
||||
void imlib_context_set_progress_function(Imlib_Progress_Function
|
||||
progress_function);
|
||||
|
@ -146,6 +149,9 @@ extern "C"
|
|||
double imlib_context_get_angle(void);
|
||||
Imlib_Text_Direction imlib_context_get_direction(void);
|
||||
void imlib_context_get_color(int *red, int *green, int *blue, int *alpha);
|
||||
void imlib_context_get_color_hsva(float *hue, float *saturation, float *value, int *alpha);
|
||||
void imlib_context_get_color_hlsa(float *hue, float *lightness, float *saturation, int *alpha);
|
||||
void imlib_context_get_color_cmya(int *cyan, int *magenta, int *yellow, int *alpha);
|
||||
Imlib_Color *imlib_context_get_imlib_color(void);
|
||||
Imlib_Color_Range imlib_context_get_color_range(void);
|
||||
Imlib_Progress_Function imlib_context_get_progress_function(void);
|
||||
|
@ -193,7 +199,9 @@ extern "C"
|
|||
char *imlib_image_format(void);
|
||||
void imlib_image_set_has_alpha(char has_alpha);
|
||||
void imlib_image_query_pixel(int x, int y, Imlib_Color * color_return);
|
||||
|
||||
void imlib_image_query_pixel_hsva(int x, int y, float *hue, float *saturation, float *value, int *alpha);
|
||||
void imlib_image_query_pixel_hlsa(int x, int y, float *hue, float *lightness, float *saturation, int *alpha);
|
||||
void imlib_image_query_pixel_cmya(int x, int y, int *cyan, int *magenta, int *yellow, int *alpha);
|
||||
|
||||
/* rendering functions */
|
||||
#ifndef X_DISPLAY_MISSING
|
||||
|
@ -386,6 +394,8 @@ extern "C"
|
|||
void imlib_add_color_to_color_range(int distance_away);
|
||||
void imlib_image_fill_color_range_rectangle(int x, int y, int width,
|
||||
int height, double angle);
|
||||
void imlib_image_fill_hsva_color_range_rectangle(int x, int y, int width,
|
||||
int height, double angle);
|
||||
|
||||
/* image data */
|
||||
void imlib_image_attach_data_value(const char *key, void *data, int value,
|
||||
|
|
|
@ -18,10 +18,11 @@ lib_LTLIBRARIES = libImlib2.la
|
|||
include_HEADERS = Imlib2.h
|
||||
libImlib2_la_SOURCES = scale.c image.c blend.c file.c rgbadraw.c api.c \
|
||||
updates.c colormod.c font.c format.c grad.c rotate.c \
|
||||
filter.c script.c dynamic_filters.c \
|
||||
filter.c script.c dynamic_filters.c color_helpers.c \
|
||||
Imlib2.h image.h scale.h blend.h updates.h colormod.h \
|
||||
file.h common.h rgbadraw.h font.h format.h \
|
||||
rotate.h grad.h filter.h script.h dynamic_filters.h
|
||||
rotate.h grad.h filter.h script.h dynamic_filters.h \
|
||||
color_helpers.h
|
||||
|
||||
EXTRA_libImlib2_la_SOURCES = rend.c ximage.c rgba.c color.c grab.c draw.c \
|
||||
context.c color.h context.h draw.h grab.h rend.h \
|
||||
|
|
175
src/api.c
175
src/api.c
|
@ -36,6 +36,7 @@
|
|||
#include "dynamic_filters.h"
|
||||
#include "script.h"
|
||||
#include <math.h>
|
||||
#include "color_helpers.h"
|
||||
|
||||
/* convenience macros */
|
||||
#define CAST_IMAGE(im, image) (im) = (ImlibImage *)(image)
|
||||
|
@ -498,6 +499,63 @@ imlib_context_get_imlib_color(void)
|
|||
return &ctx->color;
|
||||
}
|
||||
|
||||
void
|
||||
imlib_context_set_color_hsva(float hue, float saturation, float value, int alpha)
|
||||
{
|
||||
int r,g,b;
|
||||
|
||||
__imlib_hsv_to_rgb(hue, saturation, value, &r, &g, &b);
|
||||
imlib_context_set_color(r, g, b, alpha);
|
||||
}
|
||||
|
||||
void
|
||||
imlib_context_get_color_hsva(float *hue, float *saturation, float *value, int *alpha)
|
||||
{
|
||||
int r,g,b,f;
|
||||
float i,j,k,max,min,d;
|
||||
|
||||
imlib_context_get_color(&r, &g, &b, alpha);
|
||||
__imlib_rgb_to_hsv(r, g, b, hue, saturation, value);
|
||||
}
|
||||
|
||||
void
|
||||
imlib_context_set_color_hlsa(float hue, float lightness, float saturation, int alpha)
|
||||
{
|
||||
int r,g,b;
|
||||
|
||||
__imlib_hls_to_rgb(hue, lightness, saturation, &r, &g, &b);
|
||||
imlib_context_set_color(r, g, b, alpha);
|
||||
}
|
||||
|
||||
void
|
||||
imlib_context_get_color_hlsa(float *hue, float *lightness, float *saturation, int *alpha)
|
||||
{
|
||||
int r,g,b;
|
||||
|
||||
imlib_context_get_color(&r, &g, &b, alpha);
|
||||
__imlib_rgb_to_hls(r, g, b, hue, lightness, saturation);
|
||||
}
|
||||
|
||||
void
|
||||
imlib_context_set_color_cmya(int cyan, int magenta, int yellow, int alpha)
|
||||
{
|
||||
if (!ctx) ctx = imlib_context_new();
|
||||
ctx->color.red = 255 - cyan;
|
||||
ctx->color.green = 255 - magenta;
|
||||
ctx->color.blue = 255 - yellow;
|
||||
ctx->color.alpha = alpha;
|
||||
}
|
||||
|
||||
void
|
||||
imlib_context_get_color_cmya(int *cyan, int *magenta, int *yellow, int *alpha)
|
||||
{
|
||||
if (!ctx) ctx = imlib_context_new();
|
||||
*cyan = 255 - ctx->color.red;
|
||||
*magenta = 255 - ctx->color.green;
|
||||
*yellow = 255 - ctx->color.blue;
|
||||
*alpha = ctx->color.alpha;
|
||||
}
|
||||
|
||||
void
|
||||
imlib_context_set_color_range(Imlib_Color_Range color_range)
|
||||
{
|
||||
|
@ -3440,6 +3498,31 @@ imlib_image_fill_color_range_rectangle(int x, int y, int width, int height,
|
|||
ctx->cliprect.w, ctx->cliprect.h);
|
||||
}
|
||||
|
||||
void
|
||||
imlib_image_fill_hsva_color_range_rectangle(int x, int y, int width, int height,
|
||||
double angle)
|
||||
{
|
||||
ImlibImage *im;
|
||||
|
||||
if (!ctx) ctx = imlib_context_new();
|
||||
CHECK_PARAM_POINTER("imlib_image_fill_color_range_rectangle", "image",
|
||||
ctx->image);
|
||||
CHECK_PARAM_POINTER("imlib_image_fill_color_range_rectangle",
|
||||
"color_range", ctx->color_range);
|
||||
CAST_IMAGE(im, ctx->image);
|
||||
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||
im->loader->load(im, NULL, 0, 1);
|
||||
if (!(im->data))
|
||||
return;
|
||||
__imlib_DirtyImage(im);
|
||||
__imlib_DirtyPixmapsForImage(im);
|
||||
__imlib_DrawHsvaGradient(im, x, y, width, height,
|
||||
(ImlibRange *) ctx->color_range, angle,
|
||||
ctx->operation,
|
||||
ctx->cliprect.x, ctx->cliprect.y,
|
||||
ctx->cliprect.w, ctx->cliprect.h);
|
||||
}
|
||||
|
||||
void
|
||||
imlib_image_query_pixel(int x, int y, Imlib_Color * color_return)
|
||||
{
|
||||
|
@ -3470,6 +3553,98 @@ imlib_image_query_pixel(int x, int y, Imlib_Color * color_return)
|
|||
color_return->alpha = ((*p) >> 24) & 0xff;
|
||||
}
|
||||
|
||||
void
|
||||
imlib_image_query_pixel_hsva(int x, int y, float *hue, float *saturation, float *value, int *alpha)
|
||||
{
|
||||
ImlibImage *im;
|
||||
DATA32 *p;
|
||||
int r,g,b,f;
|
||||
float i,j,k,max,min,d;
|
||||
|
||||
if (!ctx) ctx = imlib_context_new();
|
||||
CHECK_PARAM_POINTER("imlib_image_query_pixel", "image", ctx->image);
|
||||
CAST_IMAGE(im, ctx->image);
|
||||
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||
im->loader->load(im, NULL, 0, 1);
|
||||
if (!(im->data))
|
||||
return;
|
||||
if ((x < 0) || (x >= im->w) || (y < 0) || (y >= im->h))
|
||||
{
|
||||
*hue = 0;
|
||||
*saturation = 0;
|
||||
*value = 0;
|
||||
*alpha = 0;
|
||||
return;
|
||||
}
|
||||
p = im->data + (im->w * y) + x;
|
||||
r = ((*p) >> 16) & 0xff;
|
||||
g = ((*p) >> 8) & 0xff;
|
||||
b = (*p) & 0xff;
|
||||
*alpha = ((*p) >> 24) & 0xff;
|
||||
|
||||
__imlib_rgb_to_hsv(r, g, b, hue, saturation, value);
|
||||
}
|
||||
|
||||
void
|
||||
imlib_image_query_pixel_hlsa(int x, int y, float *hue, float *lightness, float *saturation, int *alpha)
|
||||
{
|
||||
ImlibImage *im;
|
||||
DATA32 *p;
|
||||
int r,g,b,f;
|
||||
float i,j,k,max,min,d;
|
||||
|
||||
if (!ctx) ctx = imlib_context_new();
|
||||
CHECK_PARAM_POINTER("imlib_image_query_pixel", "image", ctx->image);
|
||||
CAST_IMAGE(im, ctx->image);
|
||||
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||
im->loader->load(im, NULL, 0, 1);
|
||||
if (!(im->data))
|
||||
return;
|
||||
if ((x < 0) || (x >= im->w) || (y < 0) || (y >= im->h))
|
||||
{
|
||||
*hue = 0;
|
||||
*lightness = 0;
|
||||
*saturation = 0;
|
||||
*alpha = 0;
|
||||
return;
|
||||
}
|
||||
p = im->data + (im->w * y) + x;
|
||||
r = ((*p) >> 16) & 0xff;
|
||||
g = ((*p) >> 8) & 0xff;
|
||||
b = (*p) & 0xff;
|
||||
*alpha = ((*p) >> 24) & 0xff;
|
||||
|
||||
__imlib_rgb_to_hls(r, g, b, hue, lightness, saturation);
|
||||
}
|
||||
|
||||
void
|
||||
imlib_image_query_pixel_cmya(int x, int y, int *cyan, int *magenta, int *yellow, int *alpha)
|
||||
{
|
||||
ImlibImage *im;
|
||||
DATA32 *p;
|
||||
|
||||
if (!ctx) ctx = imlib_context_new();
|
||||
CHECK_PARAM_POINTER("imlib_image_query_pixel", "image", ctx->image);
|
||||
CAST_IMAGE(im, ctx->image);
|
||||
if ((!(im->data)) && (im->loader) && (im->loader->load))
|
||||
im->loader->load(im, NULL, 0, 1);
|
||||
if (!(im->data))
|
||||
return;
|
||||
if ((x < 0) || (x >= im->w) || (y < 0) || (y >= im->h))
|
||||
{
|
||||
*cyan = 0;
|
||||
*magenta = 0;
|
||||
*yellow = 0;
|
||||
*alpha = 0;
|
||||
return;
|
||||
}
|
||||
p = im->data + (im->w * y) + x;
|
||||
*cyan = 255 - (((*p) >> 16) & 0xff);
|
||||
*magenta = 255 - (((*p) >> 8) & 0xff);
|
||||
*yellow = 255 - ((*p) & 0xff);
|
||||
*alpha = ((*p) >> 24) & 0xff;
|
||||
}
|
||||
|
||||
void
|
||||
imlib_image_attach_data_value(const char *key, void *data, int value,
|
||||
Imlib_Internal_Data_Destructor_Function
|
||||
|
|
271
src/grad.c
271
src/grad.c
|
@ -6,6 +6,7 @@
|
|||
#include "image.h"
|
||||
#include "blend.h"
|
||||
#include "grad.h"
|
||||
#include "color_helpers.h"
|
||||
|
||||
ImlibRange *
|
||||
__imlib_CreateRange(void)
|
||||
|
@ -141,6 +142,87 @@ __imlib_MapRange(ImlibRange *rg, int len)
|
|||
return map;
|
||||
}
|
||||
|
||||
DATA32 *
|
||||
__imlib_MapHsvaRange(ImlibRange *rg, int len)
|
||||
{
|
||||
ImlibRangeColor *p;
|
||||
DATA32 *map, *pmap, k, kk;
|
||||
int r, g, b, a, rr, gg, bb, aa, i, l, ll, inc, j;
|
||||
float h1, s1, v1, h2, s2, v2, h, s, v, k1, k2;
|
||||
|
||||
if (!rg->color)
|
||||
return NULL;
|
||||
if (!rg->color->next)
|
||||
return NULL;
|
||||
ll = 1;
|
||||
for (p = rg->color; p; p = p->next)
|
||||
ll += p->distance;
|
||||
map = malloc(len * sizeof(DATA32));
|
||||
pmap = malloc(ll * sizeof(DATA32));
|
||||
i = 0;
|
||||
for (p = rg->color; p; p = p->next)
|
||||
{
|
||||
if (p->next)
|
||||
{
|
||||
for (j = 0; j < p->distance; j++)
|
||||
{
|
||||
k1 = (j << 16) / (float)p->distance;
|
||||
k2 = 65536 - k1;
|
||||
r = p->red; rr = p->next->red;
|
||||
g = p->green; gg = p->next->green;
|
||||
b = p->blue; bb = p->next->blue;
|
||||
__imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1);
|
||||
__imlib_rgb_to_hsv(rr, gg, bb, &h2, &s2, &v2);
|
||||
h = ((h1 * k2) + (h2 * k1)) / 65536.0;
|
||||
s = ((s1 * k2) + (s2 * k1)) / 65536.0;
|
||||
v = ((v1 * k2) + (v2 * k1)) / 65536.0;
|
||||
__imlib_hsv_to_rgb(h, s, v, &r, &g, &b);
|
||||
a = (unsigned long int)((p->alpha * k2) + (p->next->alpha * k1)) >> 16;
|
||||
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
r = p->red;
|
||||
g = p->green;
|
||||
b = p->blue;
|
||||
a = p->alpha;
|
||||
pmap[i++] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
}
|
||||
inc = ((ll - 1) << 16) / (len);
|
||||
l = 0;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
k = pmap[l >> 16];
|
||||
if ((l >> 16) < ll)
|
||||
kk = pmap[(l >> 16) + 1];
|
||||
else
|
||||
kk = pmap[(l >> 16)];
|
||||
k1 = l - (float)((l >> 16) << 16);
|
||||
k2 = 65536 - k1;
|
||||
b = ((k) ) & 0xff;
|
||||
g = ((k) >> 8 ) & 0xff;
|
||||
r = ((k) >> 16) & 0xff;
|
||||
a = ((k) >> 24) & 0xff;
|
||||
bb = ((kk) ) & 0xff;
|
||||
gg = ((kk) >> 8 ) & 0xff;
|
||||
rr = ((kk) >> 16) & 0xff;
|
||||
aa = ((kk) >> 24) & 0xff;
|
||||
__imlib_rgb_to_hsv(r, g, b, &h1, &s1, &v1);
|
||||
__imlib_rgb_to_hsv(rr, gg, bb, &h2, &s2, &v2);
|
||||
h = ((h1 * k2) + (h2 * k1)) / 65536.0;
|
||||
s = ((s1 * k2) + (s2 * k1)) / 65536.0;
|
||||
v = ((v1 * k2) + (v2 * k1)) / 65536.0;
|
||||
__imlib_hsv_to_rgb(h, s, v, &r, &g, &b);
|
||||
a = (unsigned long int)((a * k2) + (aa * k1)) >> 16;
|
||||
map[i] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
l += inc;
|
||||
}
|
||||
free(pmap);
|
||||
return map;
|
||||
}
|
||||
|
||||
void
|
||||
__imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h,
|
||||
ImlibRange *rg, double angle, ImlibOp op,
|
||||
|
@ -328,3 +410,192 @@ __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h,
|
|||
free(hlut);
|
||||
free(map);
|
||||
}
|
||||
|
||||
void
|
||||
__imlib_DrawHsvaGradient(ImlibImage *im, int x, int y, int w, int h,
|
||||
ImlibRange *rg, double angle, ImlibOp op,
|
||||
int clx, int cly, int clw, int clh)
|
||||
{
|
||||
DATA32 *map, *p, v;
|
||||
int *hlut, *vlut, len = 0, xx, yy, xoff = 0, yoff = 0, ww, hh, jump;
|
||||
int tmp, i, divw, divh;
|
||||
DATA8 rr, gg, bb, aa, r, g, b, a, nr, ng, nb, na;
|
||||
|
||||
ww = w;
|
||||
hh = h;
|
||||
if (x < 0)
|
||||
{
|
||||
w += x;
|
||||
xoff = -x;
|
||||
x = 0;
|
||||
}
|
||||
if (w <= 0)
|
||||
return;
|
||||
if ((x + w) > im->w)
|
||||
w = (im->w - x);
|
||||
if (w <= 0)
|
||||
return;
|
||||
if (y < 0)
|
||||
{
|
||||
h += y;
|
||||
yoff = -y;
|
||||
y = 0;
|
||||
}
|
||||
if (h <= 0)
|
||||
return;
|
||||
if ((y + h) > im->h)
|
||||
h = (im->h - y);
|
||||
if (h <= 0)
|
||||
return;
|
||||
if (clw)
|
||||
{
|
||||
int px, py;
|
||||
|
||||
CLIP_TO(clx, cly, clw, clh, 0, 0, im->w, im->h);
|
||||
px = x;
|
||||
py = y;
|
||||
CLIP_TO(x, y, w, h, clx, cly, clw, clh);
|
||||
if ((w < 1) || (h < 1)) return;
|
||||
xoff += (x - px);
|
||||
yoff += (y - py);
|
||||
}
|
||||
|
||||
hlut = malloc(sizeof(int) * ww);
|
||||
vlut = malloc(sizeof(int) * hh);
|
||||
if (ww > hh)
|
||||
len = ww * 16;
|
||||
else
|
||||
len = hh * 16;
|
||||
map = __imlib_MapHsvaRange(rg, len);
|
||||
if (!map) return;
|
||||
|
||||
xx = (int)(32 * sin(((angle + 180) * 2 * 3.141592654) / 360));
|
||||
yy = -(int)(32 * cos(((angle + 180) * 2 * 3.141592654) / 360));
|
||||
divw = ((ww - 1) << 5);
|
||||
divh = ((hh - 1) << 5);
|
||||
if (divw < 1) divw = 1;
|
||||
if (divh < 1) divh = 1;
|
||||
if (xx < 0)
|
||||
{
|
||||
for (i = 0; i < ww; i++)
|
||||
hlut[i] = (-xx * (ww - 1 - i) * len) / divw;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < ww; i++)
|
||||
hlut[i] = (xx * i * len) / divw;
|
||||
}
|
||||
if (yy < 0)
|
||||
{
|
||||
for (i = 0; i < hh; i++)
|
||||
vlut[i] = (-yy * (hh - 1 - i) * len) / divh;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < hh; i++)
|
||||
vlut[i] = (yy * i * len) / divh;
|
||||
}
|
||||
jump = im->w - w;
|
||||
|
||||
p = im->data + (y * im->w) + x;
|
||||
switch (op)
|
||||
{
|
||||
case OP_COPY:
|
||||
if (IMAGE_HAS_ALPHA(im))
|
||||
{
|
||||
__imlib_build_pow_lut();
|
||||
for (yy = 0; yy < h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < w; xx++)
|
||||
{
|
||||
i = vlut[yoff + yy] + hlut[xoff + xx];
|
||||
if (i < 0)
|
||||
i = 0;
|
||||
else if (i >= len)
|
||||
i = len - 1;
|
||||
READ_RGBA(&(map[i]), r, g, b, a);
|
||||
BLEND_DST_ALPHA(r, g, b, a, p);
|
||||
p++;
|
||||
}
|
||||
p += jump;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (yy = 0; yy < h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < w; xx++)
|
||||
{
|
||||
i = vlut[yoff + yy] + hlut[xoff + xx];
|
||||
if (i < 0)
|
||||
i = 0;
|
||||
else if (i >= len)
|
||||
i = len - 1;
|
||||
READ_RGBA(&(map[i]), r, g, b, a);
|
||||
BLEND(r, g, b, a, p);
|
||||
p++;
|
||||
}
|
||||
p += jump;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OP_ADD:
|
||||
for (yy = 0; yy < h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < w; xx++)
|
||||
{
|
||||
i = vlut[yoff + yy] + hlut[xoff + xx];
|
||||
if (i < 0)
|
||||
i = 0;
|
||||
else if (i >= len)
|
||||
i = len - 1;
|
||||
READ_RGBA(&(map[i]), r, g, b, a);
|
||||
BLEND_SUB(r, g, b, a, p);
|
||||
p++;
|
||||
}
|
||||
p += jump;
|
||||
}
|
||||
break;
|
||||
case OP_SUBTRACT:
|
||||
for (yy = 0; yy < h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < w; xx++)
|
||||
{
|
||||
i = vlut[yoff + yy] + hlut[xoff + xx];
|
||||
if (i < 0)
|
||||
i = 0;
|
||||
else if (i >= len)
|
||||
i = len - 1;
|
||||
READ_RGBA(&(map[i]), r, g, b, a);
|
||||
BLEND_SUB(r, g, b, a, p);
|
||||
p++;
|
||||
}
|
||||
p += jump;
|
||||
}
|
||||
break;
|
||||
case OP_RESHADE:
|
||||
for (yy = 0; yy < h; yy++)
|
||||
{
|
||||
for (xx = 0; xx < w; xx++)
|
||||
{
|
||||
i = vlut[yoff + yy] + hlut[xoff + xx];
|
||||
if (i < 0)
|
||||
i = 0;
|
||||
else if (i >= len)
|
||||
i = len - 1;
|
||||
READ_RGBA(&(map[i]), r, g, b, a);
|
||||
BLEND_RE(r, g, b, a, p);
|
||||
p++;
|
||||
}
|
||||
p += jump;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
free(vlut);
|
||||
free(hlut);
|
||||
free(map);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ void __imlib_FreeRange(ImlibRange *rg);
|
|||
void __imlib_AddRangeColor(ImlibRange *rg, DATA8 r, DATA8 g, DATA8 b,
|
||||
DATA8 a, int dist);
|
||||
DATA32 *__imlib_MapRange(ImlibRange *rg, int len);
|
||||
DATA32 *__imlib_MapHsvaRange(ImlibRange *rg, int len);
|
||||
void __imlib_DrawGradient(ImlibImage *im, int x, int y, int w, int h, ImlibRange *rg, double angle, ImlibOp op, int clx, int cly, int clw, int clh);
|
||||
void __imlib_DrawHsvaGradient(ImlibImage *im, int x, int y, int w, int h, ImlibRange *rg, double angle, ImlibOp op, int clx, int cly, int clw, int clh);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,7 @@ INCLUDES = -I/usr/X11R6/include -I$(top_srcdir)/libltdl \
|
|||
-I. -I$(top_srcdir) -I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/loaders
|
||||
|
||||
bin_PROGRAMS = imlib2 bumpmaptest imlib2_test polytest
|
||||
bin_PROGRAMS = imlib2 bumpmaptest imlib2_test polytest color_spaces
|
||||
imlib2_SOURCES = main.c
|
||||
imlib2_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
|
||||
$(x_libs) -lttf -lImlib2 -lm
|
||||
|
@ -27,3 +27,8 @@ imlib2_test_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
|
|||
polytest_SOURCES = polytest.c
|
||||
polytest_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
|
||||
$(x_libs) -lttf -lImlib2 -lm
|
||||
|
||||
color_spaces_SOURCES = color_spaces.c
|
||||
color_spaces_LDADD = @DLLDFLAGS@ $(top_builddir)/libltdl/libltdlc.la \
|
||||
$(x_libs) -lttf -lImlib2 -lm
|
||||
|
||||
|
|
Loading…
Reference in New Issue