1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-02 22:25:48 +01:00

changed indentation to use spaces only

This commit is contained in:
dan
2004-10-12 21:28:27 +00:00
parent 5912898b06
commit 6830b05716
240 changed files with 35951 additions and 35773 deletions

View File

@@ -1,6 +1,6 @@
/* $XConsortium: CmapAlloc.c,v 1.9 94/04/17 20:15:52 rws Exp $ */
/*
/*
Copyright (c) 1989, 1994 X Consortium
@@ -45,11 +45,11 @@ static int icbrt();
static int icbrt_with_bits();
static int icbrt_with_guess();
/* To determine the best allocation of reds, greens, and blues in a
/* To determine the best allocation of reds, greens, and blues in a
* standard colormap, use XmuGetColormapAllocation.
* vinfo specifies visual information for a chosen visual
* property specifies one of the standard colormap property names
* red_max returns maximum red value
* red_max returns maximum red value
* green_max returns maximum green value
* blue_max returns maximum blue value
*
@@ -65,33 +65,32 @@ Status XmuGetColormapAllocation(vinfo, property, red_max, green_max, blue_max)
Status status = 1;
if (vinfo->colormap_size <= 2)
return 0;
return 0;
switch (property)
{
case XA_RGB_DEFAULT_MAP:
status = default_allocation(vinfo, red_max, green_max, blue_max);
break;
case XA_RGB_BEST_MAP:
best_allocation(vinfo, red_max, green_max, blue_max);
break;
case XA_RGB_GRAY_MAP:
gray_allocation(vinfo->colormap_size, red_max, green_max, blue_max);
break;
case XA_RGB_RED_MAP:
*red_max = vinfo->colormap_size - 1;
*green_max = *blue_max = 0;
break;
case XA_RGB_GREEN_MAP:
*green_max = vinfo->colormap_size - 1;
*red_max = *blue_max = 0;
break;
case XA_RGB_BLUE_MAP:
*blue_max = vinfo->colormap_size - 1;
*red_max = *green_max = 0;
break;
default:
status = 0;
switch (property) {
case XA_RGB_DEFAULT_MAP:
status = default_allocation(vinfo, red_max, green_max, blue_max);
break;
case XA_RGB_BEST_MAP:
best_allocation(vinfo, red_max, green_max, blue_max);
break;
case XA_RGB_GRAY_MAP:
gray_allocation(vinfo->colormap_size, red_max, green_max, blue_max);
break;
case XA_RGB_RED_MAP:
*red_max = vinfo->colormap_size - 1;
*green_max = *blue_max = 0;
break;
case XA_RGB_GREEN_MAP:
*green_max = vinfo->colormap_size - 1;
*red_max = *blue_max = 0;
break;
case XA_RGB_BLUE_MAP:
*blue_max = vinfo->colormap_size - 1;
*red_max = *green_max = 0;
break;
default:
status = 0;
}
return status;
}
@@ -107,15 +106,15 @@ static void gray_allocation(n, red_max, green_max, blue_max)
unsigned long *red_max, *green_max, *blue_max;
{
*red_max = (n * 30) / 100;
*green_max = (n * 59) / 100;
*blue_max = (n * 11) / 100;
*green_max = (n * 59) / 100;
*blue_max = (n * 11) / 100;
*green_max += ((n - 1) - (*red_max + *green_max + *blue_max));
}
/****************************************************************************/
/* Determine an appropriate color allocation for the RGB_DEFAULT_MAP.
* If a map has less than a minimum number of definable entries, we do not
* produce an allocation for an RGB_DEFAULT_MAP.
* produce an allocation for an RGB_DEFAULT_MAP.
*
* For 16 planes, the default colormap will have 27 each RGB; for 12 planes,
* 12 each. For 8 planes, let n = the number of colormap entries, which may
@@ -133,51 +132,51 @@ static int default_allocation(vinfo, red, green, blue)
int ngrays; /* number of gray cells */
switch (vinfo->class) {
case PseudoColor:
case PseudoColor:
if (vinfo->colormap_size > 65000)
/* intended for displays with 16 planes */
*red = *green = *blue = (unsigned long) 27;
else if (vinfo->colormap_size > 4000)
/* intended for displays with 12 planes */
*red = *green = *blue = (unsigned long) 12;
else if (vinfo->colormap_size < 250)
return 0;
else
/* intended for displays with 8 planes */
*red = *green = *blue = (unsigned long)
(icbrt(vinfo->colormap_size - 125) - 1);
break;
if (vinfo->colormap_size > 65000)
/* intended for displays with 16 planes */
*red = *green = *blue = (unsigned long) 27;
else if (vinfo->colormap_size > 4000)
/* intended for displays with 12 planes */
*red = *green = *blue = (unsigned long) 12;
else if (vinfo->colormap_size < 250)
return 0;
else
/* intended for displays with 8 planes */
*red = *green = *blue = (unsigned long)
(icbrt(vinfo->colormap_size - 125) - 1);
break;
case DirectColor:
case DirectColor:
if (vinfo->colormap_size < 10)
return 0;
*red = *green = *blue = vinfo->colormap_size / 2 - 1;
break;
if (vinfo->colormap_size < 10)
return 0;
*red = *green = *blue = vinfo->colormap_size / 2 - 1;
break;
case TrueColor:
case TrueColor:
*red = vinfo->red_mask / lowbit(vinfo->red_mask);
*green = vinfo->green_mask / lowbit(vinfo->green_mask);
*blue = vinfo->blue_mask / lowbit(vinfo->blue_mask);
break;
*red = vinfo->red_mask / lowbit(vinfo->red_mask);
*green = vinfo->green_mask / lowbit(vinfo->green_mask);
*blue = vinfo->blue_mask / lowbit(vinfo->blue_mask);
break;
case GrayScale:
case GrayScale:
if (vinfo->colormap_size > 65000)
ngrays = 4096;
else if (vinfo->colormap_size > 4000)
ngrays = 512;
else if (vinfo->colormap_size < 250)
return 0;
else
ngrays = 12;
gray_allocation(ngrays, red, green, blue);
break;
default:
return 0;
if (vinfo->colormap_size > 65000)
ngrays = 4096;
else if (vinfo->colormap_size > 4000)
ngrays = 512;
else if (vinfo->colormap_size < 250)
return 0;
else
ngrays = 12;
gray_allocation(ngrays, red, green, blue);
break;
default:
return 0;
}
return 1;
}
@@ -199,65 +198,58 @@ static int default_allocation(vinfo, red, green, blue)
* Which, on a GPX, allows for 252 entries in the best map, out of 254
* defineable colormap entries.
*/
static void best_allocation(vinfo, red, green, blue)
XVisualInfo *vinfo;
unsigned long *red, *green, *blue;
{
if (vinfo->class == DirectColor || vinfo->class == TrueColor)
{
*red = vinfo->red_mask;
while ((*red & 01) == 0)
*red >>= 1;
*green = vinfo->green_mask;
while ((*green & 01) == 0)
*green >>=1;
*blue = vinfo->blue_mask;
while ((*blue & 01) == 0)
*blue >>= 1;
}
else
{
register int bits, n;
/* Determine n such that n is the least integral power of 2 which is
* greater than or equal to the number of entries in the colormap.
*/
n = 1;
bits = 0;
while (vinfo->colormap_size > n)
{
n = n << 1;
bits++;
}
/* If the number of entries in the colormap is a power of 2, determine
* the allocation by "dealing" the bits, first to green, then red, then
* blue. If not, find the maximum integral red, green, and blue values
* which, when multiplied together, do not exceed the number of
if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
*red = vinfo->red_mask;
while ((*red & 01) == 0)
*red >>= 1;
*green = vinfo->green_mask;
while ((*green & 01) == 0)
*green >>=1;
*blue = vinfo->blue_mask;
while ((*blue & 01) == 0)
*blue >>= 1;
} else {
register int bits, n;
* colormap entries.
*/
if (n == vinfo->colormap_size)
{
register int r, g, b;
b = bits / 3;
g = b + ((bits % 3) ? 1 : 0);
r = b + (((bits % 3) == 2) ? 1 : 0);
*red = 1 << r;
*green = 1 << g;
*blue = 1 << b;
}
else
{
*red = icbrt_with_bits(vinfo->colormap_size, bits);
*blue = *red;
*green = (vinfo->colormap_size / ((*red) * (*blue)));
}
(*red)--;
(*green)--;
(*blue)--;
/* Determine n such that n is the least integral power of 2 which is
* greater than or equal to the number of entries in the colormap.
*/
n = 1;
bits = 0;
while (vinfo->colormap_size > n) {
n = n << 1;
bits++;
}
/* If the number of entries in the colormap is a power of 2, determine
* the allocation by "dealing" the bits, first to green, then red, then
* blue. If not, find the maximum integral red, green, and blue values
* which, when multiplied together, do not exceed the number of
* colormap entries.
*/
if (n == vinfo->colormap_size) {
register int r, g, b;
b = bits / 3;
g = b + ((bits % 3) ? 1 : 0);
r = b + (((bits % 3) == 2) ? 1 : 0);
*red = 1 << r;
*green = 1 << g;
*blue = 1 << b;
} else {
*red = icbrt_with_bits(vinfo->colormap_size, bits);
*blue = *red;
*green = (vinfo->colormap_size / ((*red) * (*blue)));
}
(*red)--;
(*green)--;
(*blue)--;
}
return;
}
@@ -274,10 +266,9 @@ static int icbrt(a) /* integer cube root */
register int bits = 0;
register unsigned n = a;
while (n)
{
bits++;
n >>= 1;
while (n) {
bits++;
n >>= 1;
}
return icbrt_with_bits(a, bits);
}
@@ -313,23 +304,24 @@ static int icbrt_with_guess(a, guess)
icbrt_loopcount = 0;
#endif
if (a <= 0)
return 0;
return 0;
if (guess < 1)
guess = 1;
guess = 1;
do {
#ifdef DEBUG
icbrt_loopcount++;
icbrt_loopcount++;
#endif
delta = (guess - a/(guess*guess))/3;
delta = (guess - a/(guess*guess))/3;
#ifdef DEBUG
printf("pass %d: guess=%d, delta=%d\n", icbrt_loopcount, guess, delta);
printf("pass %d: guess=%d, delta=%d\n", icbrt_loopcount, guess, delta);
#endif
guess -= delta;
guess -= delta;
} while (delta != 0);
if (guess*guess*guess > a)
guess--;
guess--;
return guess;
}

View File

@@ -1,6 +1,6 @@
/* $XConsortium: CrCmap.c,v 1.6 94/04/17 20:15:53 rws Exp $ */
/*
/*
Copyright (c) 1989 X Consortium
@@ -53,7 +53,7 @@ static Status readwrite_map(); /* create a map in a RW visual type */
#define lowbit(x) ((x) & (~(x) + 1))
#define TRUEMATCH(mult,max,mask) \
(colormap->max * colormap->mult <= vinfo->mask && \
lowbit(vinfo->mask) == colormap->mult)
lowbit(vinfo->mask) == colormap->mult)
/*
* To create any one colormap which is described by an XStandardColormap
@@ -65,7 +65,7 @@ static Status readwrite_map(); /* create a map in a RW visual type */
*
* All colormaps are created with read only allocations, with the exception
* of read only allocations of colors in the default map or otherwise
* which fail to return the expected pixel value, and these are individually
* which fail to return the expected pixel value, and these are individually
* defined as read/write allocations. This is done so that all the cells
* defined in the default map are contiguous, for use in image processing.
* This typically happens with White and Black in the default map.
@@ -74,76 +74,76 @@ static Status readwrite_map(); /* create a map in a RW visual type */
* the map of the static visual matches the definition given in the
* standard colormap structure.
*/
Status XmuCreateColormap(dpy, colormap)
Display *dpy; /* specifies the connection under
* which the map is created */
Display *dpy; /* specifies the connection under
* which the map is created */
XStandardColormap *colormap; /* specifies the map to be created,
* and returns, particularly if the
* map is created as a subset of the
* default colormap of the screen,
* the base_pixel of the map.
*/
* and returns, particularly if the
* map is created as a subset of the
* default colormap of the screen,
* the base_pixel of the map.
*/
{
XVisualInfo vinfo_template; /* template visual information */
XVisualInfo *vinfo; /* matching visual information */
XVisualInfo *vpointer; /* for freeing the entire list */
long vinfo_mask; /* specifies the visual mask value */
int n; /* number of matching visuals */
int status;
int status;
vinfo_template.visualid = colormap->visualid;
vinfo_mask = VisualIDMask;
if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL)
return 0;
return 0;
/* A visual id may be valid on multiple screens. Also, there may
* be multiple visuals with identical visual ids at different depths.
/* A visual id may be valid on multiple screens. Also, there may
* be multiple visuals with identical visual ids at different depths.
* If the colormap is the Default Colormap, use the Default Visual.
* Otherwise, arbitrarily, use the deepest visual.
*/
vpointer = vinfo;
if (n > 1)
{
register int i;
register int screen_number;
Bool def_cmap;
register int i;
register int screen_number;
Bool def_cmap;
def_cmap = False;
for (screen_number = ScreenCount(dpy); --screen_number >= 0; )
if (colormap->colormap == DefaultColormap(dpy, screen_number)) {
def_cmap = True;
break;
}
def_cmap = False;
for (screen_number = ScreenCount(dpy); --screen_number >= 0; )
if (colormap->colormap == DefaultColormap(dpy, screen_number)) {
def_cmap = True;
break;
}
if (def_cmap) {
for (i=0; i < n; i++, vinfo++) {
if (vinfo->visual == DefaultVisual(dpy, screen_number))
break;
}
} else {
unsigned int maxdepth = 0;
XVisualInfo *v = vinfo;
if (def_cmap) {
for (i=0; i < n; i++, vinfo++) {
if (vinfo->visual == DefaultVisual(dpy, screen_number))
break;
}
} else {
unsigned int maxdepth = 0;
XVisualInfo *v = vinfo;
for (i=0; i < n; i++, vinfo++)
if (vinfo->depth > maxdepth) {
maxdepth = vinfo->depth;
v = vinfo;
}
vinfo = v;
}
for (i=0; i < n; i++, vinfo++)
if (vinfo->depth > maxdepth) {
maxdepth = vinfo->depth;
v = vinfo;
}
vinfo = v;
}
}
if (vinfo->class == PseudoColor || vinfo->class == DirectColor ||
vinfo->class == GrayScale)
status = readwrite_map(dpy, vinfo, colormap);
vinfo->class == GrayScale)
status = readwrite_map(dpy, vinfo, colormap);
else if (vinfo->class == TrueColor)
status = TRUEMATCH(red_mult, red_max, red_mask) &&
TRUEMATCH(green_mult, green_max, green_mask) &&
TRUEMATCH(blue_mult, blue_max, blue_mask);
else
status = readonly_map(dpy, vinfo, colormap);
status = TRUEMATCH(red_mult, red_max, red_mask) &&
TRUEMATCH(green_mult, green_max, green_mask) &&
TRUEMATCH(blue_mult, blue_max, blue_mask);
else
status = readonly_map(dpy, vinfo, colormap);
XFree((char *) vpointer);
return status;
}
@@ -163,39 +163,39 @@ static Status readwrite_map(dpy, vinfo, colormap)
unsigned long *pixels; /* array of colormap pixels */
unsigned long delta;
/* Determine ncolors, the number of colors to be defined.
* Insure that 1 < ncolors <= the colormap size.
*/
if (vinfo->class == DirectColor) {
ncolors = colormap->red_max;
if (colormap->green_max > ncolors)
ncolors = colormap->green_max;
if (colormap->blue_max > ncolors)
ncolors = colormap->blue_max;
ncolors++;
delta = lowbit(vinfo->red_mask) +
lowbit(vinfo->green_mask) +
lowbit(vinfo->blue_mask);
ncolors = colormap->red_max;
if (colormap->green_max > ncolors)
ncolors = colormap->green_max;
if (colormap->blue_max > ncolors)
ncolors = colormap->blue_max;
ncolors++;
delta = lowbit(vinfo->red_mask) +
lowbit(vinfo->green_mask) +
lowbit(vinfo->blue_mask);
} else {
ncolors = colormap->red_max * colormap->red_mult +
colormap->green_max * colormap->green_mult +
colormap->blue_max * colormap->blue_mult + 1;
delta = 1;
ncolors = colormap->red_max * colormap->red_mult +
colormap->green_max * colormap->green_mult +
colormap->blue_max * colormap->blue_mult + 1;
delta = 1;
}
if (ncolors <= 1 || ncolors > vinfo->colormap_size) return 0;
/* Allocate Read/Write as much of the colormap as we can possibly get.
* Then insure that the pixels we were allocated are given in
* Then insure that the pixels we were allocated are given in
* monotonically increasing order, using a quicksort. Next, insure
* that our allocation includes a subset of contiguous pixels at least
* as long as the number of colors to be defined. Now we know that
* as long as the number of colors to be defined. Now we know that
* these conditions are met:
* 1) There are no free cells in the colormap.
* 2) We have a contiguous sequence of pixels, monotonically
* 2) We have a contiguous sequence of pixels, monotonically
* increasing, of length >= the number of colors requested.
*
* One cell at a time, we will free, compute the next color value,
* One cell at a time, we will free, compute the next color value,
* then allocate read only. This takes a long time.
* This is done to insure that cells are allocated read only in the
* contiguous order which we prefer. If the server has a choice of
@@ -204,98 +204,98 @@ static Status readwrite_map(dpy, vinfo, colormap)
*/
if ((pixels = (unsigned long *) calloc((unsigned) vinfo->colormap_size,
sizeof(unsigned long))) == NULL)
return 0;
sizeof(unsigned long))) == NULL)
return 0;
if ((npixels = ROmap(dpy, colormap->colormap, pixels,
vinfo->colormap_size, ncolors)) == 0) {
free((char *) pixels);
return 0;
vinfo->colormap_size, ncolors)) == 0) {
free((char *) pixels);
return 0;
}
qsort((char *) pixels, npixels, sizeof(unsigned long), compare);
if (!contiguous(pixels, npixels, ncolors, delta, &first_index, &remainder))
{
/* can't find enough contiguous cells, give up */
XFreeColors(dpy, colormap->colormap, pixels, npixels,
(unsigned long) 0);
free((char *) pixels);
return 0;
/* can't find enough contiguous cells, give up */
XFreeColors(dpy, colormap->colormap, pixels, npixels,
(unsigned long) 0);
free((char *) pixels);
return 0;
}
colormap->base_pixel = pixels[first_index];
/* construct a gray map */
if (colormap->red_mult == 1 && colormap->green_mult == 1 &&
colormap->blue_mult == 1)
for (n=colormap->base_pixel, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n;
color.blue = color.green = color.red =
(unsigned short) ((i * 65535) / (colormap->red_max +
colormap->green_max +
colormap->blue_max));
colormap->blue_mult == 1)
for (n=colormap->base_pixel, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n;
color.blue = color.green = color.red =
(unsigned short) ((i * 65535) / (colormap->red_max +
colormap->green_max +
colormap->blue_max));
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
/* construct a red ramp map */
else if (colormap->green_max == 0 && colormap->blue_max == 0)
for (n=colormap->base_pixel, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n;
color.red = (unsigned short) ((i * 65535) / colormap->red_max);
color.green = color.blue = 0;
for (n=colormap->base_pixel, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n;
color.red = (unsigned short) ((i * 65535) / colormap->red_max);
color.green = color.blue = 0;
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
/* construct a green ramp map */
else if (colormap->red_max == 0 && colormap->blue_max == 0)
for (n=colormap->base_pixel, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n;
color.green = (unsigned short) ((i * 65535) / colormap->green_max);
color.red = color.blue = 0;
for (n=colormap->base_pixel, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n;
color.green = (unsigned short) ((i * 65535) / colormap->green_max);
color.red = color.blue = 0;
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
/* construct a blue ramp map */
else if (colormap->red_max == 0 && colormap->green_max == 0)
for (n=colormap->base_pixel, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n;
color.blue = (unsigned short) ((i * 65535) / colormap->blue_max);
color.red = color.green = 0;
for (n=colormap->base_pixel, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n;
color.blue = (unsigned short) ((i * 65535) / colormap->blue_max);
color.red = color.green = 0;
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
/* construct a standard red green blue cube map */
else
{
#define calc(max,mult) (((n / colormap->mult) % \
(colormap->max + 1)) * 65535) / colormap->max
(colormap->max + 1)) * 65535) / colormap->max
for (n=0, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n + colormap->base_pixel;
color.red = calc(red_max, red_mult);
color.green = calc(green_max, green_mult);
color.blue = calc(blue_max, blue_mult);
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
for (n=0, i=0; i < ncolors; i++, n += delta)
{
color.pixel = n + colormap->base_pixel;
color.red = calc(red_max, red_mult);
color.green = calc(green_max, green_mult);
color.blue = calc(blue_max, blue_mult);
if (! ROorRWcell(dpy, colormap->colormap, pixels, npixels, &color,
first_index + i))
return 0;
}
#undef calc
}
/* We have a read-only map defined. Now free unused cells,
@@ -304,12 +304,12 @@ static Status readwrite_map(dpy, vinfo, colormap)
*/
if (first_index)
XFreeColors(dpy, colormap->colormap, pixels, first_index,
(unsigned long) 0);
XFreeColors(dpy, colormap->colormap, pixels, first_index,
(unsigned long) 0);
if (remainder)
XFreeColors(dpy, colormap->colormap,
&(pixels[first_index + ncolors]), remainder,
(unsigned long) 0);
XFreeColors(dpy, colormap->colormap,
&(pixels[first_index + ncolors]), remainder,
(unsigned long) 0);
free((char *) pixels);
return 1;
@@ -327,64 +327,64 @@ static int ROmap(dpy, cmap, pixels, m, n)
register int p;
/* first try to allocate the entire colormap */
if (XAllocColorCells(dpy, cmap, 1, (unsigned long *) NULL,
(unsigned) 0, pixels, (unsigned) m))
return m;
if (XAllocColorCells(dpy, cmap, 1, (unsigned long *) NULL,
(unsigned) 0, pixels, (unsigned) m))
return m;
/* Allocate all available cells in the colormap, using a binary
* algorithm to discover how many cells we can allocate in the colormap.
*/
m--;
while (n <= m) {
p = n + ((m - n + 1) / 2);
if (XAllocColorCells(dpy, cmap, 1, (unsigned long *) NULL,
(unsigned) 0, pixels, (unsigned) p)) {
if (p == m)
return p;
else {
XFreeColors(dpy, cmap, pixels, p, (unsigned long) 0);
n = p;
}
}
else
m = p - 1;
p = n + ((m - n + 1) / 2);
if (XAllocColorCells(dpy, cmap, 1, (unsigned long *) NULL,
(unsigned) 0, pixels, (unsigned) p)) {
if (p == m)
return p;
else {
XFreeColors(dpy, cmap, pixels, p, (unsigned long) 0);
n = p;
}
}
else
m = p - 1;
}
return 0;
}
/****************************************************************************/
static Status contiguous(pixels, npixels, ncolors, delta, first, rem)
unsigned long pixels[]; /* specifies allocated pixels */
unsigned long pixels[]; /* specifies allocated pixels */
int npixels; /* specifies count of alloc'd pixels */
int ncolors; /* specifies needed sequence length */
unsigned long delta; /* between pixels */
unsigned long delta; /* between pixels */
int *first; /* returns first index of sequence */
int *rem; /* returns first index after sequence,
* or 0, if none follow */
* or 0, if none follow */
{
register int i = 1; /* walking index into the pixel array */
register int count = 1; /* length of sequence discovered so far */
*first = 0;
if (npixels == ncolors) {
*rem = 0;
return 1;
*rem = 0;
return 1;
}
*rem = npixels - 1;
while (count < ncolors && ncolors - count <= *rem)
{
if (pixels[i-1] + delta == pixels[i])
count++;
else {
count = 1;
*first = i;
}
i++;
(*rem)--;
if (pixels[i-1] + delta == pixels[i])
count++;
else {
count = 1;
*first = i;
}
i++;
(*rem)--;
}
if (count != ncolors)
return 0;
return 0;
return 1;
}
@@ -408,23 +408,23 @@ static Status ROorRWcell(dpy, cmap, pixels, npixels, color, p)
* If the read only allocation is granted, but gives us a cell which
* is not the one that we just freed, it is probably the case that
* we are trying allocate White or Black or some other color which
* already has a read-only allocation in the map. So we try to
* already has a read-only allocation in the map. So we try to
* allocate the previously freed cell with a read/write allocation,
* because we want contiguous cells for image processing algorithms.
*/
pixel = color->pixel;
request.red = color->red;
request.green = color->green;
request.blue = color->blue;
XFreeColors(dpy, cmap, &pixel, 1, (unsigned long) 0);
if (! XAllocColor(dpy, cmap, color)
|| (color->pixel != pixel &&
(!RWcell(dpy, cmap, color, &request, &pixel))))
if (! XAllocColor(dpy, cmap, color)
|| (color->pixel != pixel &&
(!RWcell(dpy, cmap, color, &request, &pixel))))
{
free_cells(dpy, cmap, pixels, npixels, (int)p);
return 0;
free_cells(dpy, cmap, pixels, npixels, (int)p);
return 0;
}
return 1;
}
@@ -436,7 +436,7 @@ static void free_cells(dpy, cmap, pixels, npixels, p)
Colormap cmap;
unsigned long pixels[]; /* to be freed */
int npixels; /* original number allocated */
int p;
int p;
{
/* One of the npixels allocated has already been freed.
* p is the index of the freed pixel.
@@ -461,12 +461,12 @@ static Status RWcell(dpy, cmap, color, request, pixel)
XFreeColors(dpy, cmap, &(color->pixel), 1, (unsigned long)0);
if (! XAllocColorCells(dpy, cmap, (Bool) 0, (unsigned long *) NULL,
(unsigned) 0, pixel, (unsigned) 1))
return 0;
(unsigned) 0, pixel, (unsigned) 1))
return 0;
if (*pixel != n)
{
XFreeColors(dpy, cmap, pixel, 1, (unsigned long) 0);
return 0;
XFreeColors(dpy, cmap, pixel, 1, (unsigned long) 0);
return 0;
}
color->pixel = *pixel;
color->flags = DoRed | DoGreen | DoBlue;
@@ -497,28 +497,29 @@ static Status readonly_map(dpy, vinfo, colormap)
int i, last_pixel;
XColor color;
last_pixel = (colormap->red_max + 1) * (colormap->green_max + 1) *
(colormap->blue_max + 1) + colormap->base_pixel - 1;
last_pixel = (colormap->red_max + 1) * (colormap->green_max + 1) *
(colormap->blue_max + 1) + colormap->base_pixel - 1;
for(i=colormap->base_pixel; i <= last_pixel; i++) {
color.pixel = (unsigned long) i;
color.red = (unsigned short)
(((i/colormap->red_mult) * 65535) / colormap->red_max);
color.pixel = (unsigned long) i;
color.red = (unsigned short)
(((i/colormap->red_mult) * 65535) / colormap->red_max);
if (vinfo->class == StaticColor) {
color.green = (unsigned short)
((((i/colormap->green_mult) % (colormap->green_max + 1)) *
65535) / colormap->green_max);
color.blue = (unsigned short)
(((i%colormap->green_mult) * 65535) / colormap->blue_max);
}
else /* vinfo->class == GrayScale, old style allocation XXX */
color.green = color.blue = color.red;
if (vinfo->class == StaticColor) {
color.green = (unsigned short)
((((i/colormap->green_mult) % (colormap->green_max + 1)) *
65535) / colormap->green_max);
color.blue = (unsigned short)
(((i%colormap->green_mult) * 65535) / colormap->blue_max);
}
else /* vinfo->class == GrayScale, old style allocation XXX */
color.green = color.blue = color.red;
XAllocColor(dpy, colormap->colormap, &color);
if (color.pixel != (unsigned long) i)
return 0;
XAllocColor(dpy, colormap->colormap, &color);
if (color.pixel != (unsigned long) i)
return 0;
}
return 1;
}

View File

@@ -1,7 +1,7 @@
/* $XConsortium: DelCmap.c,v 1.2 94/04/17 20:15:58 converse Exp $ */
/*
/*
Copyright (c) 1989 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -49,19 +49,18 @@ void XmuDeleteStandardColormap(dpy, screen, property)
int count = 0;
if (XGetRGBColormaps(dpy, RootWindow(dpy, screen), &stdcmaps, &count,
property))
{
for (s=stdcmaps; count > 0; count--, s++) {
if ((s->killid == ReleaseByFreeingColormap) &&
(s->colormap != None) &&
(s->colormap != DefaultColormap(dpy, screen)))
XFreeColormap(dpy, s->colormap);
else if (s->killid != None)
XKillClient(dpy, s->killid);
}
XDeleteProperty(dpy, RootWindow(dpy, screen), property);
XFree((char *) stdcmaps);
XSync(dpy, False);
property)) {
for (s=stdcmaps; count > 0; count--, s++) {
if ((s->killid == ReleaseByFreeingColormap) &&
(s->colormap != None) &&
(s->colormap != DefaultColormap(dpy, screen)))
XFreeColormap(dpy, s->colormap);
else if (s->killid != None)
XKillClient(dpy, s->killid);
}
XDeleteProperty(dpy, RootWindow(dpy, screen), property);
XFree((char *) stdcmaps);
XSync(dpy, False);
}
}

View File

@@ -1,7 +1,7 @@
/* $XConsortium: LookupCmap.c,v 1.10 94/04/17 20:16:11 rws Exp $ */
/*
/*
Copyright (c) 1989 X Consortium
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -43,7 +43,7 @@ static Status lookup();
/*
* To create a standard colormap if one does not currently exist, or
* replace the currently existing standard colormap, use
* replace the currently existing standard colormap, use
* XmuLookupStandardColormap().
*
* Given a screen, a visual, and a property, XmuLookupStandardColormap()
@@ -52,14 +52,14 @@ static Status lookup();
* the default colormap of the screen. It will call XmuStandardColormap()
* to create the standard colormap.
*
* If replace is true, any previous definition of the property will be
* If replace is true, any previous definition of the property will be
* replaced. If retain is true, the property and the colormap will be
* made permanent for the duration of the server session. However,
* pre-existing property definitions which are not replaced cannot be made
* permanent by a call to XmuLookupStandardColormap(); a request to retain
* permanent by a call to XmuLookupStandardColormap(); a request to retain
* resources pertains to newly created resources.
*
* Returns 0 on failure, non-zero on success. A request to create a
* Returns 0 on failure, non-zero on success. A request to create a
* standard colormap upon a visual which cannot support such a map is
* considered a failure. An example of this would be requesting any
* standard colormap property on a monochrome visual, or, requesting an
@@ -67,7 +67,7 @@ static Status lookup();
*/
Status XmuLookupStandardColormap(dpy, screen, visualid, depth, property,
replace, retain)
replace, retain)
Display *dpy; /* specifies X server connection */
int screen; /* specifies screen of display */
VisualID visualid; /* specifies the visual type */
@@ -77,41 +77,41 @@ Status XmuLookupStandardColormap(dpy, screen, visualid, depth, property,
Bool retain; /* specifies whether to retain */
{
Display *odpy; /* original display connection */
XStandardColormap *colormap;
XStandardColormap *colormap;
XVisualInfo vinfo_template, *vinfo; /* visual */
long vinfo_mask;
unsigned long r_max, g_max, b_max; /* allocation */
int count;
int count;
Colormap cmap; /* colormap ID */
Status status = 0;
/* Match the requested visual */
vinfo_template.visualid = visualid;
vinfo_template.visualid = visualid;
vinfo_template.screen = screen;
vinfo_template.depth = depth;
vinfo_mask = VisualIDMask | VisualScreenMask | VisualDepthMask;
if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &count)) ==
NULL)
return 0;
NULL)
return 0;
/* Monochrome visuals have no standard maps */
if (vinfo->colormap_size <= 2) {
XFree((char *) vinfo);
return 0;
XFree((char *) vinfo);
return 0;
}
/* If the requested property already exists on this screen, and,
/* If the requested property already exists on this screen, and,
* if the replace flag has not been set to true, return success.
* lookup() will remove a pre-existing map if replace is true.
*/
if (lookup(dpy, screen, visualid, property, (XStandardColormap *) NULL,
replace) && !replace) {
XFree((char *) vinfo);
return 1;
replace) && !replace) {
XFree((char *) vinfo);
return 1;
}
/* Determine the best allocation for this property under the requested
@@ -120,54 +120,54 @@ Status XmuLookupStandardColormap(dpy, screen, visualid, depth, property,
*/
if (!XmuGetColormapAllocation(vinfo, property, &r_max, &g_max, &b_max)) {
XFree((char *) vinfo);
return 0;
XFree((char *) vinfo);
return 0;
}
cmap = (property == XA_RGB_DEFAULT_MAP &&
visualid == XVisualIDFromVisual(DefaultVisual(dpy, screen)))
? DefaultColormap(dpy, screen) : None;
visualid == XVisualIDFromVisual(DefaultVisual(dpy, screen)))
? DefaultColormap(dpy, screen) : None;
/* If retaining resources, open a new connection to the same server */
if (retain) {
odpy = dpy;
if ((dpy = XOpenDisplay(XDisplayString(odpy))) == NULL) {
XFree((char *) vinfo);
return 0;
}
odpy = dpy;
if ((dpy = XOpenDisplay(XDisplayString(odpy))) == NULL) {
XFree((char *) vinfo);
return 0;
}
}
/* Create the standard colormap */
colormap = XmuStandardColormap(dpy, screen, visualid, depth, property,
cmap, r_max, g_max, b_max);
cmap, r_max, g_max, b_max);
/* Set the standard colormap property */
if (colormap) {
XGrabServer(dpy);
XGrabServer(dpy);
if (lookup(dpy, screen, visualid, property, colormap, replace) &&
!replace) {
/* Someone has defined the property since we last looked.
* Since we will not replace it, release our own resources.
* If this is the default map, our allocations will be freed
* when this connection closes.
*/
if (colormap->killid == ReleaseByFreeingColormap)
XFreeColormap(dpy, colormap->colormap);
}
else if (retain) {
XSetCloseDownMode(dpy, RetainPermanent);
}
XUngrabServer(dpy);
XFree((char *) colormap);
status = 1;
if (lookup(dpy, screen, visualid, property, colormap, replace) &&
!replace) {
/* Someone has defined the property since we last looked.
* Since we will not replace it, release our own resources.
* If this is the default map, our allocations will be freed
* when this connection closes.
*/
if (colormap->killid == ReleaseByFreeingColormap)
XFreeColormap(dpy, colormap->colormap);
}
else if (retain) {
XSetCloseDownMode(dpy, RetainPermanent);
}
XUngrabServer(dpy);
XFree((char *) colormap);
status = 1;
}
if (retain)
XCloseDisplay(dpy);
XCloseDisplay(dpy);
XFree((char *) vinfo);
return status;
}
@@ -184,7 +184,7 @@ Status XmuLookupStandardColormap(dpy, screen, visualid, depth, property,
*
* If new is not NULL, new points to an XStandardColormap structure which
* describes a standard colormap of the specified property. It will be made
* a standard colormap of the screen if none already exists, or if replace
* a standard colormap of the screen if none already exists, or if replace
* is true.
*/
@@ -204,109 +204,110 @@ static Status lookup(dpy, screen, visualid, property, new, replace)
/* The property does not already exist */
if (! XGetRGBColormaps(dpy, win, &stdcmaps, &count, property)) {
if (new)
XSetRGBColormaps(dpy, win, new, 1, property);
return 0;
if (new)
XSetRGBColormaps(dpy, win, new, 1, property);
return 0;
}
/* The property exists and is not describing the RGB_DEFAULT_MAP */
if (property != XA_RGB_DEFAULT_MAP) {
if (replace) {
XmuDeleteStandardColormap(dpy, screen, property);
if (new)
XSetRGBColormaps(dpy, win, new, 1, property);
}
XFree((char *)stdcmaps);
return 1;
if (replace) {
XmuDeleteStandardColormap(dpy, screen, property);
if (new)
XSetRGBColormaps(dpy, win, new, 1, property);
}
XFree((char *)stdcmaps);
return 1;
}
/* The property exists and is RGB_DEFAULT_MAP */
for (i=0, s=stdcmaps; (i < count) && (s->visualid != visualid); i++, s++)
;
;
/* No RGB_DEFAULT_MAP property matches the given visualid */
if (i == count) {
if (new) {
XStandardColormap *m, *maps;
if (new) {
XStandardColormap *m, *maps;
s = (XStandardColormap *) malloc((unsigned) ((count+1) * sizeof
(XStandardColormap)));
s = (XStandardColormap *) malloc((unsigned) ((count+1) * sizeof
(XStandardColormap)));
for (i = 0, m = s, maps = stdcmaps; i < count; i++, m++, maps++) {
m->colormap = maps->colormap;
m->red_max = maps->red_max;
m->red_mult = maps->red_mult;
m->green_max = maps->green_max;
m->green_mult = maps->green_mult;
m->blue_max = maps->blue_max;
m->blue_mult = maps->blue_mult;
m->base_pixel = maps->base_pixel;
m->visualid = maps->visualid;
m->killid = maps->killid;
}
m->colormap = new->colormap;
m->red_max = new->red_max;
m->red_mult = new->red_mult;
m->green_max = new->green_max;
m->green_mult = new->green_mult;
m->blue_max = new->blue_max;
m->blue_mult = new->blue_mult;
m->base_pixel = new->base_pixel;
m->visualid = new->visualid;
m->killid = new->killid;
for (i = 0, m = s, maps = stdcmaps; i < count; i++, m++, maps++) {
m->colormap = maps->colormap;
m->red_max = maps->red_max;
m->red_mult = maps->red_mult;
m->green_max = maps->green_max;
m->green_mult = maps->green_mult;
m->blue_max = maps->blue_max;
m->blue_mult = maps->blue_mult;
m->base_pixel = maps->base_pixel;
m->visualid = maps->visualid;
m->killid = maps->killid;
}
m->colormap = new->colormap;
m->red_max = new->red_max;
m->red_mult = new->red_mult;
m->green_max = new->green_max;
m->green_mult = new->green_mult;
m->blue_max = new->blue_max;
m->blue_mult = new->blue_mult;
m->base_pixel = new->base_pixel;
m->visualid = new->visualid;
m->killid = new->killid;
XSetRGBColormaps(dpy, win, s, ++count, property);
free((char *) s);
}
XFree((char *) stdcmaps);
return 0;
XSetRGBColormaps(dpy, win, s, ++count, property);
free((char *) s);
}
XFree((char *) stdcmaps);
return 0;
}
/* Found an RGB_DEFAULT_MAP property with a matching visualid */
if (replace) {
/* Free old resources first - we may need them, particularly in
* the default colormap of the screen. However, because of this,
* it is possible that we will destroy the old resource and fail
* to create a new one if XmuStandardColormap() fails.
*/
/* Free old resources first - we may need them, particularly in
* the default colormap of the screen. However, because of this,
* it is possible that we will destroy the old resource and fail
* to create a new one if XmuStandardColormap() fails.
*/
if (count == 1) {
XmuDeleteStandardColormap(dpy, screen, property);
if (new)
XSetRGBColormaps(dpy, win, new, 1, property);
}
else {
XStandardColormap *map;
if (count == 1) {
XmuDeleteStandardColormap(dpy, screen, property);
if (new)
XSetRGBColormaps(dpy, win, new, 1, property);
}
else {
XStandardColormap *map;
/* s still points to the matching standard colormap */
/* s still points to the matching standard colormap */
if (s->killid == ReleaseByFreeingColormap) {
if ((s->colormap != None) &&
(s->colormap != DefaultColormap(dpy, screen)))
XFreeColormap(dpy, s->colormap);
}
else if (s->killid != None)
XKillClient(dpy, s->killid);
if (s->killid == ReleaseByFreeingColormap) {
if ((s->colormap != None) &&
(s->colormap != DefaultColormap(dpy, screen)))
XFreeColormap(dpy, s->colormap);
}
else if (s->killid != None)
XKillClient(dpy, s->killid);
map = (new) ? new : stdcmaps + --count;
map = (new) ? new : stdcmaps + --count;
s->colormap = map->colormap;
s->red_max = map->red_max;
s->red_mult = map->red_mult;
s->green_max = map->green_max;
s->green_mult = map->green_mult;
s->blue_max = map->blue_max;
s->blue_mult = map->blue_mult;
s->visualid = map->visualid;
s->killid = map->killid;
s->colormap = map->colormap;
s->red_max = map->red_max;
s->red_mult = map->red_mult;
s->green_max = map->green_max;
s->green_mult = map->green_mult;
s->blue_max = map->blue_max;
s->blue_mult = map->blue_mult;
s->visualid = map->visualid;
s->killid = map->killid;
XSetRGBColormaps(dpy, win, stdcmaps, count, property);
}
XSetRGBColormaps(dpy, win, stdcmaps, count, property);
}
}
XFree((char *) stdcmaps);
return 1;
}

View File

@@ -1,6 +1,6 @@
/* $XConsortium: StdCmap.c,v 1.14 94/04/17 20:16:14 rws Exp $ */
/*
/*
Copyright (c) 1989 X Consortium
@@ -49,7 +49,7 @@ static Status valid_args(); /* argument restrictions */
* given standard property name. Return a pointer to an XStandardColormap
* structure which describes the newly created colormap, upon success.
* Upon failure, return NULL.
*
*
* XmuStandardColormap() calls XmuCreateColormap() to create the map.
*
* Resources created by this function are not made permanent; that is the
@@ -57,7 +57,7 @@ static Status valid_args(); /* argument restrictions */
*/
XStandardColormap *XmuStandardColormap(dpy, screen, visualid, depth, property,
cmap, red_max, green_max, blue_max)
cmap, red_max, green_max, blue_max)
Display *dpy; /* specifies X server connection */
int screen; /* specifies display screen */
VisualID visualid; /* identifies the visual type */
@@ -73,12 +73,12 @@ XStandardColormap *XmuStandardColormap(dpy, screen, visualid, depth, property,
int n;
/* Match the required visual information to an actual visual */
vinfo_template.visualid = visualid;
vinfo_template.visualid = visualid;
vinfo_template.screen = screen;
vinfo_template.depth = depth;
vinfo_mask = VisualIDMask | VisualScreenMask | VisualDepthMask;
if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL)
return 0;
return 0;
/* Check the validity of the combination of visual characteristics,
* allocation, and colormap property. Create an XStandardColormap
@@ -86,41 +86,41 @@ XStandardColormap *XmuStandardColormap(dpy, screen, visualid, depth, property,
*/
if (! valid_args(vinfo, red_max, green_max, blue_max, property)
|| ((stdcmap = XAllocStandardColormap()) == NULL)) {
XFree((char *) vinfo);
return 0;
|| ((stdcmap = XAllocStandardColormap()) == NULL)) {
XFree((char *) vinfo);
return 0;
}
/* Fill in the XStandardColormap structure */
if (cmap == DefaultColormap(dpy, screen)) {
/* Allocating out of the default map, cannot use XFreeColormap() */
Window win = XCreateWindow(dpy, RootWindow(dpy, screen), 1, 1, 1, 1,
0, 0, InputOnly, vinfo->visual,
(unsigned long) 0,
(XSetWindowAttributes *)NULL);
stdcmap->killid = (XID) XCreatePixmap(dpy, win, 1, 1, depth);
XDestroyWindow(dpy, win);
stdcmap->colormap = cmap;
/* Allocating out of the default map, cannot use XFreeColormap() */
Window win = XCreateWindow(dpy, RootWindow(dpy, screen), 1, 1, 1, 1,
0, 0, InputOnly, vinfo->visual,
(unsigned long) 0,
(XSetWindowAttributes *)NULL);
stdcmap->killid = (XID) XCreatePixmap(dpy, win, 1, 1, depth);
XDestroyWindow(dpy, win);
stdcmap->colormap = cmap;
} else {
stdcmap->killid = ReleaseByFreeingColormap;
stdcmap->colormap = XCreateColormap(dpy, RootWindow(dpy, screen),
vinfo->visual, AllocNone);
stdcmap->killid = ReleaseByFreeingColormap;
stdcmap->colormap = XCreateColormap(dpy, RootWindow(dpy, screen),
vinfo->visual, AllocNone);
}
stdcmap->red_max = red_max;
stdcmap->green_max = green_max;
stdcmap->blue_max = blue_max;
if (property == XA_RGB_GRAY_MAP)
stdcmap->red_mult = stdcmap->green_mult = stdcmap->blue_mult = 1;
if (property == XA_RGB_GRAY_MAP)
stdcmap->red_mult = stdcmap->green_mult = stdcmap->blue_mult = 1;
else if (vinfo->class == TrueColor || vinfo->class == DirectColor) {
stdcmap->red_mult = lowbit(vinfo->red_mask);
stdcmap->green_mult = lowbit(vinfo->green_mask);
stdcmap->blue_mult = lowbit(vinfo->blue_mask);
stdcmap->red_mult = lowbit(vinfo->red_mask);
stdcmap->green_mult = lowbit(vinfo->green_mask);
stdcmap->blue_mult = lowbit(vinfo->blue_mask);
} else {
stdcmap->red_mult = (red_max > 0)
? (green_max + 1) * (blue_max + 1) : 0;
stdcmap->green_mult = (green_max > 0) ? blue_max + 1 : 0;
stdcmap->blue_mult = (blue_max > 0) ? 1 : 0;
stdcmap->red_mult = (red_max > 0)
? (green_max + 1) * (blue_max + 1) : 0;
stdcmap->green_mult = (green_max > 0) ? blue_max + 1 : 0;
stdcmap->blue_mult = (blue_max > 0) ? 1 : 0;
}
stdcmap->base_pixel = 0; /* base pixel may change */
stdcmap->visualid = vinfo->visualid;
@@ -134,14 +134,14 @@ XStandardColormap *XmuStandardColormap(dpy, screen, visualid, depth, property,
XFree((char *) vinfo);
if (!status) {
/* Free the colormap or the pixmap, if we created one */
if (stdcmap->killid == ReleaseByFreeingColormap)
XFreeColormap(dpy, stdcmap->colormap);
else if (stdcmap->killid != None)
XFreePixmap(dpy, stdcmap->killid);
XFree((char *) stdcmap);
return (XStandardColormap *) NULL;
/* Free the colormap or the pixmap, if we created one */
if (stdcmap->killid == ReleaseByFreeingColormap)
XFreeColormap(dpy, stdcmap->colormap);
else if (stdcmap->killid != None)
XFreePixmap(dpy, stdcmap->killid);
XFree((char *) stdcmap);
return (XStandardColormap *) NULL;
}
return stdcmap;
}
@@ -157,63 +157,64 @@ static Status valid_args(vinfo, red_max, green_max, blue_max, property)
/* Determine that the number of colors requested is <= map size */
if ((vinfo->class == DirectColor) || (vinfo->class == TrueColor)) {
unsigned long mask;
unsigned long mask;
mask = vinfo->red_mask;
while (!(mask & 1))
mask >>= 1;
if (red_max > mask)
return 0;
mask = vinfo->green_mask;
while (!(mask & 1))
mask >>= 1;
if (green_max > mask)
return 0;
mask = vinfo->blue_mask;
while (!(mask & 1))
mask >>= 1;
if (blue_max > mask)
return 0;
mask = vinfo->red_mask;
while (!(mask & 1))
mask >>= 1;
if (red_max > mask)
return 0;
mask = vinfo->green_mask;
while (!(mask & 1))
mask >>= 1;
if (green_max > mask)
return 0;
mask = vinfo->blue_mask;
while (!(mask & 1))
mask >>= 1;
if (blue_max > mask)
return 0;
} else if (property == XA_RGB_GRAY_MAP) {
ncolors = red_max + green_max + blue_max + 1;
if (ncolors > vinfo->colormap_size)
return 0;
ncolors = red_max + green_max + blue_max + 1;
if (ncolors > vinfo->colormap_size)
return 0;
} else {
ncolors = (red_max + 1) * (green_max + 1) * (blue_max + 1);
if (ncolors > vinfo->colormap_size)
return 0;
ncolors = (red_max + 1) * (green_max + 1) * (blue_max + 1);
if (ncolors > vinfo->colormap_size)
return 0;
}
/* Determine that the allocation and visual make sense for the property */
switch (property)
{
case XA_RGB_DEFAULT_MAP:
if (red_max == 0 || green_max == 0 || blue_max == 0)
return 0;
break;
case XA_RGB_RED_MAP:
if (red_max == 0)
return 0;
break;
case XA_RGB_GREEN_MAP:
if (green_max == 0)
return 0;
break;
case XA_RGB_BLUE_MAP:
if (blue_max == 0)
return 0;
break;
case XA_RGB_BEST_MAP:
if (red_max == 0 || green_max == 0 || blue_max == 0)
return 0;
break;
case XA_RGB_GRAY_MAP:
if (red_max == 0 || blue_max == 0 || green_max == 0)
return 0;
break;
default:
return 0;
case XA_RGB_DEFAULT_MAP:
if (red_max == 0 || green_max == 0 || blue_max == 0)
return 0;
break;
case XA_RGB_RED_MAP:
if (red_max == 0)
return 0;
break;
case XA_RGB_GREEN_MAP:
if (green_max == 0)
return 0;
break;
case XA_RGB_BLUE_MAP:
if (blue_max == 0)
return 0;
break;
case XA_RGB_BEST_MAP:
if (red_max == 0 || green_max == 0 || blue_max == 0)
return 0;
break;
case XA_RGB_GRAY_MAP:
if (red_max == 0 || blue_max == 0 || green_max == 0)
return 0;
break;
default:
return 0;
}
return 1;
}

View File

@@ -1,25 +1,25 @@
/* alloca.c -- allocate automatically reclaimed memory
(Mostly) portable public-domain implementation -- D A Gwyn
(Mostly) portable public-domain implementation -- D A Gwyn
This implementation of the PWB library alloca function,
which is used to allocate space off the run-time stack so
that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
J.Otto Tennant <jot@cray.com> contributed the Cray support.
This implementation of the PWB library alloca function,
which is used to allocate space off the run-time stack so
that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
J.Otto Tennant <jot@cray.com> contributed the Cray support.
There are some preprocessor constants that can
be defined when compiling for your specific system, for
improved efficiency; however, the defaults should be okay.
There are some preprocessor constants that can
be defined when compiling for your specific system, for
improved efficiency; however, the defaults should be okay.
The general concept of this implementation is to keep
track of all alloca-allocated blocks, and reclaim any
that are found to be deeper in the stack than the current
invocation. This heuristic does not reclaim storage as
soon as it becomes invalid, but it will do so eventually.
The general concept of this implementation is to keep
track of all alloca-allocated blocks, and reclaim any
that are found to be deeper in the stack than the current
invocation. This heuristic does not reclaim storage as
soon as it becomes invalid, but it will do so eventually.
As a special case, alloca(0) reclaims storage without
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
As a special case, alloca(0) reclaims storage without
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -40,15 +40,15 @@
#if !defined (__GNUC__) || __GNUC__ < 2
/* If someone has defined alloca as a macro,
there must be some other way alloca is supposed to work. */
there must be some other way alloca is supposed to work. */
#ifndef alloca
#ifdef emacs
#ifdef static
/* actually, only want this if static is defined as ""
-- this is for usg, in which emacs must undefine static
in order to make unexec workable
*/
-- this is for usg, in which emacs must undefine static
in order to make unexec workable
*/
#ifndef STACK_DIRECTION
you
lose
@@ -78,14 +78,14 @@ typedef char *pointer;
#endif
/* Different portions of Emacs need to call different versions of
malloc. The Emacs executable needs alloca to call xmalloc, because
ordinary malloc isn't protected from input signals. On the other
hand, the utilities in lib-src need alloca to call malloc; some of
them are very simple, and don't have an xmalloc routine.
malloc. The Emacs executable needs alloca to call xmalloc, because
ordinary malloc isn't protected from input signals. On the other
hand, the utilities in lib-src need alloca to call malloc; some of
them are very simple, and don't have an xmalloc routine.
Non-Emacs programs expect this to call use xmalloc.
Non-Emacs programs expect this to call use xmalloc.
Callers below should use malloc. */
Callers below should use malloc. */
#ifndef emacs
#define malloc xmalloc
@@ -93,12 +93,12 @@ typedef char *pointer;
extern pointer malloc ();
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
deduced at run-time.
growth for your system; otherwise it will be automatically
deduced at run-time.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
#ifndef STACK_DIRECTION
#define STACK_DIRECTION 0 /* Direction unknown. */
@@ -116,33 +116,33 @@ static int stack_dir; /* 1 or -1 once known. */
static void
find_stack_direction ()
{
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
if (addr == NULL)
if (addr == NULL)
{ /* Initial entry. */
addr = ADDRESS_FUNCTION (dummy);
addr = ADDRESS_FUNCTION (dummy);
find_stack_direction (); /* Recurse once. */
find_stack_direction (); /* Recurse once. */
}
else
else
{
/* Second entry. */
if (ADDRESS_FUNCTION (dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
/* Second entry. */
if (ADDRESS_FUNCTION (dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
}
}
#endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
(b) keep track of stack depth.
(a) chain together all alloca'ed blocks;
(b) keep track of stack depth.
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
#ifndef ALIGN_SIZE
#define ALIGN_SIZE sizeof(double)
@@ -150,86 +150,86 @@ find_stack_direction ()
typedef union hdr
{
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
} header;
static header *last_alloca_header = NULL; /* -> last alloca header. */
/* Return a pointer to at least SIZE bytes of storage,
which will be automatically reclaimed upon exit from
the procedure that called alloca. Originally, this space
was supposed to be taken from the current stack frame of the
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
which will be automatically reclaimed upon exit from
the procedure that called alloca. Originally, this space
was supposed to be taken from the current stack frame of the
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
pointer
alloca (size)
unsigned size;
unsigned size;
{
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
#if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
#endif
/* Reclaim garbage, defined as all alloca'd storage that
/* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */
{
register header *hp; /* Traverses linked list. */
{
register header *hp; /* Traverses linked list. */
#ifdef emacs
BLOCK_INPUT;
BLOCK_INPUT;
#endif
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
register header *np = hp->h.next;
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
register header *np = hp->h.next;
free ((pointer) hp); /* Collect garbage. */
free ((pointer) hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
last_alloca_header = hp; /* -> last valid storage. */
last_alloca_header = hp; /* -> last valid storage. */
#ifdef emacs
UNBLOCK_INPUT;
UNBLOCK_INPUT;
#endif
}
}
if (size == 0)
return NULL; /* No allocation required. */
if (size == 0)
return NULL; /* No allocation required. */
/* Allocate combined header + user data storage. */
/* Allocate combined header + user data storage. */
{
register pointer new = malloc (sizeof (header) + size);
/* Address of header. */
{
register pointer new = malloc (sizeof (header) + size);
/* Address of header. */
if (new == 0)
abort();
if (new == 0)
abort();
((header *) new)->h.next = last_alloca_header;
((header *) new)->h.deep = depth;
((header *) new)->h.next = last_alloca_header;
((header *) new)->h.deep = depth;
last_alloca_header = (header *) new;
last_alloca_header = (header *) new;
/* User storage begins just after header. */
/* User storage begins just after header. */
return (pointer) ((char *) new + sizeof (header));
}
return (pointer) ((char *) new + sizeof (header));
}
}
#if defined (CRAY) && defined (CRAY_STACKSEG_END)
@@ -243,32 +243,32 @@ alloca (size)
#ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header
{
{
long shgrow:32; /* Number of times stack has grown. */
long shaseg:32; /* Size of increments to stack. */
long shhwm:32; /* High water mark of stack. */
long shsize:32; /* Current size of stack (all segments). */
};
};
/* The stack segment linkage control information occurs at
the high-address end of a stack segment. (The stack
grows from low addresses to high addresses.) The initial
part of the stack segment linkage control information is
0200 (octal) words. This provides for register storage
for the routine which overflows the stack. */
the high-address end of a stack segment. (The stack
grows from low addresses to high addresses.) The initial
part of the stack segment linkage control information is
0200 (octal) words. This provides for register storage
for the routine which overflows the stack. */
struct stack_segment_linkage
{
{
long ss[0200]; /* 0200 overflow words. */
long sssize:32; /* Number of words in this segment. */
long ssbase:32; /* Offset to stack base. */
long:32;
long sspseg:32; /* Offset to linkage control of previous
segment of stack. */
segment of stack. */
long:32;
long sstcpt:32; /* Pointer to task common address block. */
long sscsnm; /* Private control structure number for
microtasking. */
microtasking. */
long ssusr1; /* Reserved for user. */
long ssusr2; /* Reserved for user. */
long sstpid; /* Process ID for pid based multi-tasking. */
@@ -290,17 +290,17 @@ struct stack_segment_linkage
long sss5;
long sss6;
long sss7;
};
};
#else /* CRAY2 */
/* The following structure defines the vector of words
returned by the STKSTAT library routine. */
returned by the STKSTAT library routine. */
struct stk_stat
{
{
long now; /* Current total stack size. */
long maxc; /* Amount of contiguous space which would
be required to satisfy the maximum
stack demand to date. */
be required to satisfy the maximum
stack demand to date. */
long high_water; /* Stack high-water mark. */
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
long hits; /* Number of internal buffer hits. */
@@ -314,25 +314,25 @@ struct stk_stat
long pad_size; /* Stack pad size. */
long current_address; /* Current stack segment address. */
long current_size; /* Current stack segment size. This
number is actually corrupted by STKSTAT to
include the fifteen word trailer area. */
number is actually corrupted by STKSTAT to
include the fifteen word trailer area. */
long initial_address; /* Address of initial segment. */
long initial_size; /* Size of initial segment. */
};
};
/* The following structure describes the data structure which trails
any stack segment. I think that the description in 'asdef' is
out of date. I only describe the parts that I am sure about. */
any stack segment. I think that the description in 'asdef' is
out of date. I only describe the parts that I am sure about. */
struct stk_trailer
{
{
long this_address; /* Address of this block. */
long this_size; /* Size of this block (does not include
this trailer). */
this trailer). */
long unknown2;
long unknown3;
long link; /* Address of trailer block of previous
segment. */
segment. */
long unknown5;
long unknown6;
long unknown7;
@@ -343,100 +343,100 @@ struct stk_trailer
long unknown12;
long unknown13;
long unknown14;
};
};
#endif /* CRAY2 */
#endif /* not CRAY_STACK */
#ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */
I doubt that "lint" will like this much. */
static long
i00afunc (long *address)
{
struct stk_stat status;
struct stk_trailer *trailer;
long *block, size;
long result = 0;
struct stk_stat status;
struct stk_trailer *trailer;
long *block, size;
long result = 0;
/* We want to iterate through all of the segments. The first
/* We want to iterate through all of the segments. The first
step is to get the stack status structure. We could do this
more quickly and more directly, perhaps, by referencing the
$LM00 common block, but I know that this works. */
STKSTAT (&status);
STKSTAT (&status);
/* Set up the iteration. */
/* Set up the iteration. */
trailer = (struct stk_trailer *) (status.current_address
+ status.current_size
- 15);
trailer = (struct stk_trailer *) (status.current_address
+ status.current_size
- 15);
/* There must be at least one stack segment. Therefore it is
/* There must be at least one stack segment. Therefore it is
a fatal error if "trailer" is null. */
if (trailer == 0)
abort ();
if (trailer == 0)
abort ();
/* Discard segments that do not contain our argument address. */
/* Discard segments that do not contain our argument address. */
while (trailer != 0)
while (trailer != 0)
{
block = (long *) trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
abort ();
trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size)))
break;
block = (long *) trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
abort ();
trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size)))
break;
}
/* Set the result to the offset in this segment and add the sizes
/* Set the result to the offset in this segment and add the sizes
of all predecessor segments. */
result = address - block;
result = address - block;
if (trailer == 0)
if (trailer == 0)
{
return result;
return result;
}
do
do
{
if (trailer->this_size <= 0)
abort ();
result += trailer->this_size;
trailer = (struct stk_trailer *) trailer->link;
if (trailer->this_size <= 0)
abort ();
result += trailer->this_size;
trailer = (struct stk_trailer *) trailer->link;
}
while (trailer != 0);
while (trailer != 0);
/* We are done. Note that if you present a bogus address (one
/* We are done. Note that if you present a bogus address (one
not in any segment), you will get a different number back, formed
from subtracting the address of the first block. This is probably
not what you want. */
return (result);
return (result);
}
#else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
routine is to linearize, in some sense, stack addresses
for alloca. */
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
routine is to linearize, in some sense, stack addresses
for alloca. */
static long
i00afunc (long address)
{
long stkl = 0;
long stkl = 0;
long size, pseg, this_segment, stack;
long result = 0;
long size, pseg, this_segment, stack;
long result = 0;
struct stack_segment_linkage *ssptr;
struct stack_segment_linkage *ssptr;
/* Register B67 contains the address of the end of the
/* Register B67 contains the address of the end of the
current stack segment. If you (as a subprogram) store
your registers on the stack and find that you are past
the contents of B67, you have overflowed the segment.
@@ -444,57 +444,57 @@ i00afunc (long address)
B67 also points to the stack segment linkage control
area, which is what we are really interested in. */
stkl = CRAY_STACKSEG_END ();
ssptr = (struct stack_segment_linkage *) stkl;
stkl = CRAY_STACKSEG_END ();
ssptr = (struct stack_segment_linkage *) stkl;
/* If one subtracts 'size' from the end of the segment,
/* If one subtracts 'size' from the end of the segment,
one has the address of the first word of the segment.
If this is not the first segment, 'pseg' will be
nonzero. */
pseg = ssptr->sspseg;
size = ssptr->sssize;
pseg = ssptr->sspseg;
size = ssptr->sssize;
this_segment = stkl - size;
this_segment = stkl - size;
/* It is possible that calling this routine itself caused
/* It is possible that calling this routine itself caused
a stack overflow. Discard stack segments which do not
contain the target address. */
while (!(this_segment <= address && address <= stkl))
while (!(this_segment <= address && address <= stkl))
{
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
#endif
if (pseg == 0)
break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
this_segment = stkl - size;
if (pseg == 0)
break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
this_segment = stkl - size;
}
result = address - this_segment;
result = address - this_segment;
/* If you subtract pseg from the current end of the stack,
/* If you subtract pseg from the current end of the stack,
you get the address of the previous stack segment's end.
This seems a little convoluted to me, but I'll bet you save
a cycle somewhere. */
while (pseg != 0)
while (pseg != 0)
{
#ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size);
fprintf (stderr, "%011o %011o\n", pseg, size);
#endif
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
result += size;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
result += size;
}
return (result);
return (result);
}
#endif /* not CRAY2 */

View File

@@ -2,38 +2,38 @@
inline static void
cycle_bench(int start)
cycle_bench(int start)
{
static volatile unsigned int start_cycle;
if (start) {
asm volatile
("pushl %%edx \n\t"
"rdtsc \n\t"
"movl %%eax,%0 \n\t"
"cld \n\t"
"popl %%edx \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
: "=m" (start_cycle) : : "eax", "edx");
asm volatile
("pushl %%edx \n\t"
"rdtsc \n\t"
"movl %%eax,%0 \n\t"
"cld \n\t"
"popl %%edx \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
"nop \n\t"
: "=m" (start_cycle) : : "eax", "edx");
} else {
volatile int end;
volatile int end;
asm volatile
("pushl %%edx \n\t"
"clc \n\t"
"rdtsc \n\t"
"movl %%eax, %0 \n\t"
"popl %%edx \n\t"
: "=m" (end) : : "eax", "edx");
printf("Cycle count = %u\n", end - start_cycle - 68);
asm volatile
("pushl %%edx \n\t"
"clc \n\t"
"rdtsc \n\t"
"movl %%eax, %0 \n\t"
"popl %%edx \n\t"
: "=m" (end) : : "eax", "edx");
printf("Cycle count = %u\n", end - start_cycle - 68);
}
}
@@ -42,26 +42,26 @@ cycle_bench(int start)
#if 0
// seems linux doesnt allow user progs to exec rdpcm..
inline static void
cache_bench(int start)
cache_bench(int start)
{
static int start_cycle;
if (start) {
asm volatile(
"movl $1,%%ecx \n\t"
"rdpmc \n\t"
"movl %%eax,%0 \n\t"
: "=m" (start_cycle));
asm volatile
("movl $1,%%ecx \n\t"
"rdpmc \n\t"
"movl %%eax,%0 \n\t"
: "=m" (start_cycle));
} else {
int end;
asm volatile(
"movl $1,%%ecx \n\t"
"rdpmc \n\t"
"movl %%eax,%0"
: "=m" (end));
printf("Cache reloads counted = %i\n", end - start_cycle);
int end;
asm volatile
("movl $1,%%ecx \n\t"
"rdpmc \n\t"
"movl %%eax,%0"
: "=m" (end));
printf("Cache reloads counted = %i\n", end - start_cycle);
}
}

View File

@@ -1,19 +1,19 @@
/* color.c - color stuff (rgb -> hsv convertion etc.)
*
*
* Raster graphics library
*
*
* Copyright (c) 1998-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -50,8 +50,8 @@ RHSVtoRGB(RHSVColor *hsv, RColor *rgb)
int p, q, t;
if (s == 0) {
rgb->red = rgb->green = rgb->blue = v;
return;
rgb->red = rgb->green = rgb->blue = v;
return;
}
i = h / 60;
f = h % 60;
@@ -60,36 +60,36 @@ RHSVtoRGB(RHSVColor *hsv, RColor *rgb)
t = v * (255 - s * (60 - f) / 60) / 255;
switch (i) {
case 0:
rgb->red = v;
rgb->green = t;
rgb->blue = p;
break;
case 1:
rgb->red = q;
rgb->green = v;
rgb->blue = p;
break;
case 2:
rgb->red = p;
rgb->green = v;
rgb->blue = t;
break;
case 3:
rgb->red = p;
rgb->green = q;
rgb->blue = v;
break;
case 4:
rgb->red = t;
rgb->green = p;
rgb->blue = v;
break;
case 5:
rgb->red = v;
rgb->green = p;
rgb->blue = q;
break;
case 0:
rgb->red = v;
rgb->green = t;
rgb->blue = p;
break;
case 1:
rgb->red = q;
rgb->green = v;
rgb->blue = p;
break;
case 2:
rgb->red = p;
rgb->green = v;
rgb->blue = t;
break;
case 3:
rgb->red = p;
rgb->green = q;
rgb->blue = v;
break;
case 4:
rgb->red = t;
rgb->green = p;
rgb->blue = v;
break;
case 5:
rgb->red = v;
rgb->green = p;
rgb->blue = q;
break;
}
}
@@ -104,31 +104,32 @@ RRGBtoHSV(RColor *rgb, RHSVColor *hsv)
v = max;
if (max == 0)
s = 0;
s = 0;
else
s = (max - min) * 255 / max;
s = (max - min) * 255 / max;
if (s == 0)
h = 0;
h = 0;
else {
int rc, gc, bc;
int rc, gc, bc;
rc = (max - rgb->red) * 255 / (max - min);
gc = (max - rgb->green) * 255 / (max - min);
bc = (max - rgb->blue) * 255 / (max - min);
rc = (max - rgb->red) * 255 / (max - min);
gc = (max - rgb->green) * 255 / (max - min);
bc = (max - rgb->blue) * 255 / (max - min);
if (rgb->red == max) {
h = ((bc - gc) * 60 / 255);
} else if (rgb->green == max) {
h = 2*60 + ((rc - bc) * 60 / 255);
} else {
h = 4*60 + ((gc - rc) * 60 / 255);
}
if (h < 0)
h += 360;
if (rgb->red == max) {
h = ((bc - gc) * 60 / 255);
} else if (rgb->green == max) {
h = 2*60 + ((rc - bc) * 60 / 255);
} else {
h = 4*60 + ((gc - rc) * 60 / 255);
}
if (h < 0)
h += 360;
}
hsv->hue = h;
hsv->saturation = s;
hsv->value = v;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,18 +1,18 @@
/*
/*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -47,83 +47,83 @@ RBlurImage(RImage *image)
pptr = malloc(image->width * ch);
if (!pptr) {
RErrorCode = RERR_NOMEMORY;
return False;
RErrorCode = RERR_NOMEMORY;
return False;
}
#define MASK(prev, cur, next, ch)\
(*(prev-ch) + *prev + *(prev+ch)\
+*(cur-ch) + 2 * *cur + *(cur+ch)\
+*(next-ch) + *next + *(next+ch)) / 10
(*(prev-ch) + *prev + *(prev+ch)\
+*(cur-ch) + 2 * *cur + *(cur+ch)\
+*(next-ch) + *next + *(next+ch)) / 10
memcpy(pptr, image->data, image->width * ch);
ptr = image->data;
nptr = ptr + image->width*ch;
tmpp = pptr;
if (ch == 3) {
ptr+=3;
nptr+=3;
pptr+=3;
ptr+=3;
nptr+=3;
pptr+=3;
for (y = 1; y < image->height-1; y++) {
for (x = 1; x < image->width-1; x++) {
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 3);
*pptr = tmp;
ptr++; nptr++; pptr++;
for (y = 1; y < image->height-1; y++) {
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 3);
*pptr = tmp;
ptr++; nptr++; pptr++;
for (x = 1; x < image->width-1; x++) {
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 3);
*pptr = tmp;
ptr++; nptr++; pptr++;
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 3);
*pptr = tmp;
ptr++; nptr++; pptr++;
}
pptr = tmpp;
ptr+=6;
nptr+=6;
pptr+=6;
}
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 3);
*pptr = tmp;
ptr++; nptr++; pptr++;
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 3);
*pptr = tmp;
ptr++; nptr++; pptr++;
}
pptr = tmpp;
ptr+=6;
nptr+=6;
pptr+=6;
}
} else {
ptr+=4;
nptr+=4;
pptr+=4;
ptr+=4;
nptr+=4;
pptr+=4;
for (y = 1; y < image->height-1; y++) {
for (x = 1; x < image->width-1; x++) {
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 4);
*pptr = tmp;
ptr++; nptr++; pptr++;
for (y = 1; y < image->height-1; y++) {
for (x = 1; x < image->width-1; x++) {
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 4);
*pptr = tmp;
ptr++; nptr++; pptr++;
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 4);
*pptr = tmp;
ptr++; nptr++; pptr++;
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 4);
*pptr = tmp;
ptr++; nptr++; pptr++;
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 4);
*pptr = tmp;
ptr++; nptr++; pptr++;
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 4);
*pptr = tmp;
ptr++; nptr++; pptr++;
}
pptr = tmpp;
ptr+=8;
nptr+=8;
pptr+=8;
}
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 4);
*pptr = tmp;
ptr++; nptr++; pptr++;
tmp = *ptr;
*ptr = MASK(pptr, ptr, nptr, 4);
*pptr = tmp;
ptr++; nptr++; pptr++;
}
pptr = tmpp;
ptr+=8;
nptr+=8;
pptr+=8;
}
}
return True;
}
@@ -142,24 +142,24 @@ REdgeDetectImage(RImage *image)
image2 = RCloneImage(image);
pr = alloca(image->width*sizeof(char));
if (!pr)
goto outofmem;
goto outofmem;
pg = alloca(image->width*sizeof(char));
if (!pg)
goto outofmem;
goto outofmem;
pb = alloca(image->width*sizeof(char));
if (!pb)
goto outofmem;
goto outofmem;
pa = alloca(image->width*sizeof(char));
if (!pa)
goto outofmem;
goto outofmem;
r = image->data[0];
g = image->data[1];
b = image->data[2];
@@ -170,91 +170,91 @@ REdgeDetectImage(RImage *image)
db = image2->data[2];
da = image2->data[3];
for (x=0; x<image->width; x++) {
*(dr++) = *(r++);
*(dg++) = *(g++);
*(db++) = *(b++);
*(dr++) = *(r++);
*(dg++) = *(g++);
*(db++) = *(b++);
}
w = image->width;
for (y=1; y<image->height-1; y++) {
dr[w-1] = r[w-1];
dg[w-1] = g[w-1];
db[w-1] = b[w-1];
dr[w-1] = r[w-1];
dg[w-1] = g[w-1];
db[w-1] = b[w-1];
*(dr++) = *(r++);
*(dg++) = *(g++);
*(db++) = *(b++);
for (x=1; x<image->width-1; x++) {
d1 = r[w+1] - r[-w-1];
d2 = r[1] - r[-1];
d3 = r[-w+1] - r[w-1];
d4 = r[-w] - r[w];
*(dr++) = *(r++);
*(dg++) = *(g++);
*(db++) = *(b++);
rsum = d1 + d2 + d3;
if (rsum < 0) rsum = -rsum;
d1 = d1 - d2 - d4; /* vertical gradient */
if (d1 < 0) d1 = -d1;
if (d1 > rsum) rsum = d1;
rsum /= 3;
*(dr++) = rsum;
d1 = g[w+1] - g[-w-1];
d2 = g[1] - g[-1];
d3 = g[-w+1] - g[w-1];
d4 = g[-w] - g[w];
for (x=1; x<image->width-1; x++) {
d1 = r[w+1] - r[-w-1];
d2 = r[1] - r[-1];
d3 = r[-w+1] - r[w-1];
d4 = r[-w] - r[w];
rsum = d1 + d2 + d3;
if (rsum < 0) rsum = -rsum;
d1 = d1 - d2 - d4; /* vertical gradient */
if (d1 < 0) d1 = -d1;
if (d1 > rsum) rsum = d1;
rsum /= 3;
*(dg++) = rsum;
rsum = d1 + d2 + d3;
if (rsum < 0) rsum = -rsum;
d1 = d1 - d2 - d4; /* vertical gradient */
if (d1 < 0) d1 = -d1;
if (d1 > rsum) rsum = d1;
rsum /= 3;
d1 = b[w+1] - b[-w-1];
d2 = b[1] - b[-1];
d3 = b[-w+1] - b[w-1];
d4 = b[-w] - b[w];
*(dr++) = rsum;
rsum = d1 + d2 + d3;
if (rsum < 0) rsum = -rsum;
d1 = d1 - d2 - d4; /* vertical gradient */
if (d1 < 0) d1 = -d1;
if (d1 > rsum) rsum = d1;
rsum /= 3;
*(db++) = rsum;
r++;
g++;
b++;
}
r++;
g++;
b++;
d1 = g[w+1] - g[-w-1];
d2 = g[1] - g[-1];
d3 = g[-w+1] - g[w-1];
d4 = g[-w] - g[w];
dr++;
dg++;
db++;
rsum = d1 + d2 + d3;
if (rsum < 0) rsum = -rsum;
d1 = d1 - d2 - d4; /* vertical gradient */
if (d1 < 0) d1 = -d1;
if (d1 > rsum) rsum = d1;
rsum /= 3;
*(dg++) = rsum;
d1 = b[w+1] - b[-w-1];
d2 = b[1] - b[-1];
d3 = b[-w+1] - b[w-1];
d4 = b[-w] - b[w];
rsum = d1 + d2 + d3;
if (rsum < 0) rsum = -rsum;
d1 = d1 - d2 - d4; /* vertical gradient */
if (d1 < 0) d1 = -d1;
if (d1 > rsum) rsum = d1;
rsum /= 3;
*(db++) = rsum;
r++;
g++;
b++;
}
r++;
g++;
b++;
dr++;
dg++;
db++;
}
{
r = image->data[0];
image2->data[0] = r;
g = image->data[1];
image2->data[1] = g;
b = image->data[2];
image2->data[2] = b;
RReleaseImage(image2);
r = image->data[0];
image2->data[0] = r;
g = image->data[1];
image2->data[1] = g;
b = image->data[2];
image2->data[2] = b;
RReleaseImage(image2);
}
#undef MASK
return True;
}
@@ -272,39 +272,40 @@ RSmoothImage(RImage *image)
w = image->width*ch;
for (y=0; y<image->height - 1; y++) {
for (x=0; x<image->width - 1; x++) {
v = *ptr + 2 * *(ptr + ch) + 2 * *(ptr + w) + *(ptr + w + ch);
*ptr = v/6;
v = *(ptr+1) + 2 * *(ptr+1 + ch) + 2 * *(ptr+1 + w) + *(ptr+1 + w + ch);
*(ptr+1) = v/6;
for (x=0; x<image->width - 1; x++) {
v = *ptr + 2 * *(ptr + ch) + 2 * *(ptr + w) + *(ptr + w + ch);
*ptr = v/6;
v = *(ptr+1) + 2 * *(ptr+1 + ch) + 2 * *(ptr+1 + w) + *(ptr+1 + w + ch);
*(ptr+1) = v/6;
v = *(ptr+2) + 2 * *(ptr+2 + ch) + 2 * *(ptr+2 + w) + *(ptr+2 + w + ch);
*(ptr+2) = v/6;
ptr+= ch;
}
/* last column */
v = 3 * *ptr + 3 * *(ptr + w);
*(ptr+2) = v/6;
ptr+= ch;
}
/* last column */
v = 3 * *ptr + 3 * *(ptr + w);
*ptr = v/6;
v = 3 * *(ptr+1) + 3 * *(ptr+1 + w);
v = 3 * *(ptr+1) + 3 * *(ptr+1 + w);
*(ptr+1) = v/6;
v = 3 * *(ptr+2) + 3 * *(ptr+2 + w);
*(ptr+2) = v/6;
ptr+= ch;
v = 3 * *(ptr+2) + 3 * *(ptr+2 + w);
*(ptr+2) = v/6;
ptr+= ch;
}
/* last line */
for (x=0; x<image->width - 1; x++) {
v = 3 * *ptr + 3 * *(ptr + ch);
*ptr = v/6;
v = 3 * *(ptr+1) + 3 * *(ptr+1 + ch);
*(ptr+1) = v/6;
v = 3 * *(ptr+2) + 3 * *(ptr+2 + ch);
*(ptr+2) = v/6;
ptr+= ch;
v = 3 * *ptr + 3 * *(ptr + ch);
*ptr = v/6;
v = 3 * *(ptr+1) + 3 * *(ptr+1 + ch);
*(ptr+1) = v/6;
v = 3 * *(ptr+2) + 3 * *(ptr+2 + ch);
*(ptr+2) = v/6;
ptr+= ch;
}
return True;
}
#endif

View File

@@ -1,7 +1,7 @@
/* draw.c - pixel plotting, line drawing
*
*
* Raster graphics library
*
*
* Copyright (c) 1998-2003 Dan Pascu
* Copyright (c) 2000-2003 Alfredo K. Kojima
*
@@ -9,12 +9,12 @@
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -44,22 +44,22 @@ RGetPixel(RImage *image, int x, int y, RColor *color)
assert(image!=NULL);
if (x < 0 || x >= image->width
|| y < 0 || y >= image->height)
return False;
|| y < 0 || y >= image->height)
return False;
if (image->format == RRGBAFormat) {
ofs = (y*image->width + x) * 4;
color->red = image->data[ofs++];
color->green = image->data[ofs++];
color->blue = image->data[ofs++];
color->alpha = image->data[ofs];
ofs = (y*image->width + x) * 4;
color->red = image->data[ofs++];
color->green = image->data[ofs++];
color->blue = image->data[ofs++];
color->alpha = image->data[ofs];
} else {
ofs = (y*image->width + x) * 3;
color->red = image->data[ofs++];
color->green = image->data[ofs++];
color->blue = image->data[ofs];
/* If the image does not have alpha channel, we consider alpha 255 */
color->alpha = 255;
ofs = (y*image->width + x) * 3;
color->red = image->data[ofs++];
color->green = image->data[ofs++];
color->blue = image->data[ofs];
/* If the image does not have alpha channel, we consider alpha 255 */
color->alpha = 255;
}
return True;
@@ -74,21 +74,21 @@ RPutPixel(RImage *image, int x, int y, RColor *color)
assert(image!=NULL);
assert(color!=NULL);
if (x < 0 || x >= image->width || y < 0 || y >= image->height)
return;
return;
if (image->format == RRGBAFormat) {
ptr = image->data + (y*image->width + x) * 4;
ptr = image->data + (y*image->width + x) * 4;
} else {
ptr = image->data + (y*image->width + x) * 3;
ptr = image->data + (y*image->width + x) * 3;
}
if (color->alpha==255) {
*ptr++ = color->red;
*ptr++ = color->red;
*ptr++ = color->green;
*ptr++ = color->blue;
if (image->format == RRGBAFormat) {
*ptr = 255;
}
if (image->format == RRGBAFormat) {
*ptr = 255;
}
} else {
register int alpha, nalpha, r, g, b;
@@ -103,7 +103,7 @@ RPutPixel(RImage *image, int x, int y, RColor *color)
*ptr = (((int)*ptr * nalpha) + (b * alpha))/256; ptr++;
if (image->format == RRGBAFormat) {
*ptr = alpha + ((int)*ptr * nalpha)/256;
}
}
}
}
@@ -122,55 +122,55 @@ operatePixel(RImage *image, int ofs, int operation, RColor *color)
sg = image->data + ofs*(hasAlpha ? 4 : 3) + 1;
sb = image->data + ofs*(hasAlpha ? 4 : 3) + 2;
sa = image->data + ofs*(hasAlpha ? 4 : 3) + 3;
switch (operation) {
case RClearOperation:
*sr = 0;
*sg = 0;
*sb = 0;
if (hasAlpha)
*sa = 0;
break;
case RCopyOperation:
*sr = color->red;
*sg = color->green;
*sb = color->blue;
if (hasAlpha)
*sa = color->alpha;
break;
case RNormalOperation:
if (color->alpha==255) {
*sr = color->red;
*sg = color->green;
*sb = color->blue;
if (hasAlpha)
*sa = 255;
} else {
*sr = (((int)*sr * nalpha) + ((int)color->red * alpha))/256;
*sg = (((int)*sg * nalpha) + ((int)color->green * alpha))/256;
*sb = (((int)*sb * nalpha) + ((int)color->blue * alpha))/256;
}
break;
case RAddOperation:
tmp = color->red + *sr;
*sr = MIN(255, tmp);
tmp = color->green + *sg;
*sg = MIN(255, tmp);
tmp = color->blue + *sb;
*sb = MIN(255, tmp);
if (hasAlpha)
*sa = MIN(*sa, color->alpha);
break;
case RSubtractOperation:
tmp = *sr - color->red;
*sr = MAX(0, tmp);
tmp = *sg - color->green;
*sg = MAX(0, tmp);
tmp = *sb - color->blue;
*sb = MAX(0, tmp);
if (hasAlpha)
*sa = MIN(*sa, color->alpha);
break;
case RClearOperation:
*sr = 0;
*sg = 0;
*sb = 0;
if (hasAlpha)
*sa = 0;
break;
case RCopyOperation:
*sr = color->red;
*sg = color->green;
*sb = color->blue;
if (hasAlpha)
*sa = color->alpha;
break;
case RNormalOperation:
if (color->alpha==255) {
*sr = color->red;
*sg = color->green;
*sb = color->blue;
if (hasAlpha)
*sa = 255;
} else {
*sr = (((int)*sr * nalpha) + ((int)color->red * alpha))/256;
*sg = (((int)*sg * nalpha) + ((int)color->green * alpha))/256;
*sb = (((int)*sb * nalpha) + ((int)color->blue * alpha))/256;
}
break;
case RAddOperation:
tmp = color->red + *sr;
*sr = MIN(255, tmp);
tmp = color->green + *sg;
*sg = MIN(255, tmp);
tmp = color->blue + *sb;
*sb = MIN(255, tmp);
if (hasAlpha)
*sa = MIN(*sa, color->alpha);
break;
case RSubtractOperation:
tmp = *sr - color->red;
*sr = MAX(0, tmp);
tmp = *sg - color->green;
*sg = MAX(0, tmp);
tmp = *sb - color->blue;
*sb = MAX(0, tmp);
if (hasAlpha)
*sa = MIN(*sa, color->alpha);
break;
}
}
@@ -187,7 +187,7 @@ ROperatePixel(RImage *image, int operation, int x, int y, RColor *color)
assert(y >= 0 && y < image->height);
ofs = y*image->width + x;
operatePixel(image, ofs, operation, color);
}
@@ -216,8 +216,8 @@ RPutPixels(RImage *image, RPoint *points, int npoints, int mode, RColor *color)
void
ROperatePixels(RImage *image, int operation, RPoint *points, int npoints,
int mode, RColor *color)
ROperatePixels(RImage *image, int operation, RPoint *points, int npoints,
int mode, RColor *color)
{
register int x, y, i;
@@ -241,14 +241,14 @@ ROperatePixels(RImage *image, int operation, RPoint *points, int npoints,
static Bool
clipLineInRectangle(int xmin, int ymin, int xmax, int ymax,
int *x1, int *y1, int *x2, int *y2)
int *x1, int *y1, int *x2, int *y2)
{
#define TOP (1<<0)
#define BOT (1<<1)
#define LEF (1<<2)
#define RIG (1<<3)
#define CHECK_OUT(X,Y) (((Y) > ymax ? TOP : ((Y) < ymin ? BOT : 0))\
| ((X) > xmax ? RIG : ((X) < xmin ? LEF : 0)))
| ((X) > xmax ? RIG : ((X) < xmin ? LEF : 0)))
int ocode1, ocode2, ocode;
int accept = 0;
@@ -258,43 +258,43 @@ clipLineInRectangle(int xmin, int ymin, int xmax, int ymax,
ocode2 = CHECK_OUT(*x2, *y2);
for(;;) {
if (!ocode1 && !ocode2) { /* completely inside */
accept = 1;
break;
} else if (ocode1 & ocode2) {
break;
}
if (!ocode1 && !ocode2) { /* completely inside */
accept = 1;
break;
} else if (ocode1 & ocode2) {
break;
}
if (ocode1)
ocode = ocode1;
else
ocode = ocode2;
if (ocode1)
ocode = ocode1;
else
ocode = ocode2;
if (ocode & TOP) {
x = *x1 + (*x2 - *x1) * (ymax - *y1) / (*y2 - *y1);
y = ymax;
} else if (ocode & BOT) {
x = *x1 + (*x2 - *x1) * (ymin - *y1) / (*y2 - *y1);
y = ymin;
} else if (ocode & RIG) {
y = *y1 + (*y2 - *y1) * (xmax - *x1) / (*x2 - *x1);
x = xmax;
if (ocode & TOP) {
x = *x1 + (*x2 - *x1) * (ymax - *y1) / (*y2 - *y1);
y = ymax;
} else if (ocode & BOT) {
x = *x1 + (*x2 - *x1) * (ymin - *y1) / (*y2 - *y1);
y = ymin;
} else if (ocode & RIG) {
y = *y1 + (*y2 - *y1) * (xmax - *x1) / (*x2 - *x1);
x = xmax;
} else { //if (ocode & LEF) {
y = *y1 + (*y2 - *y1) * (xmax - *x1) / (*x2 - *x1);
x = xmin;
}
y = *y1 + (*y2 - *y1) * (xmax - *x1) / (*x2 - *x1);
x = xmin;
}
if (ocode == ocode1) {
*x1 = x;
*y1 = y;
ocode1 = CHECK_OUT(x, y);
} else {
*x2 = x;
*y2 = y;
ocode2 = CHECK_OUT(x, y);
}
if (ocode == ocode1) {
*x1 = x;
*y1 = y;
ocode1 = CHECK_OUT(x, y);
} else {
*x2 = x;
*y2 = y;
ocode2 = CHECK_OUT(x, y);
}
}
return accept;
}
@@ -312,8 +312,8 @@ genericLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color,
assert(image!=NULL);
if (!clipLineInRectangle(0, 0, image->width-1, image->height-1,
&x0, &y0, &x1, &y1))
return True;
&x0, &y0, &x1, &y1))
return True;
if (x0 < x1) {
du = x1 - x0;
@@ -342,53 +342,53 @@ genericLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color,
last = (polyline) ? du-1 : du;
if (color->alpha==255 || operation==RCopyOperation) {
unsigned char *ptr;
unsigned char *ptr;
if (image->format == RRGBAFormat)
i = (y0*image->width + x0) * 4;
else
i = (y0*image->width + x0) * 3;
ptr = image->data + i;
if (image->format == RRGBAFormat)
i = (y0*image->width + x0) * 4;
else
i = (y0*image->width + x0) * 3;
ptr = image->data + i;
for (i=0; i<=last; i++) {
/* Draw the pixel */
*ptr = color->red;
*(ptr+1) = color->green;
*(ptr+2) = color->blue;
if (image->format == RRGBAFormat)
*(ptr+3) = 255;
for (i=0; i<=last; i++) {
/* Draw the pixel */
*ptr = color->red;
*(ptr+1) = color->green;
*(ptr+2) = color->blue;
if (image->format == RRGBAFormat)
*(ptr+3) = 255;
/* Compute error for NeXT Step */
err += dv2;
if (err >= du) {
if (image->format == RRGBAFormat)
ptr += vofs*4;
else
ptr += vofs*3;
err -= du2;
}
if (image->format == RRGBAFormat)
ptr += uofs*4;
else
ptr += uofs*3;
}
/* Compute error for NeXT Step */
err += dv2;
if (err >= du) {
if (image->format == RRGBAFormat)
ptr += vofs*4;
else
ptr += vofs*3;
err -= du2;
}
if (image->format == RRGBAFormat)
ptr += uofs*4;
else
ptr += uofs*3;
}
} else {
register int ofs = y0*image->width + x0;
for (i=0; i<=last; i++) {
/* Draw the pixel */
operatePixel(image, ofs, operation, color);
/* Compute error for NeXT Step */
err += dv2;
if (err >= du) {
ofs += vofs;
err -= du2;
}
ofs += uofs;
}
register int ofs = y0*image->width + x0;
for (i=0; i<=last; i++) {
/* Draw the pixel */
operatePixel(image, ofs, operation, color);
/* Compute error for NeXT Step */
err += dv2;
if (err >= du) {
ofs += vofs;
err -= du2;
}
ofs += uofs;
}
}
#if 0
if (mode == RALTER_PIXELS) {
RColorOffset *cdelta = (RColorOffset*)cdata;
@@ -485,8 +485,8 @@ RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color)
int
ROperateLine(RImage *image, int operation, int x0, int y0, int x1,
int y1, RColor *color)
ROperateLine(RImage *image, int operation, int x0, int y0, int x1,
int y1, RColor *color)
{
return genericLine(image, x0, y0, x1, y1, color, operation, False);
}
@@ -534,7 +534,7 @@ RDrawLines(RImage *image, RPoint *points, int npoints, int mode, RColor *color)
void
ROperateLines(RImage *image, int operation, RPoint *points,
int npoints, int mode, RColor *color)
int npoints, int mode, RColor *color)
{
register int x1, y1, x2, y2, i;
@@ -589,8 +589,8 @@ RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color)
void
ROperateSegments(RImage *image, int operation, RSegment *segs,
int nsegs, RColor *color)
ROperateSegments(RImage *image, int operation, RSegment *segs,
int nsegs, RColor *color)
{
register int i;

View File

@@ -1,19 +1,19 @@
/* gif.c - load GIF image from file
*
*
* Raster graphics library
*
*
* Copyright (c) 1998-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -56,7 +56,7 @@ RLoadGIF(RContext *context, char *file, int index)
unsigned char bmap[256];
if (index < 0)
index = 0;
index = 0;
/* default error message */
RErrorCode = RERR_BADINDEX;
@@ -64,168 +64,169 @@ RLoadGIF(RContext *context, char *file, int index)
gif = DGifOpenFileName(file);
if (!gif) {
switch (GifLastError()) {
case D_GIF_ERR_OPEN_FAILED:
RErrorCode = RERR_OPEN;
break;
case D_GIF_ERR_READ_FAILED:
RErrorCode = RERR_READ;
break;
default:
RErrorCode = RERR_BADIMAGEFILE;
break;
}
return NULL;
switch (GifLastError()) {
case D_GIF_ERR_OPEN_FAILED:
RErrorCode = RERR_OPEN;
break;
case D_GIF_ERR_READ_FAILED:
RErrorCode = RERR_READ;
break;
default:
RErrorCode = RERR_BADIMAGEFILE;
break;
}
return NULL;
}
if (gif->SWidth<1 || gif->SHeight<1) {
DGifCloseFile(gif);
RErrorCode = RERR_BADIMAGEFILE;
RErrorCode = RERR_BADIMAGEFILE;
return NULL;
}
colormap = gif->SColorMap;
i = 0;
do {
int extCode;
GifByteType *extension;
int extCode;
GifByteType *extension;
if (DGifGetRecordType(gif, &recType) == GIF_ERROR) {
goto giferr;
}
switch (recType) {
case IMAGE_DESC_RECORD_TYPE:
if (i++ != index)
break;
if (DGifGetRecordType(gif, &recType) == GIF_ERROR) {
goto giferr;
}
switch (recType) {
case IMAGE_DESC_RECORD_TYPE:
if (i++ != index)
break;
if (DGifGetImageDesc(gif)==GIF_ERROR) {
goto giferr;
}
width = gif->Image.Width;
height = gif->Image.Height;
if (gif->Image.ColorMap)
colormap = gif->Image.ColorMap;
if (DGifGetImageDesc(gif)==GIF_ERROR) {
goto giferr;
}
/* the gif specs talk about a default colormap, but it
* doesnt say what the heck is this default colormap */
if (!colormap) {
/*
* Well, since the spec says the colormap can be anything,
* lets just render it with whatever garbage the stack
* has :)
*
goto bye;
*/
} else {
for (j = 0; j < colormap->ColorCount; j++) {
rmap[j] = colormap->Colors[j].Red;
gmap[j] = colormap->Colors[j].Green;
bmap[j] = colormap->Colors[j].Blue;
}
}
width = gif->Image.Width;
height = gif->Image.Height;
buffer = malloc(width * sizeof(GifColorType));
if (!buffer) {
RErrorCode = RERR_NOMEMORY;
goto bye;
}
if (gif->Image.ColorMap)
colormap = gif->Image.ColorMap;
image = RCreateImage(width, height, False);
if (!image) {
goto bye;
}
/* the gif specs talk about a default colormap, but it
* doesnt say what the heck is this default colormap */
if (!colormap) {
/*
* Well, since the spec says the colormap can be anything,
* lets just render it with whatever garbage the stack
* has :)
*
if (gif->Image.Interlace) {
int l;
int pelsPerLine;
goto bye;
*/
} else {
for (j = 0; j < colormap->ColorCount; j++) {
rmap[j] = colormap->Colors[j].Red;
gmap[j] = colormap->Colors[j].Green;
bmap[j] = colormap->Colors[j].Blue;
}
}
if (RRGBAFormat==image->format)
pelsPerLine = width * 4;
else
pelsPerLine = width * 3;
buffer = malloc(width * sizeof(GifColorType));
if (!buffer) {
RErrorCode = RERR_NOMEMORY;
goto bye;
}
for (j = 0; j < 4; j++) {
for (k = InterlacedOffset[j]; k < height;
k += InterlacedJumps[j]) {
if (DGifGetLine(gif, buffer, width)==GIF_ERROR) {
goto giferr;
}
cptr = image->data + (k*pelsPerLine);
for (l = 0; l < width; l++) {
int pixel = buffer[l];
*cptr++ = rmap[pixel];
*cptr++ = gmap[pixel];
*cptr++ = bmap[pixel];
}
}
}
} else {
cptr = image->data;
for (j = 0; j < height; j++) {
if (DGifGetLine(gif, buffer, width)==GIF_ERROR) {
goto giferr;
}
for (k = 0; k < width; k++) {
int pixel = buffer[k];
*cptr++ = rmap[pixel];
*cptr++ = gmap[pixel];
*cptr++ = bmap[pixel];
if (RRGBAFormat==image->format)
cptr++;
}
}
}
break;
image = RCreateImage(width, height, False);
if (!image) {
goto bye;
}
case EXTENSION_RECORD_TYPE:
/* skip all extension blocks */
if (DGifGetExtension(gif, &extCode, &extension)==GIF_ERROR) {
goto giferr;
}
while (extension) {
if (DGifGetExtensionNext(gif, &extension)==GIF_ERROR) {
goto giferr;
}
}
break;
if (gif->Image.Interlace) {
int l;
int pelsPerLine;
default:
break;
}
if (RRGBAFormat==image->format)
pelsPerLine = width * 4;
else
pelsPerLine = width * 3;
for (j = 0; j < 4; j++) {
for (k = InterlacedOffset[j]; k < height;
k += InterlacedJumps[j]) {
if (DGifGetLine(gif, buffer, width)==GIF_ERROR) {
goto giferr;
}
cptr = image->data + (k*pelsPerLine);
for (l = 0; l < width; l++) {
int pixel = buffer[l];
*cptr++ = rmap[pixel];
*cptr++ = gmap[pixel];
*cptr++ = bmap[pixel];
}
}
}
} else {
cptr = image->data;
for (j = 0; j < height; j++) {
if (DGifGetLine(gif, buffer, width)==GIF_ERROR) {
goto giferr;
}
for (k = 0; k < width; k++) {
int pixel = buffer[k];
*cptr++ = rmap[pixel];
*cptr++ = gmap[pixel];
*cptr++ = bmap[pixel];
if (RRGBAFormat==image->format)
cptr++;
}
}
}
break;
case EXTENSION_RECORD_TYPE:
/* skip all extension blocks */
if (DGifGetExtension(gif, &extCode, &extension)==GIF_ERROR) {
goto giferr;
}
while (extension) {
if (DGifGetExtensionNext(gif, &extension)==GIF_ERROR) {
goto giferr;
}
}
break;
default:
break;
}
} while (recType != TERMINATE_RECORD_TYPE && i <= index);
/* yuck! */
goto did_not_get_any_errors;
giferr:
switch (GifLastError()) {
case D_GIF_ERR_OPEN_FAILED:
RErrorCode = RERR_OPEN;
break;
case D_GIF_ERR_READ_FAILED:
RErrorCode = RERR_READ;
break;
default:
RErrorCode = RERR_BADIMAGEFILE;
break;
case D_GIF_ERR_OPEN_FAILED:
RErrorCode = RERR_OPEN;
break;
case D_GIF_ERR_READ_FAILED:
RErrorCode = RERR_READ;
break;
default:
RErrorCode = RERR_BADIMAGEFILE;
break;
}
bye:
if (image)
RReleaseImage(image);
RReleaseImage(image);
image = NULL;
did_not_get_any_errors:
if (buffer)
free(buffer);
free(buffer);
if (gif)
DGifCloseFile(gif);
DGifCloseFile(gif);
return image;
}
#endif /* USE_GIF */

View File

@@ -9,12 +9,12 @@
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -31,22 +31,22 @@
#include "wraster.h"
static RImage *renderHGradient(unsigned width, unsigned height,
int r0, int g0, int b0,
int rf, int gf, int bf);
static RImage *renderVGradient(unsigned width, unsigned height,
int r0, int g0, int b0,
int rf, int gf, int bf);
static RImage *renderDGradient(unsigned width, unsigned height,
int r0, int g0, int b0,
int rf, int gf, int bf);
static RImage *renderHGradient(unsigned width, unsigned height,
int r0, int g0, int b0,
int rf, int gf, int bf);
static RImage *renderVGradient(unsigned width, unsigned height,
int r0, int g0, int b0,
int rf, int gf, int bf);
static RImage *renderDGradient(unsigned width, unsigned height,
int r0, int g0, int b0,
int rf, int gf, int bf);
static RImage *renderMHGradient(unsigned width, unsigned height,
RColor **colors, int count);
static RImage *renderMHGradient(unsigned width, unsigned height,
RColor **colors, int count);
static RImage *renderMVGradient(unsigned width, unsigned height,
RColor **colors, int count);
static RImage *renderMDGradient(unsigned width, unsigned height,
RColor **colors, int count);
RColor **colors, int count);
static RImage *renderMDGradient(unsigned width, unsigned height,
RColor **colors, int count);
RImage*
RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, int style)
@@ -57,18 +57,18 @@ RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, int style
while (colors[count]!=NULL) count++;
if (count > 2) {
switch (style) {
case RHorizontalGradient:
return renderMHGradient(width, height, colors, count);
case RVerticalGradient:
return renderMVGradient(width, height, colors, count);
case RDiagonalGradient:
return renderMDGradient(width, height, colors, count);
}
switch (style) {
case RHorizontalGradient:
return renderMHGradient(width, height, colors, count);
case RVerticalGradient:
return renderMVGradient(width, height, colors, count);
case RDiagonalGradient:
return renderMDGradient(width, height, colors, count);
}
} else if (count > 1) {
return RRenderGradient(width, height, colors[0], colors[1], style);
return RRenderGradient(width, height, colors[0], colors[1], style);
} else if (count > 0) {
return RRenderGradient(width, height, colors[0], colors[0], style);
return RRenderGradient(width, height, colors[0], colors[0], style);
}
assert(0);
return NULL;
@@ -77,20 +77,20 @@ RRenderMultiGradient(unsigned width, unsigned height, RColor **colors, int style
RImage*
RRenderGradient(unsigned width, unsigned height, RColor *from, RColor *to,
int style)
RRenderGradient(unsigned width, unsigned height, RColor *from, RColor *to,
int style)
{
switch (style) {
case RHorizontalGradient:
return renderHGradient(width, height, from->red, from->green,
from->blue, to->red, to->green, to->blue);
case RVerticalGradient:
return renderVGradient(width, height, from->red, from->green,
from->blue, to->red, to->green, to->blue);
case RHorizontalGradient:
return renderHGradient(width, height, from->red, from->green,
from->blue, to->red, to->green, to->blue);
case RVerticalGradient:
return renderVGradient(width, height, from->red, from->green,
from->blue, to->red, to->green, to->blue);
case RDiagonalGradient:
return renderDGradient(width, height, from->red, from->green,
from->blue, to->red, to->green, to->blue);
case RDiagonalGradient:
return renderDGradient(width, height, from->red, from->green,
from->blue, to->red, to->green, to->blue);
}
assert(0);
return NULL;
@@ -101,19 +101,19 @@ RRenderGradient(unsigned width, unsigned height, RColor *from, RColor *to,
*----------------------------------------------------------------------
* renderHGradient--
* Renders a horizontal linear gradient of the specified size in the
* RImage format with a border of the specified type.
*
* RImage format with a border of the specified type.
*
* Returns:
* A 24bit RImage with the gradient (no alpha channel).
*
*
* Side effects:
* None
*----------------------------------------------------------------------
*----------------------------------------------------------------------
*/
static RImage*
renderHGradient(unsigned width, unsigned height, int r0, int g0, int b0,
int rf, int gf, int bf)
{
renderHGradient(unsigned width, unsigned height, int r0, int g0, int b0,
int rf, int gf, int bf)
{
int i;
long r, g, b, dr, dg, db;
unsigned lineSize = width*3;
@@ -122,30 +122,30 @@ renderHGradient(unsigned width, unsigned height, int r0, int g0, int b0,
image = RCreateImage(width, height, False);
if (!image) {
return NULL;
return NULL;
}
ptr = image->data;
r = r0 << 16;
g = g0 << 16;
b = b0 << 16;
dr = ((rf-r0)<<16)/(int)width;
dg = ((gf-g0)<<16)/(int)width;
db = ((bf-b0)<<16)/(int)width;
/* render the first line */
for (i=0; i<width; i++) {
*(ptr++) = (unsigned char)(r>>16);
*(ptr++) = (unsigned char)(g>>16);
*(ptr++) = (unsigned char)(b>>16);
r += dr;
g += dg;
b += db;
*(ptr++) = (unsigned char)(r>>16);
*(ptr++) = (unsigned char)(g>>16);
*(ptr++) = (unsigned char)(b>>16);
r += dr;
g += dg;
b += db;
}
/* copy the first line to the other lines */
for (i=1; i<height; i++) {
memcpy(&(image->data[i*lineSize]), image->data, lineSize);
memcpy(&(image->data[i*lineSize]), image->data, lineSize);
}
return image;
}
@@ -167,7 +167,7 @@ renderHGradient(unsigned width, unsigned height, int r0, int g0, int b0,
*/
static RImage*
renderVGradient(unsigned width, unsigned height, int r0, int g0, int b0,
int rf, int gf, int bf)
int rf, int gf, int bf)
{
int i, j;
long r, g, b, dr, dg, db;
@@ -177,8 +177,8 @@ renderVGradient(unsigned width, unsigned height, int r0, int g0, int b0,
image = RCreateImage(width, height, False);
if (!image) {
return NULL;
}
return NULL;
}
ptr = image->data;
r = r0<<16;
@@ -190,28 +190,28 @@ renderVGradient(unsigned width, unsigned height, int r0, int g0, int b0,
db = ((bf-b0)<<16)/(int)height;
for (i=0; i<height; i++) {
rr = r>>16;
gg = g>>16;
bb = b>>16;
for (j=0; j<width/8; j++) {
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
switch (width%8) {
case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
rr = r>>16;
gg = g>>16;
bb = b>>16;
for (j=0; j<width/8; j++) {
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
switch (width%8) {
case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
r+=dr;
g+=dg;
b+=db;
@@ -237,7 +237,7 @@ renderVGradient(unsigned width, unsigned height, int r0, int g0, int b0,
static RImage*
renderDGradient(unsigned width, unsigned height, int r0, int g0, int b0,
int rf, int gf, int bf)
int rf, int gf, int bf)
{
RImage *image, *tmp;
int j;
@@ -267,7 +267,7 @@ renderDGradient(unsigned width, unsigned height, int r0, int g0, int b0,
/* copy the first line to the other lines with corresponding offset */
for (j=0, offset=0.0; j<width*height; j += width) {
memcpy(&(image->data[j]), &ptr[3*(int)offset], width);
memcpy(&(image->data[j]), &ptr[3*(int)offset], width);
offset += a;
}
@@ -285,24 +285,24 @@ renderMHGradient(unsigned width, unsigned height, RColor **colors, int count)
RImage *image;
unsigned char *ptr;
unsigned width2;
assert(count > 2);
image = RCreateImage(width, height, False);
if (!image) {
return NULL;
return NULL;
}
ptr = image->data;
if (count > width)
count = width;
count = width;
if (count > 1)
width2 = width/(count-1);
else
width2 = width;
k = 0;
r = colors[0]->red << 16;
@@ -311,31 +311,31 @@ renderMHGradient(unsigned width, unsigned height, RColor **colors, int count)
/* render the first line */
for (i=1; i<count; i++) {
dr = ((int)(colors[i]->red - colors[i-1]->red) <<16)/(int)width2;
dg = ((int)(colors[i]->green - colors[i-1]->green)<<16)/(int)width2;
db = ((int)(colors[i]->blue - colors[i-1]->blue) <<16)/(int)width2;
for (j=0; j<width2; j++) {
*ptr++ = (unsigned char)(r>>16);
*ptr++ = (unsigned char)(g>>16);
*ptr++ = (unsigned char)(b>>16);
r += dr;
g += dg;
b += db;
k++;
}
r = colors[i]->red << 16;
g = colors[i]->green << 16;
b = colors[i]->blue << 16;
dr = ((int)(colors[i]->red - colors[i-1]->red) <<16)/(int)width2;
dg = ((int)(colors[i]->green - colors[i-1]->green)<<16)/(int)width2;
db = ((int)(colors[i]->blue - colors[i-1]->blue) <<16)/(int)width2;
for (j=0; j<width2; j++) {
*ptr++ = (unsigned char)(r>>16);
*ptr++ = (unsigned char)(g>>16);
*ptr++ = (unsigned char)(b>>16);
r += dr;
g += dg;
b += db;
k++;
}
r = colors[i]->red << 16;
g = colors[i]->green << 16;
b = colors[i]->blue << 16;
}
for (j=k; j<width; j++) {
*ptr++ = (unsigned char)(r>>16);
*ptr++ = (unsigned char)(g>>16);
*ptr++ = (unsigned char)(b>>16);
*ptr++ = (unsigned char)(r>>16);
*ptr++ = (unsigned char)(g>>16);
*ptr++ = (unsigned char)(b>>16);
}
/* copy the first line to the other lines */
for (i=1; i<height; i++) {
memcpy(&(image->data[i*lineSize]), image->data, lineSize);
memcpy(&(image->data[i*lineSize]), image->data, lineSize);
}
return image;
}
@@ -354,24 +354,24 @@ renderMVGradient(unsigned width, unsigned height, RColor **colors, int count)
unsigned height2;
int x;
unsigned char rr, gg, bb;
assert(count > 2);
image = RCreateImage(width, height, False);
if (!image) {
return NULL;
return NULL;
}
ptr = image->data;
if (count > height)
count = height;
count = height;
if (count > 1)
height2 = height/(count-1);
else
height2 = height;
k = 0;
r = colors[0]->red << 16;
@@ -379,34 +379,34 @@ renderMVGradient(unsigned width, unsigned height, RColor **colors, int count)
b = colors[0]->blue << 16;
for (i=1; i<count; i++) {
dr = ((int)(colors[i]->red - colors[i-1]->red) <<16)/(int)height2;
dg = ((int)(colors[i]->green - colors[i-1]->green)<<16)/(int)height2;
db = ((int)(colors[i]->blue - colors[i-1]->blue) <<16)/(int)height2;
dr = ((int)(colors[i]->red - colors[i-1]->red) <<16)/(int)height2;
dg = ((int)(colors[i]->green - colors[i-1]->green)<<16)/(int)height2;
db = ((int)(colors[i]->blue - colors[i-1]->blue) <<16)/(int)height2;
for (j=0; j<height2; j++) {
rr = r>>16;
gg = g>>16;
bb = b>>16;
for (j=0; j<height2; j++) {
rr = r>>16;
gg = g>>16;
bb = b>>16;
for (x=0; x<width/4; x++) {
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
}
switch (width%4) {
case 3: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
case 2: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
case 1: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
}
r += dr;
g += dg;
b += db;
k++;
}
r = colors[i]->red << 16;
g = colors[i]->green << 16;
b = colors[i]->blue << 16;
for (x=0; x<width/4; x++) {
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
*ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
}
switch (width%4) {
case 3: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
case 2: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
case 1: *ptr++ = rr; *ptr++ = gg; *ptr++ = bb;
}
r += dr;
g += dg;
b += db;
k++;
}
r = colors[i]->red << 16;
g = colors[i]->green << 16;
b = colors[i]->blue << 16;
}
rr = r>>16;
@@ -433,7 +433,7 @@ renderMVGradient(unsigned width, unsigned height, RColor **colors, int count)
ptr += lineSize;
}
}
return image;
}
@@ -462,14 +462,14 @@ renderMDGradient(unsigned width, unsigned height, RColor **colors, int count)
count = width;
if (count > height)
count = height;
if (count > 2)
tmp = renderMHGradient(2*width-1, 1, colors, count);
tmp = renderMHGradient(2*width-1, 1, colors, count);
else
tmp = renderHGradient(2*width-1, 1, colors[0]->red<<8,
colors[0]->green<<8, colors[0]->blue<<8,
colors[1]->red<<8, colors[1]->green<<8,
colors[1]->blue<<8);
tmp = renderHGradient(2*width-1, 1, colors[0]->red<<8,
colors[0]->green<<8, colors[0]->blue<<8,
colors[1]->red<<8, colors[1]->green<<8,
colors[1]->blue<<8);
if (!tmp) {
RReleaseImage(image);
@@ -482,7 +482,7 @@ renderMDGradient(unsigned width, unsigned height, RColor **colors, int count)
/* copy the first line to the other lines with corresponding offset */
for (j=0, offset=0; j<width*height; j += width) {
memcpy(&(image->data[j]), &ptr[3*(int)offset], width);
memcpy(&(image->data[j]), &ptr[3*(int)offset], width);
offset += a;
}
RReleaseImage(tmp);
@@ -506,8 +506,8 @@ RRenderInterwovenGradient(unsigned width, unsigned height,
image = RCreateImage(width, height, False);
if (!image) {
return NULL;
}
return NULL;
}
ptr = image->data;
r1 = colors1[0].red<<16;
@@ -527,51 +527,51 @@ RRenderInterwovenGradient(unsigned width, unsigned height,
db2 = ((colors2[1].blue-colors2[0].blue)<<16)/(int)height;
for (i=0,k=0,l=0,ll=thickness1; i<height; i++) {
if (k == 0) {
rr = r1>>16;
gg = g1>>16;
bb = b1>>16;
} else {
rr = r2>>16;
gg = g2>>16;
bb = b2>>16;
}
for (j=0; j<width/8; j++) {
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
switch (width%8) {
case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
if (++l == ll) {
if (k == 0) {
k = 1;
ll = thickness2;
} else {
k = 0;
ll = thickness1;
}
l = 0;
}
r1+=dr1;
g1+=dg1;
b1+=db1;
r2+=dr2;
g2+=dg2;
b2+=db2;
if (k == 0) {
rr = r1>>16;
gg = g1>>16;
bb = b1>>16;
} else {
rr = r2>>16;
gg = g2>>16;
bb = b2>>16;
}
for (j=0; j<width/8; j++) {
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
*(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
switch (width%8) {
case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
}
if (++l == ll) {
if (k == 0) {
k = 1;
ll = thickness2;
} else {
k = 0;
ll = thickness1;
}
l = 0;
}
r1+=dr1;
g1+=dg1;
b1+=db1;
r2+=dr2;
g2+=dg2;
b2+=db2;
}
return image;
}

View File

@@ -1,19 +1,19 @@
/* jpeg.c - load JPEG image from file
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -68,9 +68,9 @@
*/
struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
jmp_buf setjmp_buffer; /* for return to caller */
};
typedef struct my_error_mgr * my_error_ptr;
@@ -82,15 +82,15 @@ typedef struct my_error_mgr * my_error_ptr;
static void
my_error_exit(j_common_ptr cinfo)
{
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
my_error_ptr myerr = (my_error_ptr) cinfo->err;
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
my_error_ptr myerr = (my_error_ptr) cinfo->err;
/* Always display the message. */
/* We could postpone this until after returning, if we chose. */
(*cinfo->err->output_message) (cinfo);
/* Always display the message. */
/* We could postpone this until after returning, if we chose. */
(*cinfo->err->output_message) (cinfo);
/* Return control to the setjmp point */
longjmp(myerr->setjmp_buffer, 1);
/* Return control to the setjmp point */
longjmp(myerr->setjmp_buffer, 1);
}
@@ -111,41 +111,41 @@ RLoadJPEG(RContext *context, char *file_name, int index)
file = fopen(file_name, "rb");
if (!file) {
RErrorCode = RERR_OPEN;
return NULL;
RErrorCode = RERR_OPEN;
return NULL;
}
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(&cinfo);
fclose(file);
return NULL;
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(&cinfo);
fclose(file);
return NULL;
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, file);
jpeg_read_header(&cinfo, TRUE);
if (cinfo.image_width < 1 || cinfo.image_height < 1) {
RErrorCode = RERR_BADIMAGEFILE;
goto bye;
RErrorCode = RERR_BADIMAGEFILE;
goto bye;
}
bptr = buffer[0] = (JSAMPROW)malloc(cinfo.image_width*cinfo.num_components);
if (!buffer[0]) {
RErrorCode = RERR_NOMEMORY;
goto bye;
RErrorCode = RERR_NOMEMORY;
goto bye;
}
if(cinfo.jpeg_color_space==JCS_GRAYSCALE) {
cinfo.out_color_space=JCS_GRAYSCALE;
cinfo.out_color_space=JCS_GRAYSCALE;
} else
cinfo.out_color_space = JCS_RGB;
cinfo.quantize_colors = FALSE;
@@ -154,62 +154,63 @@ RLoadJPEG(RContext *context, char *file_name, int index)
jpeg_calc_output_dimensions(&cinfo);
if (context->flags.optimize_for_speed)
image = RCreateImage(cinfo.image_width, cinfo.image_height, True);
image = RCreateImage(cinfo.image_width, cinfo.image_height, True);
else
image = RCreateImage(cinfo.image_width, cinfo.image_height, False);
image = RCreateImage(cinfo.image_width, cinfo.image_height, False);
if (!image) {
RErrorCode = RERR_NOMEMORY;
goto bye;
RErrorCode = RERR_NOMEMORY;
goto bye;
}
jpeg_start_decompress(&cinfo);
ptr = image->data;
if (cinfo.out_color_space==JCS_RGB) {
if (context->flags.optimize_for_speed) {
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
bptr = buffer[0];
for (i=0; i<cinfo.image_width; i++) {
*ptr++ = *bptr++;
*ptr++ = *bptr++;
*ptr++ = *bptr++;
ptr++; /* skip alpha channel */
}
}
} else {
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
bptr = buffer[0];
memcpy(ptr, bptr, cinfo.image_width*3);
ptr += cinfo.image_width*3;
}
}
if (context->flags.optimize_for_speed) {
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
bptr = buffer[0];
for (i=0; i<cinfo.image_width; i++) {
*ptr++ = *bptr++;
*ptr++ = *bptr++;
*ptr++ = *bptr++;
ptr++; /* skip alpha channel */
}
}
} else {
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
bptr = buffer[0];
memcpy(ptr, bptr, cinfo.image_width*3);
ptr += cinfo.image_width*3;
}
}
} else {
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
bptr = buffer[0];
for (i=0; i<cinfo.image_width; i++) {
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buffer,(JDIMENSION) 1);
bptr = buffer[0];
for (i=0; i<cinfo.image_width; i++) {
*ptr++ = *bptr;
*ptr++ = *bptr;
*ptr++ = *bptr++;
}
}
}
}
}
jpeg_finish_decompress(&cinfo);
bye:
bye:
jpeg_destroy_decompress(&cinfo);
fclose(file);
if (buffer[0])
free(buffer[0]);
free(buffer[0]);
return image;
}
#endif /* USE_JPEG */

View File

@@ -1,19 +1,19 @@
/* load.c - load image from file
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -136,26 +136,26 @@ static void
init_cache()
{
char *tmp;
tmp = getenv("RIMAGE_CACHE");
if (!tmp || sscanf(tmp, "%i", &RImageCacheSize)!=1) {
RImageCacheSize = IMAGE_CACHE_SIZE;
RImageCacheSize = IMAGE_CACHE_SIZE;
}
if (RImageCacheSize<0)
RImageCacheSize = 0;
RImageCacheSize = 0;
tmp = getenv("RIMAGE_CACHE_SIZE");
if (!tmp || sscanf(tmp, "%i", &RImageCacheMaxImage)!=1) {
RImageCacheMaxImage = IMAGE_CACHE_MAX_IMAGE;
RImageCacheMaxImage = IMAGE_CACHE_MAX_IMAGE;
}
if (RImageCacheSize>0) {
RImageCache = malloc(sizeof(RCachedImage)*RImageCacheSize);
if (RImageCache==NULL) {
printf("wrlib: out of memory for image cache\n");
return;
}
memset(RImageCache, 0, sizeof(RCachedImage)*RImageCacheSize);
RImageCache = malloc(sizeof(RCachedImage)*RImageCacheSize);
if (RImageCache==NULL) {
printf("wrlib: out of memory for image cache\n");
return;
}
memset(RImageCache, 0, sizeof(RCachedImage)*RImageCacheSize);
}
}
@@ -170,111 +170,111 @@ RLoadImage(RContext *context, char *file, int index)
assert(file!=NULL);
if (RImageCacheSize<0) {
init_cache();
init_cache();
}
if (RImageCacheSize>0) {
for (i=0; i<RImageCacheSize; i++) {
if (RImageCache[i].file
&& strcmp(file, RImageCache[i].file)==0) {
if (stat(file, &st)==0
&& st.st_mtime == RImageCache[i].last_modif) {
RImageCache[i].last_use = time(NULL);
return RCloneImage(RImageCache[i].image);
} else {
free(RImageCache[i].file);
RImageCache[i].file = NULL;
RReleaseImage(RImageCache[i].image);
}
}
}
for (i=0; i<RImageCacheSize; i++) {
if (RImageCache[i].file
&& strcmp(file, RImageCache[i].file)==0) {
if (stat(file, &st)==0
&& st.st_mtime == RImageCache[i].last_modif) {
RImageCache[i].last_use = time(NULL);
return RCloneImage(RImageCache[i].image);
} else {
free(RImageCache[i].file);
RImageCache[i].file = NULL;
RReleaseImage(RImageCache[i].image);
}
}
}
}
switch (identFile(file)) {
case IM_ERROR:
return NULL;
case IM_ERROR:
return NULL;
case IM_UNKNOWN:
RErrorCode = RERR_BADFORMAT;
return NULL;
case IM_UNKNOWN:
RErrorCode = RERR_BADFORMAT;
return NULL;
case IM_XPM:
image = RLoadXPM(context, file, index);
break;
case IM_XPM:
image = RLoadXPM(context, file, index);
break;
#ifdef USE_TIFF
case IM_TIFF:
image = RLoadTIFF(context, file, index);
break;
case IM_TIFF:
image = RLoadTIFF(context, file, index);
break;
#endif /* USE_TIFF */
#ifdef USE_PNG
case IM_PNG:
image = RLoadPNG(context, file, index);
break;
case IM_PNG:
image = RLoadPNG(context, file, index);
break;
#endif /* USE_PNG */
#ifdef USE_JPEG
case IM_JPEG:
image = RLoadJPEG(context, file, index);
break;
case IM_JPEG:
image = RLoadJPEG(context, file, index);
break;
#endif /* USE_JPEG */
#ifdef USE_GIF
case IM_GIF:
image = RLoadGIF(context, file, index);
break;
case IM_GIF:
image = RLoadGIF(context, file, index);
break;
#endif /* USE_GIF */
case IM_PPM:
image = RLoadPPM(context, file, index);
break;
case IM_PPM:
image = RLoadPPM(context, file, index);
break;
default:
RErrorCode = RERR_BADFORMAT;
return NULL;
default:
RErrorCode = RERR_BADFORMAT;
return NULL;
}
/* store image in cache */
if (RImageCacheSize>0 && image &&
(RImageCacheMaxImage==0
|| RImageCacheMaxImage >= image->width*image->height)) {
time_t oldest=time(NULL);
int oldest_idx = 0;
int done = 0;
for (i=0; i<RImageCacheSize; i++) {
if (!RImageCache[i].file) {
RImageCache[i].file = malloc(strlen(file)+1);
strcpy(RImageCache[i].file, file);
RImageCache[i].image = RCloneImage(image);
RImageCache[i].last_modif = st.st_mtime;
RImageCache[i].last_use = time(NULL);
done = 1;
break;
} else {
if (oldest > RImageCache[i].last_use) {
oldest = RImageCache[i].last_use;
oldest_idx = i;
}
}
}
/* if no slot available, dump least recently used one */
if (!done) {
free(RImageCache[oldest_idx].file);
RReleaseImage(RImageCache[oldest_idx].image);
RImageCache[oldest_idx].file = malloc(strlen(file)+1);
strcpy(RImageCache[oldest_idx].file, file);
RImageCache[oldest_idx].image = RCloneImage(image);
RImageCache[oldest_idx].last_modif = st.st_mtime;
RImageCache[oldest_idx].last_use = time(NULL);
}
if (RImageCacheSize>0 && image &&
(RImageCacheMaxImage==0
|| RImageCacheMaxImage >= image->width*image->height)) {
time_t oldest=time(NULL);
int oldest_idx = 0;
int done = 0;
for (i=0; i<RImageCacheSize; i++) {
if (!RImageCache[i].file) {
RImageCache[i].file = malloc(strlen(file)+1);
strcpy(RImageCache[i].file, file);
RImageCache[i].image = RCloneImage(image);
RImageCache[i].last_modif = st.st_mtime;
RImageCache[i].last_use = time(NULL);
done = 1;
break;
} else {
if (oldest > RImageCache[i].last_use) {
oldest = RImageCache[i].last_use;
oldest_idx = i;
}
}
}
/* if no slot available, dump least recently used one */
if (!done) {
free(RImageCache[oldest_idx].file);
RReleaseImage(RImageCache[oldest_idx].image);
RImageCache[oldest_idx].file = malloc(strlen(file)+1);
strcpy(RImageCache[oldest_idx].file, file);
RImageCache[oldest_idx].image = RCloneImage(image);
RImageCache[oldest_idx].last_modif = st.st_mtime;
RImageCache[oldest_idx].last_use = time(NULL);
}
}
return image;
@@ -285,34 +285,34 @@ char*
RGetImageFileFormat(char *file)
{
switch (identFile(file)) {
case IM_XPM:
return "XPM";
case IM_XPM:
return "XPM";
#ifdef USE_TIFF
case IM_TIFF:
return "TIFF";
case IM_TIFF:
return "TIFF";
#endif /* USE_TIFF */
#ifdef USE_PNG
case IM_PNG:
return "PNG";
case IM_PNG:
return "PNG";
#endif /* USE_PNG */
#ifdef USE_JPEG
case IM_JPEG:
return "JPEG";
case IM_JPEG:
return "JPEG";
#endif /* USE_JPEG */
#ifdef USE_GIF
case IM_GIF:
return "GIF";
case IM_GIF:
return "GIF";
#endif /* USE_GIF */
case IM_PPM:
return "PPM";
case IM_PPM:
return "PPM";
default:
return NULL;
default:
return NULL;
}
}
@@ -327,42 +327,42 @@ identFile(char *path)
fd = open(path, O_RDONLY|O_BINARY);
if (fd < 0) {
RErrorCode = RERR_OPEN;
return IM_ERROR;
RErrorCode = RERR_OPEN;
return IM_ERROR;
}
if (read(fd, buffer, 32)<1) {
close(fd);
RErrorCode = RERR_READ;
return IM_ERROR;
close(fd);
RErrorCode = RERR_READ;
return IM_ERROR;
}
close(fd);
/* check for XPM */
if (strncmp((char*)buffer, "/* XPM */", 9)==0)
return IM_XPM;
if (strncmp((char*)buffer, "/* XPM */", 9)==0)
return IM_XPM;
/* check for TIFF */
if ((buffer[0]=='I' && buffer[1]=='I' && buffer[2]=='*' && buffer[3]==0)
||(buffer[0]=='M' && buffer[1]=='M' && buffer[2]==0 && buffer[3]=='*'))
return IM_TIFF;
||(buffer[0]=='M' && buffer[1]=='M' && buffer[2]==0 && buffer[3]=='*'))
return IM_TIFF;
#ifdef USE_PNG
/* check for PNG */
if (png_check_sig(buffer, 8))
return IM_PNG;
return IM_PNG;
#endif
/* check for raw PPM or PGM */
if (buffer[0]=='P' && (buffer[1]=='5' || buffer[1]=='6'))
return IM_PPM;
return IM_PPM;
/* check for JPEG */
if (buffer[0] == 0xff && buffer[1] == 0xd8)
return IM_JPEG;
return IM_JPEG;
/* check for GIF */
if (buffer[0] == 'G' && buffer[1] == 'I' && buffer[2] == 'F')
return IM_GIF;
return IM_GIF;
return IM_UNKNOWN;
}

View File

@@ -1,18 +1,18 @@
/*
/*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -27,7 +27,7 @@
#include "wraster.h"
void
void
RBevelImage(RImage *image, int bevel_type)
{
RColor color;
@@ -52,35 +52,35 @@ RBevelImage(RImage *image, int bevel_type)
if (bevel_type==RBEV_RAISED3 && h>3)
ROperateLine(image, RAddOperation, 1, 2, 1, h-3, &cdelta);
/* bottom */
/* bottom */
color.alpha = 255;
color.red = color.green = color.blue = 0;
cdelta.red = cdelta.green = cdelta.blue = 40;
if (bevel_type==RBEV_RAISED2 || bevel_type==RBEV_RAISED3) {
ROperateLine(image, RSubtractOperation, 0, h-2, w-3,
h-2, &cdelta);
ROperateLine(image, RSubtractOperation, 0, h-2, w-3,
h-2, &cdelta);
RDrawLine(image, 0, h-1, w-1, h-1, &color);
} else {
ROperateLine(image, RSubtractOperation, 0, h-1, w-1, h-1,
&cdelta);
&cdelta);
}
/* right */
/* right */
if (bevel_type==RBEV_RAISED2 || bevel_type==RBEV_RAISED3) {
ROperateLine(image, RSubtractOperation, w-2, 0, w-2, h-2,
&cdelta);
&cdelta);
RDrawLine(image, w-1, 0, w-1, h-2, &color);
} else {
ROperateLine(image, RSubtractOperation, w-1, 0, w-1, h-2,
&cdelta);
&cdelta);
}
} else { /* sunken */
cdelta.alpha = 0;
cdelta.red = cdelta.green = cdelta.blue = 40;
ROperateLine(image, RSubtractOperation, 0, 0, w-1, 0,
&cdelta); /* top */
ROperateLine(image, RSubtractOperation, 0, 1, 0, h-1,
&cdelta); /* left */
ROperateLine(image, RSubtractOperation, 0, 0, w-1, 0,
&cdelta); /* top */
ROperateLine(image, RSubtractOperation, 0, 1, 0, h-1,
&cdelta); /* left */
cdelta.red = cdelta.green = cdelta.blue = 80;
ROperateLine(image, RAddOperation, 0, h-1, w-1, h-1, &cdelta); /* bottom */
ROperateLine(image, RAddOperation, w-1, 0, w-1, h-2, &cdelta); /* right */
@@ -139,35 +139,35 @@ RClearImage(RImage *image, RColor *color)
for (i = 1; i < image->height; i++, d+=lineSize) {
memcpy(d, image->data, lineSize);
}
} else {
for (i = 0; i < image->width; i++) {
*d++ = color->red;
*d++ = color->green;
*d++ = color->blue;
}
} else {
for (i = 0; i < image->width; i++) {
*d++ = color->red;
*d++ = color->green;
*d++ = color->blue;
}
lineSize = image->width*3;
for (i = 1; i < image->height; i++, d+=lineSize) {
memcpy(d, image->data, lineSize);
}
}
memcpy(d, image->data, lineSize);
}
}
} else {
int bytes = image->width*image->height;
int alpha, nalpha, r, g, b;
int bytes = image->width*image->height;
int alpha, nalpha, r, g, b;
alpha = color->alpha;
r = color->red * alpha;
g = color->green * alpha;
b = color->blue * alpha;
nalpha = 255 - alpha;
alpha = color->alpha;
r = color->red * alpha;
g = color->green * alpha;
b = color->blue * alpha;
nalpha = 255 - alpha;
for (i=0; i<bytes; i++) {
*d = (((int)*d * nalpha) + r)/256; d++;
*d = (((int)*d * nalpha) + g)/256; d++;
*d = (((int)*d * nalpha) + b)/256; d++;
if (image->format == RRGBAFormat) {
d++;
}
}
for (i=0; i<bytes; i++) {
*d = (((int)*d * nalpha) + r)/256; d++;
*d = (((int)*d * nalpha) + g)/256; d++;
*d = (((int)*d * nalpha) + b)/256; d++;
if (image->format == RRGBAFormat) {
d++;
}
}
}
}
@@ -175,44 +175,45 @@ const char*
RMessageForError(int errorCode)
{
switch (errorCode) {
case RERR_NONE:
return "no error";
case RERR_NONE:
return "no error";
case RERR_OPEN:
return "could not open file";
case RERR_OPEN:
return "could not open file";
case RERR_READ:
return "error reading from file";
case RERR_READ:
return "error reading from file";
case RERR_WRITE:
return "error writing to file";
case RERR_WRITE:
return "error writing to file";
case RERR_NOMEMORY:
return "out of memory";
case RERR_NOMEMORY:
return "out of memory";
case RERR_NOCOLOR:
return "out of color cells";
case RERR_NOCOLOR:
return "out of color cells";
case RERR_BADIMAGEFILE:
return "invalid or corrupted image file";
case RERR_BADIMAGEFILE:
return "invalid or corrupted image file";
case RERR_BADFORMAT:
return "the image format in the file is not supported and can't be loaded";
case RERR_BADFORMAT:
return "the image format in the file is not supported and can't be loaded";
case RERR_BADINDEX:
return "image file does not contain requested image index";
case RERR_BADINDEX:
return "image file does not contain requested image index";
case RERR_BADVISUALID:
return "request for an invalid visual ID";
case RERR_BADVISUALID:
return "request for an invalid visual ID";
case RERR_STDCMAPFAIL:
return "failed to create standard colormap";
case RERR_STDCMAPFAIL:
return "failed to create standard colormap";
case RERR_XERROR:
return "internal X error";
case RERR_XERROR:
return "internal X error";
default:
case RERR_INTERNAL:
return "internal error";
default:
case RERR_INTERNAL:
return "internal error";
}
}

View File

@@ -1,19 +1,19 @@
/* nxpm.c - load "normalized" XPM image
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -50,7 +50,7 @@ char *alloca ();
/*
* Restricted support for XPM images.
*
*
* The images must be in the following "normalized" format:
*
*
@@ -86,130 +86,130 @@ RGetImageFromXPMData(RContext *context, char **data)
int w, h, ccount, csize;
if (sscanf(data[line++], "%i %i %i %i", &w, &h, &ccount, &csize)!=4
|| w <= 0 || h <= 0 || ccount <= 0 || csize <= 0)
goto bad_format;
|| w <= 0 || h <= 0 || ccount <= 0 || csize <= 0)
goto bad_format;
if (csize!=1 && csize!=2)
goto bad_format;
if (csize!=1 && csize!=2)
goto bad_format;
color_table[0] = alloca(ccount);
color_table[1] = alloca(ccount);
color_table[2] = alloca(ccount);
color_table[3] = alloca(ccount);
symbol_table = alloca(ccount * sizeof(unsigned short));
bsize = csize * w + 16;
if (!color_table[0] || !color_table[1] || !color_table[2] ||
!color_table[3] || !symbol_table || !bsize) {
RErrorCode = RERR_NOMEMORY;
alloca(0);
return NULL;
!color_table[3] || !symbol_table || !bsize) {
RErrorCode = RERR_NOMEMORY;
alloca(0);
return NULL;
}
transp = 0;
/* get color table */
for (i=0; i<ccount; i++) {
symbol_table[i] = data[line][0];
if (csize==2)
symbol_table[i] |= data[line][1]<<8;
symbol_table[i] = data[line][0];
if (csize==2)
symbol_table[i] |= data[line][1]<<8;
j = csize;
while (data[line][j]!='#' && data[line][j]!=0
&& data[line][j]!='N') j++;
j = csize;
while (data[line][j]!='#' && data[line][j]!=0
&& data[line][j]!='N') j++;
if (data[line][j]=='#') {
unsigned int red, green, blue;
k = 0;
j++;
while (data[line][j+k]!=0) k++;
if (k==6) {
if (sscanf(&(data[line][j]), "%2x%2x%2x", &red, &green, &blue)!=3)
goto bad_format;
} else if (k==12) {
if (sscanf(&(data[line][j]), "%4x%4x%4x", &red, &green, &blue)!=3)
goto bad_format;
red >>= 8;
green >>= 8;
blue >>= 8;
} else
goto bad_format;
color_table[0][i] = red;
color_table[1][i] = green;
color_table[2][i] = blue;
color_table[3][i] = 255;
} else if (strncmp(&(data[line][j]), "None", 4)==0
|| strncmp(&(data[line][j]), "none", 4)==0) {
color_table[3][i] = 0;
transp = 1;
} else {
goto bad_format;
}
line++;
if (data[line][j]=='#') {
unsigned int red, green, blue;
k = 0;
j++;
while (data[line][j+k]!=0) k++;
if (k==6) {
if (sscanf(&(data[line][j]), "%2x%2x%2x", &red, &green, &blue)!=3)
goto bad_format;
} else if (k==12) {
if (sscanf(&(data[line][j]), "%4x%4x%4x", &red, &green, &blue)!=3)
goto bad_format;
red >>= 8;
green >>= 8;
blue >>= 8;
} else
goto bad_format;
color_table[0][i] = red;
color_table[1][i] = green;
color_table[2][i] = blue;
color_table[3][i] = 255;
} else if (strncmp(&(data[line][j]), "None", 4)==0
|| strncmp(&(data[line][j]), "none", 4)==0) {
color_table[3][i] = 0;
transp = 1;
} else {
goto bad_format;
}
line++;
}
image = RCreateImage(w, h, transp);
if (!image) {
alloca(0);
return NULL;
alloca(0);
return NULL;
}
r = image->data;
g = image->data+1;
b = image->data+2;
if (image->format == RRGBAFormat)
a = image->data+3;
a = image->data+3;
else
a = NULL;
a = NULL;
for (i=0; i<h; i++) {
if (csize==1) {
for (j=0; j<w; j++) {
color = data[line][j];
for (k=0; k<ccount; k++) {
if (symbol_table[k] == color)
break;
}
if (k==ccount)
k = 0;
*r = color_table[0][k];
*g = color_table[1][k];
*b = color_table[2][k];
if (a) {
*a = color_table[3][k];
r += 4; g += 4; b += 4; a += 4;
} else {
r += 3; g += 3; b += 3;
}
}
} else {
for (j=0; j<w*2; j++) {
color = data[line][j++];
color |= data[line][j];
for (k=0; k<ccount; k++) {
if (symbol_table[k] == color)
break;
}
if (k==ccount)
k = 0;
*r = color_table[0][k];
*g = color_table[1][k];
*b = color_table[2][k];
if (a) {
*a = color_table[3][k];
r += 4; g += 4; b += 4; a += 4;
} else {
r += 3; g += 3; b += 3;
}
}
}
line++;
if (csize==1) {
for (j=0; j<w; j++) {
color = data[line][j];
for (k=0; k<ccount; k++) {
if (symbol_table[k] == color)
break;
}
if (k==ccount)
k = 0;
*r = color_table[0][k];
*g = color_table[1][k];
*b = color_table[2][k];
if (a) {
*a = color_table[3][k];
r += 4; g += 4; b += 4; a += 4;
} else {
r += 3; g += 3; b += 3;
}
}
} else {
for (j=0; j<w*2; j++) {
color = data[line][j++];
color |= data[line][j];
for (k=0; k<ccount; k++) {
if (symbol_table[k] == color)
break;
}
if (k==ccount)
k = 0;
*r = color_table[0][k];
*g = color_table[1][k];
*b = color_table[2][k];
if (a) {
*a = color_table[3][k];
r += 4; g += 4; b += 4; a += 4;
} else {
r += 3; g += 3; b += 3;
}
}
}
line++;
}
#ifdef C_ALLOCA
@@ -217,13 +217,13 @@ RGetImageFromXPMData(RContext *context, char **data)
#endif
return image;
bad_format:
bad_format:
RErrorCode = RERR_BADIMAGEFILE;
#ifdef C_ALLOCA
alloca(0);
#endif
if (image)
RReleaseImage(image);
RReleaseImage(image);
return NULL;
}
@@ -244,165 +244,165 @@ RLoadXPM(RContext *context, char *file, int index)
int bsize;
int w, h, ccount, csize;
FILE *f;
f = fopen(file, "rb");
if (!f) {
RErrorCode = RERR_OPEN;
return NULL;
RErrorCode = RERR_OPEN;
return NULL;
}
/* sig */
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
goto bad_file;
/* declaration */
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
goto bad_file;
/* data */
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
goto bad_file;
if (line[0]=='/')
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
if (sscanf(line, "\"%i %i %i %i\"", &w, &h, &ccount, &csize)!=4
|| w <= 0 || h <= 0 || ccount <= 0 || csize <= 0)
goto bad_file;
if (csize!=1 && csize!=2)
goto bad_format;
|| w <= 0 || h <= 0 || ccount <= 0 || csize <= 0)
goto bad_file;
if (csize!=1 && csize!=2)
goto bad_format;
color_table[0] = alloca(ccount);
color_table[1] = alloca(ccount);
color_table[2] = alloca(ccount);
color_table[3] = alloca(ccount);
symbol_table = alloca(ccount * sizeof(unsigned short));
bsize = csize * w + 16;
buffer = alloca(bsize);
if (!color_table[0] || !color_table[1] || !color_table[2] ||
!color_table[3] || !symbol_table || !bsize) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
alloca(0);
return NULL;
!color_table[3] || !symbol_table || !bsize) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
alloca(0);
return NULL;
}
transp = 0;
/* get color table */
for (i=0; i<ccount; i++) {
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
if (line[0]=='/')
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
if (line[0]=='/')
if (!fgets(line, LINEWIDTH, f))
goto bad_file;
symbol_table[i] = line[1];
if (csize==2)
symbol_table[i] |= line[2]<<8;
symbol_table[i] = line[1];
if (csize==2)
symbol_table[i] |= line[2]<<8;
j = csize+1;
while (line[j]!='#' && line[j]!='"' && line[j]!=0 && line[j]!='N') j++;
j = csize+1;
while (line[j]!='#' && line[j]!='"' && line[j]!=0 && line[j]!='N') j++;
if (line[j]=='#') {
unsigned int red, green, blue;
k = 0;
j++;
while (line[j+k]!='"' && line[j+k]!=0) k++;
if (k==6) {
if (sscanf(&(line[j]), "%2x%2x%2x", &red, &green, &blue)!=3)
goto bad_format;
} else if (k==12) {
if (sscanf(&(line[j]), "%4x%4x%4x", &red, &green, &blue)!=3)
goto bad_format;
red >>= 8;
green >>= 8;
blue >>= 8;
} else
goto bad_format;
color_table[0][i] = red;
color_table[1][i] = green;
color_table[2][i] = blue;
color_table[3][i] = 255;
} else if (strncmp(&(line[j]), "None", 4)==0
|| strncmp(&(line[j]), "none", 4)==0) {
color_table[3][i] = 0;
transp = 1;
} else {
goto bad_format;
}
if (line[j]=='#') {
unsigned int red, green, blue;
k = 0;
j++;
while (line[j+k]!='"' && line[j+k]!=0) k++;
if (k==6) {
if (sscanf(&(line[j]), "%2x%2x%2x", &red, &green, &blue)!=3)
goto bad_format;
} else if (k==12) {
if (sscanf(&(line[j]), "%4x%4x%4x", &red, &green, &blue)!=3)
goto bad_format;
red >>= 8;
green >>= 8;
blue >>= 8;
} else
goto bad_format;
color_table[0][i] = red;
color_table[1][i] = green;
color_table[2][i] = blue;
color_table[3][i] = 255;
} else if (strncmp(&(line[j]), "None", 4)==0
|| strncmp(&(line[j]), "none", 4)==0) {
color_table[3][i] = 0;
transp = 1;
} else {
goto bad_format;
}
}
image = RCreateImage(w, h, transp);
if (!image) {
fclose(f);
alloca(0);
return NULL;
fclose(f);
alloca(0);
return NULL;
}
r = image->data;
g = image->data+1;
b = image->data+2;
if (image->format == RRGBAFormat)
a = image->data+3;
a = image->data+3;
else
a = NULL;
a = NULL;
for (i=0; i<h; i++) {
if (!fgets(buffer, bsize, f))
goto bad_file;
if (buffer[0]=='/')
if (!fgets(buffer, bsize, f))
goto bad_file;
if (csize==1) {
for (j=1; j<=w; j++) {
color = buffer[j];
for (k=0; k<ccount; k++) {
if (symbol_table[k] == color)
break;
}
if (k==ccount)
k = 0;
*r = color_table[0][k];
*g = color_table[1][k];
*b = color_table[2][k];
if (!fgets(buffer, bsize, f))
goto bad_file;
if (buffer[0]=='/')
if (!fgets(buffer, bsize, f))
goto bad_file;
if (csize==1) {
for (j=1; j<=w; j++) {
color = buffer[j];
for (k=0; k<ccount; k++) {
if (symbol_table[k] == color)
break;
}
if (k==ccount)
k = 0;
*r = color_table[0][k];
*g = color_table[1][k];
*b = color_table[2][k];
if (a) {
*a = color_table[3][k];
r += 4; g += 4; b += 4; a += 4;
} else {
r += 3; g += 3; b += 3;
}
}
} else {
for (j=1; j<=w*2; j++) {
color = buffer[j++];
color |= buffer[j] << 8;
for (k=0; k<ccount; k++) {
if (symbol_table[k] == color)
break;
}
if (k==ccount) {
k = 0;
}
*r = color_table[0][k];
*g = color_table[1][k];
*b = color_table[2][k];
}
} else {
for (j=1; j<=w*2; j++) {
color = buffer[j++];
color |= buffer[j] << 8;
for (k=0; k<ccount; k++) {
if (symbol_table[k] == color)
break;
}
if (k==ccount) {
k = 0;
}
*r = color_table[0][k];
*g = color_table[1][k];
*b = color_table[2][k];
if (a) {
*a = color_table[3][k];
r += 4; g += 4; b += 4; a += 4;
} else {
r += 3; g += 3; b += 3;
}
}
}
}
}
}
fclose(f);
@@ -411,24 +411,24 @@ RLoadXPM(RContext *context, char *file, int index)
#endif
return image;
bad_format:
bad_format:
RErrorCode = RERR_BADIMAGEFILE;
fclose(f);
#ifdef C_ALLOCA
alloca(0);
#endif
if (image)
RReleaseImage(image);
RReleaseImage(image);
return NULL;
bad_file:
bad_file:
RErrorCode = RERR_BADIMAGEFILE;
fclose(f);
#ifdef C_ALLOCA
alloca(0);
#endif
if (image)
RReleaseImage(image);
RReleaseImage(image);
return NULL;
}
@@ -454,20 +454,20 @@ static XPMColor*
lookfor(XPMColor *list, int index)
{
if (!list)
return NULL;
return NULL;
for (; list!=NULL; list=list->next) {
if (CINDEX(list) == index)
return list;
if (CINDEX(list) == index)
return list;
}
return NULL;
}
/*
* Looks for the color in the colormap and inserts if it is not found.
*
*
* list is a binary search list. The unbalancing problem is just ignored.
*
*
* Returns False on error
*/
static Bool
@@ -483,15 +483,15 @@ addcolor(XPMColor **list, unsigned r, unsigned g, unsigned b, int *colors)
tmpc = lookfor(*list, index);
if (tmpc)
return True;
return True;
newc = malloc(sizeof(XPMColor));
if (!newc) {
RErrorCode = RERR_NOMEMORY;
RErrorCode = RERR_NOMEMORY;
return False;
return False;
}
newc->red = r;
@@ -512,11 +512,11 @@ index2str(char *buffer, int index, int charsPerPixel)
int i;
for (i=0; i<charsPerPixel; i++) {
buffer[i] = I2CHAR(index&63);
index >>= 6;
buffer[i] = I2CHAR(index&63);
index >>= 6;
}
buffer[i] = 0;
return buffer;
}
@@ -528,13 +528,13 @@ outputcolormap(FILE *file, XPMColor *colormap, int charsPerPixel)
char buf[128];
if (!colormap)
return;
return;
for (index=0; colormap!=NULL; colormap=colormap->next,index++) {
colormap->index = index;
fprintf(file, "\"%s c #%02x%02x%02x\",\n",
index2str(buf, index, charsPerPixel), colormap->red,
colormap->green, colormap->blue);
colormap->index = index;
fprintf(file, "\"%s c #%02x%02x%02x\",\n",
index2str(buf, index, charsPerPixel), colormap->red,
colormap->green, colormap->blue);
}
}
@@ -543,18 +543,18 @@ static void
freecolormap(XPMColor *colormap)
{
XPMColor *tmp;
while (colormap) {
tmp = colormap->next;
free(colormap);
colormap = tmp;
tmp = colormap->next;
free(colormap);
colormap = tmp;
}
}
/* save routine is common to internal support and library support */
Bool
Bool
RSaveXPM(RImage *image, char *filename)
{
FILE *file;
@@ -571,8 +571,8 @@ RSaveXPM(RImage *image, char *filename)
file = fopen(filename, "wb+");
if (!file) {
RErrorCode = RERR_OPEN;
return False;
RErrorCode = RERR_OPEN;
return False;
}
fprintf(file, "/* XPM */\n");
@@ -583,18 +583,18 @@ RSaveXPM(RImage *image, char *filename)
g = image->data+1;
b = image->data+2;
if (image->format == RRGBAFormat)
a = image->data+3;
a = image->data+3;
else
a = NULL;
a = NULL;
/* first pass: make colormap for the image */
if (a)
colorCount = 1;
colorCount = 1;
for (y = 0; y < image->height; y++) {
for (x = 0; x < image->width; x++) {
for (x = 0; x < image->width; x++) {
if (!a || *a>127) {
if (!addcolor(&colormap, *r, *g, *b, &colorCount)) {
goto uhoh;
if (!addcolor(&colormap, *r, *g, *b, &colorCount)) {
goto uhoh;
}
}
if (a) {
@@ -602,7 +602,7 @@ RSaveXPM(RImage *image, char *filename)
} else {
r += 3; g += 3; b += 3;
}
}
}
}
charsPerPixel = 1;
@@ -610,18 +610,18 @@ RSaveXPM(RImage *image, char *filename)
charsPerPixel++;
/* write header info */
fprintf(file, "\"%i %i %i %i\",\n", image->width, image->height,
colorCount, charsPerPixel);
fprintf(file, "\"%i %i %i %i\",\n", image->width, image->height,
colorCount, charsPerPixel);
/* write colormap data */
if (a) {
for (i=0; i<charsPerPixel; i++)
transp[i] = ' ';
transp[i] = 0;
for (i=0; i<charsPerPixel; i++)
transp[i] = ' ';
transp[i] = 0;
fprintf(file, "\"%s c None\",\n", transp);
fprintf(file, "\"%s c None\",\n", transp);
}
i = 0;
outputcolormap(file, colormap, charsPerPixel);
@@ -630,36 +630,36 @@ RSaveXPM(RImage *image, char *filename)
g = image->data+1;
b = image->data+2;
if (image->format == RRGBAFormat)
a = image->data+3;
a = image->data+3;
else
a = NULL;
a = NULL;
/* write data */
for (y = 0; y < image->height; y++) {
fprintf(file, "\"");
fprintf(file, "\"");
for (x = 0; x < image->width; x++) {
for (x = 0; x < image->width; x++) {
if (!a || *a>127) {
tmpc = lookfor(colormap, (unsigned)*r<<16|(unsigned)*g<<8|(unsigned)*b);
if (!a || *a>127) {
tmpc = lookfor(colormap, (unsigned)*r<<16|(unsigned)*g<<8|(unsigned)*b);
fprintf(file, index2str(buf, tmpc->index, charsPerPixel));
} else {
fprintf(file, transp);
}
fprintf(file, index2str(buf, tmpc->index, charsPerPixel));
} else {
fprintf(file, transp);
}
if (a) {
r += 4; g += 4; b += 4; a += 4;
} else {
r += 3; g += 3; b += 3;
}
}
}
if (y < image->height-1)
fprintf(file, "\",\n");
else
fprintf(file, "\"};\n");
if (y < image->height-1)
fprintf(file, "\",\n");
else
fprintf(file, "\"};\n");
}
ok = 1;
@@ -667,7 +667,7 @@ uhoh:
errno = 0;
fclose(file);
if (ok && errno==ENOSPC) {
RErrorCode = RERR_WRITE;
RErrorCode = RERR_WRITE;
}
freecolormap(colormap);

View File

@@ -1,19 +1,19 @@
/* png.c - load PNG image from file
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -66,76 +66,76 @@ RLoadPNG(RContext *context, char *file, int index)
int depth, junk, color_type;
png_bytep *png_rows;
unsigned char *ptr;
f = fopen(file, "rb");
if (!f) {
RErrorCode = RERR_OPEN;
return NULL;
RErrorCode = RERR_OPEN;
return NULL;
}
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
if (!png) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
return NULL;
RErrorCode = RERR_NOMEMORY;
fclose(f);
return NULL;
}
pinfo = png_create_info_struct(png);
if (!pinfo) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
png_destroy_read_struct(&png, NULL, NULL);
return NULL;
RErrorCode = RERR_NOMEMORY;
fclose(f);
png_destroy_read_struct(&png, NULL, NULL);
return NULL;
}
einfo = png_create_info_struct(png);
if (!einfo) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
png_destroy_read_struct(&png, &pinfo, NULL);
return NULL;
RErrorCode = RERR_NOMEMORY;
fclose(f);
png_destroy_read_struct(&png, &pinfo, NULL);
return NULL;
}
RErrorCode = RERR_INTERNAL;
if (setjmp(png->jmpbuf)) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
if (image)
RReleaseImage(image);
return NULL;
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
if (image)
RReleaseImage(image);
return NULL;
}
png_init_io(png, f);
png_read_info(png, pinfo);
png_get_IHDR(png, pinfo, &width, &height, &depth, &color_type,
&junk, &junk, &junk);
&junk, &junk, &junk);
/* sanity check */
if (width < 1 || height < 1) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
RErrorCode = RERR_BADIMAGEFILE;
return NULL;
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
RErrorCode = RERR_BADIMAGEFILE;
return NULL;
}
/* check for an alpha channel */
if (png_get_valid(png, pinfo, PNG_INFO_tRNS))
alpha = True;
alpha = True;
else
alpha = (color_type & PNG_COLOR_MASK_ALPHA);
alpha = (color_type & PNG_COLOR_MASK_ALPHA);
/* allocate RImage */
image = RCreateImage(width, height, alpha);
if (!image) {
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
return NULL;
fclose(f);
png_destroy_read_struct(&png, &pinfo, &einfo);
return NULL;
}
/* normalize to 8bpp with alpha channel */
if (color_type == PNG_COLOR_TYPE_PALETTE && depth <= 8)
png_set_expand(png);
@@ -151,85 +151,85 @@ RLoadPNG(RContext *context, char *file, int index)
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png);
png_set_gray_to_rgb(png);
/* set gamma correction */
if ((context->attribs->flags & RC_GammaCorrection)
&& context->depth != 8) {
sgamma = (context->attribs->rgamma + context->attribs->ggamma +
context->attribs->bgamma) / 3;
&& context->depth != 8) {
sgamma = (context->attribs->rgamma + context->attribs->ggamma +
context->attribs->bgamma) / 3;
} else if ((tmp = getenv("DISPLAY_GAMMA")) != NULL) {
sgamma = atof(tmp);
if (sgamma==0)
sgamma = 1;
sgamma = atof(tmp);
if (sgamma==0)
sgamma = 1;
} else {
/* blah */
sgamma = 2.2;
/* blah */
sgamma = 2.2;
}
if (png_get_gAMA(png, pinfo, &gamma))
png_set_gamma(png, sgamma, gamma);
png_set_gamma(png, sgamma, gamma);
else
png_set_gamma(png, sgamma, 0.45);
png_set_gamma(png, sgamma, 0.45);
/* do the transforms */
png_read_update_info(png, pinfo);
/* set background color */
if (png_get_bKGD(png, pinfo, &bkcolor)) {
image->background.red = bkcolor->red >> 8;
image->background.green = bkcolor->green >> 8;
image->background.blue = bkcolor->blue >> 8;
image->background.red = bkcolor->red >> 8;
image->background.green = bkcolor->green >> 8;
image->background.blue = bkcolor->blue >> 8;
}
png_rows = alloca(sizeof(char*)*height);
if (!png_rows) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
RReleaseImage(image);
png_destroy_read_struct(&png, &pinfo, &einfo);
RErrorCode = RERR_NOMEMORY;
fclose(f);
RReleaseImage(image);
png_destroy_read_struct(&png, &pinfo, &einfo);
#ifdef C_ALLOCA
alloca(0);
alloca(0);
#endif
return NULL;
return NULL;
}
for (y=0; y<height; y++) {
png_rows[y] = alloca(png_get_rowbytes(png, pinfo));
if (!png_rows[y]) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
RReleaseImage(image);
png_destroy_read_struct(&png, &pinfo, &einfo);
png_rows[y] = alloca(png_get_rowbytes(png, pinfo));
if (!png_rows[y]) {
RErrorCode = RERR_NOMEMORY;
fclose(f);
RReleaseImage(image);
png_destroy_read_struct(&png, &pinfo, &einfo);
#ifdef C_ALLOCA
alloca(0);
alloca(0);
#endif
return NULL;
}
return NULL;
}
}
/* read data */
png_read_image(png, png_rows);
png_read_end(png, einfo);
png_destroy_read_struct(&png, &pinfo, &einfo);
fclose(f);
ptr = image->data;
/* convert to RImage */
if (alpha) {
for (y=0; y<height; y++) {
for (x=0, i=width*4; x<i; x++, ptr++) {
*ptr = *(png_rows[y]+x);
}
}
for (y=0; y<height; y++) {
for (x=0, i=width*4; x<i; x++, ptr++) {
*ptr = *(png_rows[y]+x);
}
}
} else {
for (y=0; y<height; y++) {
for (x=0, i=width*3; x<i; x++, ptr++) {
*ptr = *(png_rows[y]+x);
}
}
for (y=0; y<height; y++) {
for (x=0, i=width*3; x<i; x++, ptr++) {
*ptr = *(png_rows[y]+x);
}
}
}
#ifdef C_ALLOCA
alloca(0);
@@ -238,3 +238,4 @@ RLoadPNG(RContext *context, char *file, int index)
}
#endif /* USE_PNG */

View File

@@ -1,19 +1,19 @@
/* ppm.c - load PPM image from file
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -34,44 +34,44 @@ static RImage*
load_graymap(char *file_name, FILE *file, int w, int h, int max, int raw)
{
RImage *image;
image = RCreateImage(w, h, 0);
if (!image) {
return NULL;
return NULL;
}
if (!raw) {
} else {
if (max<256) {
int x, y;
char *buf, *ptr;
buf = malloc(w+1);
if (!buf) {
return NULL;
}
ptr = image->data;
for (y = 0; y < h; y++) {
if (max<256) {
int x, y;
char *buf, *ptr;
buf = malloc(w+1);
if (!buf) {
return NULL;
}
ptr = image->data;
for (y = 0; y < h; y++) {
if (!fread(buf, w, 1, file)) {
free(buf);
goto short_file;
}
for (x = 0; x < w; x++) {
*(ptr++) = buf[x];
*(ptr++) = buf[x];
*(ptr++) = buf[x];
}
}
free(buf);
} else {
}
free(buf);
goto short_file;
}
for (x = 0; x < w; x++) {
*(ptr++) = buf[x];
*(ptr++) = buf[x];
*(ptr++) = buf[x];
}
}
free(buf);
} else {
}
}
return image;
short_file:
short_file:
RErrorCode = RERR_BADIMAGEFILE;
return NULL;
}
@@ -84,33 +84,33 @@ load_pixmap(char *file_name, FILE *file, int w, int h, int max, int raw)
int i;
char buf[3];
char *ptr;
image = RCreateImage(w, h, 0);
if (!image) {
return NULL;
return NULL;
}
ptr = image->data;
if (!raw) {
} else {
if (max<256) {
i = 0;
while (i < w*h) {
if (fread(buf, 1, 3, file)!=3)
goto short_file;
*(ptr++) = buf[0];
*(ptr++) = buf[1];
*(ptr++) = buf[2];
i++;
}
} else {
}
if (max<256) {
i = 0;
while (i < w*h) {
if (fread(buf, 1, 3, file)!=3)
goto short_file;
*(ptr++) = buf[0];
*(ptr++) = buf[1];
*(ptr++) = buf[2];
i++;
}
} else {
}
}
return image;
short_file:
short_file:
RErrorCode = RERR_BADIMAGEFILE;
return NULL;
}
@@ -126,52 +126,52 @@ RLoadPPM(RContext *context, char *file_name, int index)
int type;
#define GETL() if (!fgets(buffer, 255, file)) goto short_file
file = fopen(file_name, "rb");
if (!file) {
RErrorCode = RERR_OPEN;
return NULL;
RErrorCode = RERR_OPEN;
return NULL;
}
/* get signature */
GETL();
/* only accept raw pixmaps or graymaps */
if (buffer[0] != 'P' || (buffer[1] != '5' && buffer[1] != '6')) {
RErrorCode = RERR_BADFORMAT;
fclose(file);
return NULL;
RErrorCode = RERR_BADFORMAT;
fclose(file);
return NULL;
}
type = buffer[1];
/* skip comments */
while (1) {
GETL();
if (buffer[0]!='#')
break;
GETL();
if (buffer[0]!='#')
break;
}
/* get size */
if (sscanf(buffer, "%i %i", &w, &h)!=2 || w < 1 || h < 1)
goto bad_file;
goto bad_file;
GETL();
if (sscanf(buffer, "%i", &m)!=1 || m < 1)
goto bad_file;
goto bad_file;
if (type=='5')
image = load_graymap(file_name, file, w, h, m, type=='5');
image = load_graymap(file_name, file, w, h, m, type=='5');
else if (type=='6')
image = load_pixmap(file_name, file, w, h, m, type=='6');
image = load_pixmap(file_name, file, w, h, m, type=='6');
fclose(file);
return image;
bad_file:
short_file:
bad_file:
short_file:
RErrorCode = RERR_BADIMAGEFILE;
fclose(file);
return NULL;

View File

@@ -1,19 +1,19 @@
/* raster.c - main and other misc stuff
*
/* raster.c - main and other misc stuff
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -47,17 +47,17 @@ RImage*
RCreateImage(unsigned width, unsigned height, int alpha)
{
RImage *image=NULL;
assert(width>0 && height>0);
if (width > MAX_WIDTH || height > MAX_HEIGHT) {
RErrorCode = RERR_NOMEMORY;
return NULL;
return NULL;
}
image = malloc(sizeof(RImage));
if (!image) {
RErrorCode = RERR_NOMEMORY;
RErrorCode = RERR_NOMEMORY;
return NULL;
}
@@ -72,9 +72,9 @@ RCreateImage(unsigned width, unsigned height, int alpha)
*/
image->data = malloc(width * height * (alpha ? 4 : 3) + 4);
if (!image->data) {
RErrorCode = RERR_NOMEMORY;
free(image);
image = NULL;
RErrorCode = RERR_NOMEMORY;
free(image);
image = NULL;
}
return image;
@@ -92,7 +92,7 @@ RRetainImage(RImage *image)
}
void
void
RReleaseImage(RImage *image)
{
assert(image!=NULL);
@@ -112,14 +112,14 @@ RCloneImage(RImage *image)
RImage *new_image;
assert(image!=NULL);
new_image = RCreateImage(image->width, image->height, HAS_ALPHA(image));
if (!new_image)
return NULL;
return NULL;
new_image->background = image->background;
memcpy(new_image->data, image->data,
image->width*image->height*(HAS_ALPHA(image) ? 4 : 3));
image->width*image->height*(HAS_ALPHA(image) ? 4 : 3));
return new_image;
}
@@ -131,21 +131,21 @@ RGetSubImage(RImage *image, int x, int y, unsigned width, unsigned height)
int i, ofs;
RImage *new_image;
unsigned total_line_size, line_size;
assert(image!=NULL);
assert(x>=0 && y>=0);
assert(x<image->width && y<image->height);
assert(width>0 && height>0);
if (x+width > image->width)
width = image->width-x;
width = image->width-x;
if (y+height > image->height)
height = image->height-y;
height = image->height-y;
new_image = RCreateImage(width, height, HAS_ALPHA(image));
if (!new_image)
return NULL;
return NULL;
new_image->background = image->background;
total_line_size = image->width * (HAS_ALPHA(image) ? 4 : 3);
@@ -154,19 +154,19 @@ RGetSubImage(RImage *image, int x, int y, unsigned width, unsigned height)
ofs = x*(HAS_ALPHA(image) ? 4 : 3) + y*total_line_size;;
for (i=0; i<height; i++) {
memcpy(&new_image->data[i*line_size],
&image->data[i*total_line_size+ofs], line_size);
memcpy(&new_image->data[i*line_size],
&image->data[i*total_line_size+ofs], line_size);
}
return new_image;
}
/*
*----------------------------------------------------------------------
*----------------------------------------------------------------------
* RCombineImages-
* Combines two equal sized images with alpha image. The second
* image will be placed on top of the first one.
*----------------------------------------------------------------------
*----------------------------------------------------------------------
*/
void
RCombineImages(RImage *image, RImage *src)
@@ -175,51 +175,51 @@ RCombineImages(RImage *image, RImage *src)
assert(image->height == src->height);
if (!HAS_ALPHA(src)) {
if (!HAS_ALPHA(image)) {
memcpy(image->data, src->data, image->height*image->width*3);
} else {
int x, y;
unsigned char *d, *s;
d = image->data;
s = src->data;
for (y = 0; y < image->height; y++) {
for (x = 0; x < image->width; x++) {
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
d++;
}
}
}
if (!HAS_ALPHA(image)) {
memcpy(image->data, src->data, image->height*image->width*3);
} else {
int x, y;
unsigned char *d, *s;
d = image->data;
s = src->data;
for (y = 0; y < image->height; y++) {
for (x = 0; x < image->width; x++) {
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
d++;
}
}
}
} else {
register int i;
unsigned char *d;
unsigned char *s;
int alpha, calpha;
register int i;
unsigned char *d;
unsigned char *s;
int alpha, calpha;
d = image->data;
s = src->data;
d = image->data;
s = src->data;
if (!HAS_ALPHA(image)) {
for (i=0; i<image->height*image->width; i++) {
alpha = *(s+3);
calpha = 255 - alpha;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
s++;
}
} else {
for (i=0; i<image->height*image->width; i++) {
alpha = *(s+3);
calpha = 255 - alpha;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d++ |= *s++;
}
}
if (!HAS_ALPHA(image)) {
for (i=0; i<image->height*image->width; i++) {
alpha = *(s+3);
calpha = 255 - alpha;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
s++;
}
} else {
for (i=0; i<image->height*image->width; i++) {
alpha = *(s+3);
calpha = 255 - alpha;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
*d++ |= *s++;
}
}
}
}
@@ -246,36 +246,36 @@ RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness)
#define COP c_opaqueness
if (!HAS_ALPHA(src)) {
int dalpha = HAS_ALPHA(image);
for (i=0; i < image->width*image->height; i++) {
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; d++; s++;
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; d++; s++;
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; d++; s++;
if (dalpha) {
d++;
}
}
int dalpha = HAS_ALPHA(image);
for (i=0; i < image->width*image->height; i++) {
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; d++; s++;
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; d++; s++;
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; d++; s++;
if (dalpha) {
d++;
}
}
} else {
int tmp;
int tmp;
if (!HAS_ALPHA(image)) {
for (i=0; i<image->width*image->height; i++) {
tmp = (*(s+3) * opaqueness)/256;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
s++;
}
} else {
for (i=0; i<image->width*image->height; i++) {
tmp = (*(s+3) * opaqueness)/256;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d |= tmp;
d++; s++;
}
}
if (!HAS_ALPHA(image)) {
for (i=0; i<image->width*image->height; i++) {
tmp = (*(s+3) * opaqueness)/256;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
s++;
}
} else {
for (i=0; i<image->width*image->height; i++) {
tmp = (*(s+3) * opaqueness)/256;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d |= tmp;
d++; s++;
}
}
}
#undef OP
#undef COP
@@ -312,7 +312,7 @@ calculateCombineArea(RImage *des, RImage *src, int *sx, int *sy,
void
RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
unsigned height, int dx, int dy)
unsigned height, int dx, int dy)
{
int x, y, dwi, swi;
unsigned char *d;
@@ -323,71 +323,71 @@ RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
return;
if (!HAS_ALPHA(src)) {
if (!HAS_ALPHA(image)) {
swi = src->width * 3;
dwi = image->width * 3;
if (!HAS_ALPHA(image)) {
swi = src->width * 3;
dwi = image->width * 3;
s = src->data + (sy*(int)src->width + sx) * 3;
d = image->data + (dy*(int)image->width + dx) * 3;
s = src->data + (sy*(int)src->width + sx) * 3;
d = image->data + (dy*(int)image->width + dx) * 3;
for (y=0; y < height; y++) {
memcpy(d, s, width*3);
d += dwi;
s += swi;
}
} else {
swi = (src->width - width) * 3;
dwi = (image->width - width) * 4;
for (y=0; y < height; y++) {
memcpy(d, s, width*3);
d += dwi;
s += swi;
}
} else {
swi = (src->width - width) * 3;
dwi = (image->width - width) * 4;
s = src->data + (sy*(int)src->width + sx) * 3;
d = image->data + (dy*(int)image->width + dx) * 4;
s = src->data + (sy*(int)src->width + sx) * 3;
d = image->data + (dy*(int)image->width + dx) * 4;
for (y=0; y < height; y++) {
for (x=0; x < width; x++) {
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
d++;
}
d += dwi;
s += swi;
}
}
for (y=0; y < height; y++) {
for (x=0; x < width; x++) {
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
d++;
}
d += dwi;
s += swi;
}
}
} else {
int dalpha = HAS_ALPHA(image);
int dalpha = HAS_ALPHA(image);
swi = (src->width - width) * 4;
s = src->data + (sy*(int)src->width + sx) * 4;
if (dalpha) {
dwi = (image->width - width) * 4;
d = image->data + (dy*(int)image->width + dx) * 4;
} else {
dwi = (image->width - width) * 3;
d = image->data + (dy*(int)image->width + dx) * 3;
}
swi = (src->width - width) * 4;
s = src->data + (sy*(int)src->width + sx) * 4;
if (dalpha) {
dwi = (image->width - width) * 4;
d = image->data + (dy*(int)image->width + dx) * 4;
} else {
dwi = (image->width - width) * 3;
d = image->data + (dy*(int)image->width + dx) * 3;
}
for (y=0; y < height; y++) {
for (x=0; x < width; x++) {
alpha = *(s+3);
calpha = 255 - alpha;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
s++;
if (dalpha)
d++;
}
d += dwi;
s += swi;
}
for (y=0; y < height; y++) {
for (x=0; x < width; x++) {
alpha = *(s+3);
calpha = 255 - alpha;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
s++;
if (dalpha)
d++;
}
d += dwi;
s += swi;
}
}
}
void
RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
unsigned width, unsigned height, int dx, int dy,
int opaqueness)
RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
unsigned width, unsigned height, int dx, int dy,
int opaqueness)
{
int x, y, dwi, swi;
int c_opaqueness;
@@ -408,41 +408,41 @@ RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
if (!HAS_ALPHA(src)) {
s = src->data + (sy*src->width + sx)*3;
swi = (src->width - width) * 3;
for (y=0; y < height; y++) {
for (x=0; x < width; x++) {
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
if (dalpha)
d++;
}
d += dwi; s += swi;
}
s = src->data + (sy*src->width + sx)*3;
swi = (src->width - width) * 3;
for (y=0; y < height; y++) {
for (x=0; x < width; x++) {
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
if (dalpha)
d++;
}
d += dwi; s += swi;
}
} else {
int tmp;
s = src->data + (sy*src->width + sx)*4;
swi = (src->width - width) * 4;
for (y=0; y < height; y++) {
for (x=0; x < width; x++) {
tmp = (*(s+3) * opaqueness)/256;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
s++;
if (dalpha)
d++;
}
d += dwi; s += swi;
}
s = src->data + (sy*src->width + sx)*4;
swi = (src->width - width) * 4;
for (y=0; y < height; y++) {
for (x=0; x < width; x++) {
tmp = (*(s+3) * opaqueness)/256;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
s++;
if (dalpha)
d++;
}
d += dwi; s += swi;
}
}
#undef OP
#undef COP
}
}
@@ -452,26 +452,26 @@ RCombineImageWithColor(RImage *image, RColor *color)
register int i;
unsigned char *d;
int alpha, nalpha, r, g, b;
d = image->data;
if (!HAS_ALPHA(image)) {
/* Image has no alpha channel, so we consider it to be all 255.
* Thus there are no transparent parts to be filled. */
return;
/* Image has no alpha channel, so we consider it to be all 255.
* Thus there are no transparent parts to be filled. */
return;
}
r = color->red;
g = color->green;
b = color->blue;
for (i=0; i < image->width*image->height; i++) {
alpha = *(d+3);
nalpha = 255 - alpha;
alpha = *(d+3);
nalpha = 255 - alpha;
*d = (((int)*d * alpha) + (r * nalpha))/256; d++;
*d = (((int)*d * alpha) + (g * nalpha))/256; d++;
*d = (((int)*d * alpha) + (b * nalpha))/256; d++;
d++;
*d = (((int)*d * alpha) + (r * nalpha))/256; d++;
*d = (((int)*d * alpha) + (g * nalpha))/256; d++;
*d = (((int)*d * alpha) + (b * nalpha))/256; d++;
d++;
}
}
@@ -493,7 +493,7 @@ RMakeTiledImage(RImage *tile, unsigned width, unsigned height)
else if (width <= tile->width && height <= tile->height)
image = RGetSubImage(tile, 0, 0, width, height);
else {
int has_alpha = HAS_ALPHA(tile);
int has_alpha = HAS_ALPHA(tile);
image = RCreateImage(width, height, has_alpha);
@@ -505,16 +505,16 @@ RMakeTiledImage(RImage *tile, unsigned width, unsigned height)
w = (width - x < tile->width) ? width - x : tile->width;
if (has_alpha) {
w *= 4;
memcpy(d, s+tx*4, w);
} else {
w *= 3;
memcpy(d, s+tx*3, w);
}
if (has_alpha) {
w *= 4;
memcpy(d, s+tx*4, w);
} else {
w *= 3;
memcpy(d, s+tx*3, w);
}
d += w;
}
tx = (tx + tile->width) % tile_size;
}
}
@@ -557,3 +557,4 @@ RMakeCenteredImage(RImage *image, unsigned width, unsigned height, RColor *color
return tmp;
}

View File

@@ -1,19 +1,19 @@
/* rotate.c - image rotation
*
*
* Raster graphics library
*
*
* Copyright (c) 2000-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -46,140 +46,140 @@ RRotateImage(RImage *image, float angle)
int bpp = image->format == RRGBAFormat ? 4 : 3;
angle = ((int)angle % 360) + (angle - (int)angle);
if (angle == 0.0) {
return RCloneImage(image);
return RCloneImage(image);
} else if (angle == 90.0) {
nwidth = image->height;
nheight = image->width;
nwidth = image->height;
nheight = image->width;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
return NULL;
}
if (bpp == 3) {
unsigned char *optr, *nptr;
unsigned offs;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
return NULL;
}
if (bpp == 3) {
unsigned char *optr, *nptr;
unsigned offs;
offs = nwidth * 4;
optr = image->data;
nptr = img->data;
offs = nwidth * 4;
for (x = 0; x < nwidth; x++) {
nptr = img->data + x*4;
for (y = nheight; y; y--) {
nptr[0] = *optr++;
nptr[1] = *optr++;
nptr[2] = *optr++;
nptr[3] = 255;
optr = image->data;
nptr = img->data;
nptr += offs;
}
}
} else {
unsigned *optr, *nptr;
unsigned *p;
for (x = 0; x < nwidth; x++) {
nptr = img->data + x*4;
for (y = nheight; y; y--) {
nptr[0] = *optr++;
nptr[1] = *optr++;
nptr[2] = *optr++;
nptr[3] = 255;
optr = (unsigned*)image->data;
p = (unsigned*)img->data;
for (x = 0; x < nwidth; x++) {
nptr = p++;
for (y = nheight; y; y--) {
*nptr = *optr++;
nptr += nwidth;
}
}
}
nptr += offs;
}
}
} else {
unsigned *optr, *nptr;
unsigned *p;
optr = (unsigned*)image->data;
p = (unsigned*)img->data;
for (x = 0; x < nwidth; x++) {
nptr = p++;
for (y = nheight; y; y--) {
*nptr = *optr++;
nptr += nwidth;
}
}
}
} else if (angle == 180.0) {
nwidth = image->width;
nheight = image->height;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
return NULL;
}
if (bpp == 3) {
unsigned char *optr, *nptr;
optr = image->data;
nptr = img->data + nwidth * nheight * 4 - 4;
nwidth = image->width;
nheight = image->height;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
return NULL;
}
for (y = 0; y < nheight; y++) {
for (x = 0; x < nwidth; x++) {
nptr[0] = optr[0];
nptr[1] = optr[1];
nptr[2] = optr[2];
nptr[3] = 255;
optr += 3;
nptr -= 4;
}
}
} else {
unsigned *optr, *nptr;
optr = (unsigned*)image->data;
nptr = (unsigned*)img->data + nwidth * nheight - 1;
for (y = nheight*nwidth-1; y >= 0; y--) {
*nptr = *optr;
optr++;
nptr--;
}
}
if (bpp == 3) {
unsigned char *optr, *nptr;
optr = image->data;
nptr = img->data + nwidth * nheight * 4 - 4;
for (y = 0; y < nheight; y++) {
for (x = 0; x < nwidth; x++) {
nptr[0] = optr[0];
nptr[1] = optr[1];
nptr[2] = optr[2];
nptr[3] = 255;
optr += 3;
nptr -= 4;
}
}
} else {
unsigned *optr, *nptr;
optr = (unsigned*)image->data;
nptr = (unsigned*)img->data + nwidth * nheight - 1;
for (y = nheight*nwidth-1; y >= 0; y--) {
*nptr = *optr;
optr++;
nptr--;
}
}
} else if (angle == 270.0) {
nwidth = image->height;
nheight = image->width;
nwidth = image->height;
nheight = image->width;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
return NULL;
}
if (bpp == 3) {
unsigned char *optr, *nptr;
unsigned offs;
img = RCreateImage(nwidth, nheight, True);
if (!img) {
return NULL;
}
if (bpp == 3) {
unsigned char *optr, *nptr;
unsigned offs;
offs = nwidth * 4;
optr = image->data;
nptr = img->data;
offs = nwidth * 4;
for (x = 0; x < nwidth; x++) {
nptr = img->data + x*4;
for (y = nheight; y; y--) {
nptr[0] = *optr++;
nptr[1] = *optr++;
nptr[2] = *optr++;
nptr[3] = 255;
optr = image->data;
nptr = img->data;
nptr += offs;
}
}
} else {
unsigned *optr, *nptr;
unsigned *p;
for (x = 0; x < nwidth; x++) {
nptr = img->data + x*4;
for (y = nheight; y; y--) {
nptr[0] = *optr++;
nptr[1] = *optr++;
nptr[2] = *optr++;
nptr[3] = 255;
optr = (unsigned*)image->data;
p = (unsigned*)img->data + nwidth*nheight;
for (x = 0; x < nwidth; x++) {
nptr = p--;
for (y = nheight; y; y--) {
*nptr = *optr++;
nptr -= nwidth;
}
}
}
nptr += offs;
}
}
} else {
unsigned *optr, *nptr;
unsigned *p;
optr = (unsigned*)image->data;
p = (unsigned*)img->data + nwidth*nheight;
for (x = 0; x < nwidth; x++) {
nptr = p--;
for (y = nheight; y; y--) {
*nptr = *optr++;
nptr -= nwidth;
}
}
}
} else {
img = rotateImage(image, angle);
img = rotateImage(image, angle);
}
return img;
}
@@ -188,11 +188,11 @@ RRotateImage(RImage *image, float angle)
/*
* Image rotation through Bresenham's line algorithm:
*
*
* If a square must be rotate by angle a, like in:
* _______
* | B |
* | /4\ |
* | /4\ |
* | /3 8\|
* | /2 7 /|
* |A1 6 / | A_______B
@@ -204,7 +204,7 @@ RRotateImage(RImage *image, float angle)
* for each point P2 in the perpendicular line starting at P1
* get pixel from the source and plot at P2
* increment pixel location from source
*
*
*/
@@ -217,70 +217,70 @@ copyLine(int x1, int y1, int x2, int y2, int nwidth, int format,
int xi, yi;
int offset;
int dpr, dpru, p;
dx = abs(x2 - x1);
dy = abs(y2 - y1);
if (x1 > x2) xi = -1; else xi = 1;
if (y1 > y2) yi = -1; else yi = 1;
if (dx >= dy) {
dpr = dy << 1;
dpru = dpr - (dx << 1);
p = dpr - dx;
while (dx-- >= 0) {
/* fetch and draw the pixel */
offset = (x1 + y1 * nwidth) << 2;
dst[offset++] = *s++;
dst[offset++] = *s++;
dst[offset++] = *s++;
if (format == RRGBAFormat)
dst[offset++] = *s++;
else
dst[offset++] = 255;
/* calc next step */
if (p > 0) {
x1 += xi;
y1 += yi;
p += dpru;
} else {
x1 += xi;
p += dpr;
}
}
dpr = dy << 1;
dpru = dpr - (dx << 1);
p = dpr - dx;
while (dx-- >= 0) {
/* fetch and draw the pixel */
offset = (x1 + y1 * nwidth) << 2;
dst[offset++] = *s++;
dst[offset++] = *s++;
dst[offset++] = *s++;
if (format == RRGBAFormat)
dst[offset++] = *s++;
else
dst[offset++] = 255;
/* calc next step */
if (p > 0) {
x1 += xi;
y1 += yi;
p += dpru;
} else {
x1 += xi;
p += dpr;
}
}
} else {
dpr = dx << 1;
dpru = dpr - (dy << 1);
p = dpr - dy;
while (dy-- >= 0) {
/* fetch and draw the pixel */
offset = (x1 + y1 * nwidth) << 2;
dst[offset++] = *s++;
dst[offset++] = *s++;
dst[offset++] = *s++;
if (format == RRGBAFormat)
dst[offset++] = *s++;
else
dst[offset++] = 255;
/* calc next step */
if (p > 0) {
x1 += xi;
y1 += yi;
p += dpru;
} else {
y1 += yi;
p += dpr;
}
}
dpr = dx << 1;
dpru = dpr - (dy << 1);
p = dpr - dy;
while (dy-- >= 0) {
/* fetch and draw the pixel */
offset = (x1 + y1 * nwidth) << 2;
dst[offset++] = *s++;
dst[offset++] = *s++;
dst[offset++] = *s++;
if (format == RRGBAFormat)
dst[offset++] = *s++;
else
dst[offset++] = 255;
/* calc next step */
if (p > 0) {
x1 += xi;
y1 += yi;
p += dpru;
} else {
y1 += yi;
p += dpr;
}
}
}
*src = s;
}
@@ -297,30 +297,30 @@ rotateImage(RImage *image, float angle)
int xx, yy;
unsigned char *src, *dst;
int dpr, dpru, p;
/* only 180o for now */
if (angle > 180.0)
angle -= 180.0;
angle = (angle * PI) / 180.0;
nwidth = ceil(abs(cos(angle) * image->width))
+ ceil(abs(cos(PI/2 - angle) * image->width));
angle -= 180.0;
angle = (angle * PI) / 180.0;
nwidth = ceil(abs(cos(angle) * image->width))
+ ceil(abs(cos(PI/2 - angle) * image->width));
nheight = ceil(abs(sin(angle) * image->height))
+ ceil(abs(cos(PI/2 - angle) * image->height));
nheight = ceil(abs(sin(angle) * image->height))
+ ceil(abs(cos(PI/2 - angle) * image->height));
img = RCreateImage(nwidth, nheight, True);
if (!img)
return NULL;
return NULL;
src = image->data;
dst = img->data;
x1 = floor(abs(cos(PI/2 - angle)*image->width));
y1 = 0;
x2 = 0;
y2 = floor(abs(sin(PI/2 - angle)*image->width));
@@ -328,61 +328,62 @@ rotateImage(RImage *image, float angle)
yy = nheight - 1;
printf("%ix%i, %i %i %i %i %i\n",
nwidth, nheight, x1, y1, x2, y2, (int)((angle*180.0)/PI));
nwidth, nheight, x1, y1, x2, y2, (int)((angle*180.0)/PI));
dx = abs(x2 - x1);
dy = abs(y2 - y1);
if (x1 > x2) xi = -1; else xi = 1;
if (y1 > y2) yi = -1; else yi = 1;
if (dx >= dy) {
dpr = dy << 1;
dpru = dpr - (dx << 1);
p = dpr - dx;
dpr = dy << 1;
dpru = dpr - (dx << 1);
p = dpr - dx;
while (dx-- >= 0) {
while (dx-- >= 0) {
copyLine(x1, y1, xx, yy, nwidth, image->format, dst, &src);
copyLine(x1, y1, xx, yy, nwidth, image->format, dst, &src);
/* calc next step */
/* calc next step */
if (p > 0) {
x1 += xi;
y1 += yi;
xx += xi;
yy += yi;
p += dpru;
} else {
x1 += xi;
xx += xi;
p += dpr;
}
}
if (p > 0) {
x1 += xi;
y1 += yi;
xx += xi;
yy += yi;
p += dpru;
} else {
x1 += xi;
xx += xi;
p += dpr;
}
}
} else {
puts("NOT IMPLEMTENED");
return img;
dpr = dx << 1;
dpru = dpr - (dy << 1);
p = dpr - dy;
puts("NOT IMPLEMTENED");
return img;
dpr = dx << 1;
dpru = dpr - (dy << 1);
p = dpr - dy;
while (dy-- >= 0) {
xx = abs(x1*sin(angle*PI/180.0));
yy = abs(y1*cos(angle*PI/180.0));
while (dy-- >= 0) {
xx = abs(x1*sin(angle*PI/180.0));
yy = abs(y1*cos(angle*PI/180.0));
copyLine(x1, y1, xx, yy, nwidth, image->format, dst, &src);
copyLine(x1, y1, xx, yy, nwidth, image->format, dst, &src);
/* calc next step*/
if (p > 0) {
x1 += xi;
y1 += yi;
p += dpru;
} else {
y1 += yi;
p += dpr;
}
}
/* calc next step*/
if (p > 0) {
x1 += xi;
y1 += yi;
p += dpru;
} else {
y1 += yi;
p += dpr;
}
}
}
return img;
}

View File

@@ -1,19 +1,19 @@
/* save.c - save image to file
*
*
* Raster graphics library
*
*
* Copyright (c) 1998-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -41,8 +41,8 @@ Bool
RSaveImage(RImage *image, char *filename, char *format)
{
if (strcmp(format, "XPM")!=0) {
RErrorCode = RERR_BADFORMAT;
return False;
RErrorCode = RERR_BADFORMAT;
return False;
}
return RSaveXPM(image, filename);
}

View File

@@ -1,19 +1,19 @@
/* scale.c - image scaling
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -41,11 +41,11 @@
*----------------------------------------------------------------------
* RScaleImage--
* Creates a scaled copy of an image.
*
*
* Returns:
* The new scaled image.
*
*----------------------------------------------------------------------
*
*----------------------------------------------------------------------
*/
#ifndef broken_code
RImage*
@@ -62,69 +62,69 @@ RScaleImage(RImage *image, unsigned new_width, unsigned new_height)
assert(new_width >= 0 && new_height >= 0);
if (new_width == image->width && new_height == image->height)
return RCloneImage(image);
return RCloneImage(image);
img = RCreateImage(new_width, new_height, image->format==RRGBAFormat);
if (!img)
return NULL;
/* fixed point math idea taken from Imlib by
if (!img)
return NULL;
/* fixed point math idea taken from Imlib by
* Carsten Haitzler (Rasterman) */
dx = (image->width<<16)/new_width;
dy = (image->height<<16)/new_height;
py = 0;
d = img->data;
if (image->format == RRGBAFormat) {
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
s = image->data+(t<<2); /* image->data+t*4 */
s = image->data+(t<<2); /* image->data+t*4 */
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
*(d++) = *(s);
*(d++) = *(s+1);
*(d++) = *(s+2);
*(d++) = *(s+3);
t = (px - ox)>>16;
ox += t<<16;
s += t<<2; /* t*4 */
}
py += dy;
}
*(d++) = *(s);
*(d++) = *(s+1);
*(d++) = *(s+2);
*(d++) = *(s+3);
t = (px - ox)>>16;
ox += t<<16;
s += t<<2; /* t*4 */
}
py += dy;
}
} else {
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
s = image->data+(t<<1)+t; /* image->data+t*3 */
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
*(d++) = *(s);
*(d++) = *(s+1);
*(d++) = *(s+2);
t = (px - ox)>>16;
ox += t<<16;
s += (t<<1)+t; /* t*3 */
}
py += dy;
}
s = image->data+(t<<1)+t; /* image->data+t*3 */
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
*(d++) = *(s);
*(d++) = *(s+1);
*(d++) = *(s+2);
t = (px - ox)>>16;
ox += t<<16;
s += (t<<1)+t; /* t*3 */
}
py += dy;
}
}
return img;
}
@@ -142,7 +142,7 @@ RScaleImage(RImage *src, unsigned new_width, unsigned new_height)
unsigned char *dr, *dg, *db, *da;
int ys = 0;
dst = RCreateImage(new_width, new_height, src->data[3]!=NULL);
@@ -166,62 +166,62 @@ RScaleImage(RImage *src, unsigned new_width, unsigned new_height)
da = dst->data[3];
if (sa == NULL) {
for (yd = 0; yd < new_height; yd++) {
int x;
for (yd = 0; yd < new_height; yd++) {
int x;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
while (e >= 0) {
sr++;
sg++;
sb++;
e -= xd2;
}
e += xs;
}
while (ee >= 0) {
ys++;
ee -= h2;
}
ee += ddy;
}
while (e >= 0) {
sr++;
sg++;
sb++;
e -= xd2;
}
e += xs;
}
while (ee >= 0) {
ys++;
ee -= h2;
}
ee += ddy;
}
} else {
for (yd = 0; yd < new_height; yd++) {
int x;
for (yd = 0; yd < new_height; yd++) {
int x;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
sa = src->data[3] + ys * src->width;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
sa = src->data[3] + ys * src->width;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
*(da++) = *sa;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
*(da++) = *sa;
while (e >= 0) {
sr++;
sg++;
sb++;
sa++;
e -= xd2;
}
e += xs;
}
while (ee >= 0) {
ys++;
ee -= h2;
}
ee += ddy;
}
while (e >= 0) {
sr++;
sg++;
sb++;
sa++;
e -= xd2;
}
e += xs;
}
while (ee >= 0) {
ys++;
ee -= h2;
}
ee += ddy;
}
}
return dst;
@@ -283,8 +283,8 @@ double t;
if(t < 0) t = -t;
if(t < .5) return(.75 - (t * t));
if(t < 1.5) {
t = (t - 1.5);
return(.5 * (t * t));
t = (t - 1.5);
return(.5 * (t * t));
}
return(0.0);
}
@@ -296,14 +296,14 @@ B_spline_filter(t) /* box (*) box (*) box (*) box */
double t;
{
double tt;
if(t < 0) t = -t;
if(t < 1) {
tt = t * t;
return((.5 * tt * t) - tt + (2.0 / 3.0));
tt = t * t;
return((.5 * tt * t) - tt + (2.0 / 3.0));
} else if(t < 2) {
t = 2 - t;
return((1.0 / 6.0) * (t * t * t));
t = 2 - t;
return((1.0 / 6.0) * (t * t * t));
}
return(0.0);
}
@@ -338,20 +338,20 @@ Mitchell_filter(t)
double t;
{
double tt;
tt = t * t;
if(t < 0) t = -t;
if(t < 1.0) {
t = (((12.0 - 9.0 * B - 6.0 * C) * (t * tt))
+ ((-18.0 + 12.0 * B + 6.0 * C) * tt)
+ (6.0 - 2 * B));
return(t / 6.0);
t = (((12.0 - 9.0 * B - 6.0 * C) * (t * tt))
+ ((-18.0 + 12.0 * B + 6.0 * C) * tt)
+ (6.0 - 2 * B));
return(t / 6.0);
} else if(t < 2.0) {
t = (((-1.0 * B - 6.0 * C) * (t * tt))
+ ((6.0 * B + 30.0 * C) * tt)
+ ((-12.0 * B - 48.0 * C) * t)
+ (8.0 * B + 24 * C));
return(t / 6.0);
t = (((-1.0 * B - 6.0 * C) * (t * tt))
+ ((6.0 * B + 30.0 * C) * tt)
+ ((-12.0 * B - 48.0 * C) * t)
+ (8.0 * B + 24 * C));
return(t / 6.0);
}
return(0.0);
}
@@ -363,31 +363,31 @@ void
_wraster_change_filter(int type)
{
switch (type) {
case RBoxFilter:
filterf = box_filter;
fwidth = box_support;
break;
case RTriangleFilter:
filterf = triangle_filter;
fwidth = triangle_support;
break;
case RBellFilter:
filterf = bell_filter;
fwidth = bell_support;
break;
case RBSplineFilter:
filterf = B_spline_filter;
fwidth = B_spline_support;
break;
case RLanczos3Filter:
filterf = Lanczos3_filter;
fwidth = Lanczos3_support;
break;
default:
case RMitchellFilter:
filterf = Mitchell_filter;
fwidth = Mitchell_support;
break;
case RBoxFilter:
filterf = box_filter;
fwidth = box_support;
break;
case RTriangleFilter:
filterf = triangle_filter;
fwidth = triangle_support;
break;
case RBellFilter:
filterf = bell_filter;
fwidth = bell_support;
break;
case RBSplineFilter:
filterf = B_spline_filter;
fwidth = B_spline_support;
break;
case RLanczos3Filter:
filterf = Lanczos3_filter;
fwidth = Lanczos3_support;
break;
default:
case RMitchellFilter:
filterf = Mitchell_filter;
fwidth = Mitchell_support;
break;
}
}
@@ -415,7 +415,7 @@ CLIST *contrib; /* array of contribution lists */
/* return of calloc is not checked if NULL in the function below! */
RImage*
RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
{
{
RImage *tmp; /* intermediate image */
double xscale, yscale; /* zoom scale factors */
int i, j, k; /* loop variables */
@@ -428,7 +428,7 @@ RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
unsigned char *sp;
int sch = src->format == RRGBAFormat ? 4 : 3;
dst = RCreateImage(new_width, new_height, False);
/* create intermediate image to hold horizontal zoom */
@@ -439,186 +439,186 @@ RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
/* pre-calculate filter contributions for a row */
contrib = (CLIST *)calloc(new_width, sizeof(CLIST));
if (xscale < 1.0) {
width = fwidth / xscale;
fscale = 1.0 / xscale;
for (i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int)(width * 2 + 1),
sizeof(CONTRIB));
center = (double) i / xscale;
left = ceil(center - width);
right = floor(center + width);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight / fscale) / fscale;
if(j < 0) {
n = -j;
} else if(j >= src->width) {
n = (src->width - j) + src->width - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*sch;
contrib[i].p[k].weight = rweight;
}
}
width = fwidth / xscale;
fscale = 1.0 / xscale;
for (i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int)(width * 2 + 1),
sizeof(CONTRIB));
center = (double) i / xscale;
left = ceil(center - width);
right = floor(center + width);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight / fscale) / fscale;
if(j < 0) {
n = -j;
} else if(j >= src->width) {
n = (src->width - j) + src->width - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*sch;
contrib[i].p[k].weight = rweight;
}
}
} else {
for(i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
center = (double) i / xscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight);
if(j < 0) {
n = -j;
} else if(j >= src->width) {
n = (src->width - j) + src->width - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*sch;
contrib[i].p[k].weight = rweight;
}
}
for(i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
center = (double) i / xscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight);
if(j < 0) {
n = -j;
} else if(j >= src->width) {
n = (src->width - j) + src->width - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*sch;
contrib[i].p[k].weight = rweight;
}
}
}
/* apply filter to zoom horizontally from src to tmp */
p = tmp->data;
for(k = 0; k < tmp->height; ++k) {
CONTRIB *pp;
CONTRIB *pp;
sp = src->data + src->width*k*sch;
sp = src->data + src->width*k*sch;
for(i = 0; i < tmp->width; ++i) {
rweight = gweight = bweight = 0.0;
pp = contrib[i].p;
for(j = 0; j < contrib[i].n; ++j) {
rweight += sp[pp[j].pixel] * pp[j].weight;
gweight += sp[pp[j].pixel+1] * pp[j].weight;
bweight += sp[pp[j].pixel+2] * pp[j].weight;
}
*p++ = CLAMP(rweight, 0, 255);
*p++ = CLAMP(gweight, 0, 255);
*p++ = CLAMP(bweight, 0, 255);
}
for(i = 0; i < tmp->width; ++i) {
rweight = gweight = bweight = 0.0;
pp = contrib[i].p;
for(j = 0; j < contrib[i].n; ++j) {
rweight += sp[pp[j].pixel] * pp[j].weight;
gweight += sp[pp[j].pixel+1] * pp[j].weight;
bweight += sp[pp[j].pixel+2] * pp[j].weight;
}
*p++ = CLAMP(rweight, 0, 255);
*p++ = CLAMP(gweight, 0, 255);
*p++ = CLAMP(bweight, 0, 255);
}
}
/* free the memory allocated for horizontal filter weights */
for(i = 0; i < tmp->width; ++i) {
free(contrib[i].p);
free(contrib[i].p);
}
free(contrib);
/* pre-calculate filter contributions for a column */
contrib = (CLIST *)calloc(dst->height, sizeof(CLIST));
if(yscale < 1.0) {
width = fwidth / yscale;
fscale = 1.0 / yscale;
for(i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (width * 2 + 1),
sizeof(CONTRIB));
center = (double) i / yscale;
left = ceil(center - width);
right = floor(center + width);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight / fscale) / fscale;
if(j < 0) {
n = -j;
} else if(j >= tmp->height) {
n = (tmp->height - j) + tmp->height - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*3;
contrib[i].p[k].weight = rweight;
}
}
width = fwidth / yscale;
fscale = 1.0 / yscale;
for(i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (width * 2 + 1),
sizeof(CONTRIB));
center = (double) i / yscale;
left = ceil(center - width);
right = floor(center + width);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight / fscale) / fscale;
if(j < 0) {
n = -j;
} else if(j >= tmp->height) {
n = (tmp->height - j) + tmp->height - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*3;
contrib[i].p[k].weight = rweight;
}
}
} else {
for(i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
center = (double) i / yscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight);
if(j < 0) {
n = -j;
} else if(j >= tmp->height) {
n = (tmp->height - j) + tmp->height - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*3;
contrib[i].p[k].weight = rweight;
}
}
for(i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
center = (double) i / yscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight);
if(j < 0) {
n = -j;
} else if(j >= tmp->height) {
n = (tmp->height - j) + tmp->height - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*3;
contrib[i].p[k].weight = rweight;
}
}
}
/* apply filter to zoom vertically from tmp to dst */
sp = malloc(tmp->height*3);
for(k = 0; k < new_width; ++k) {
CONTRIB *pp;
p = dst->data + k*3;
CONTRIB *pp;
/* copy a column into a row */
{
int i;
unsigned char *p, *d;
p = dst->data + k*3;
d = sp;
for(i = tmp->height, p = tmp->data + k*3; i-- > 0;
p += tmp->width*3) {
*d++ = *p;
*d++ = *(p+1);
*d++ = *(p+2);
}
}
for(i = 0; i < new_height; ++i) {
rweight = gweight = bweight = 0.0;
pp = contrib[i].p;
for(j = 0; j < contrib[i].n; ++j) {
rweight += sp[pp[j].pixel] * pp[j].weight;
gweight += sp[pp[j].pixel+1] * pp[j].weight;
bweight += sp[pp[j].pixel+2] * pp[j].weight;
}
*p = CLAMP(rweight, 0, 255);
*(p+1) = CLAMP(gweight, 0, 255);
*(p+2) = CLAMP(bweight, 0, 255);
p += new_width*3;
}
/* copy a column into a row */
{
int i;
unsigned char *p, *d;
d = sp;
for(i = tmp->height, p = tmp->data + k*3; i-- > 0;
p += tmp->width*3) {
*d++ = *p;
*d++ = *(p+1);
*d++ = *(p+2);
}
}
for(i = 0; i < new_height; ++i) {
rweight = gweight = bweight = 0.0;
pp = contrib[i].p;
for(j = 0; j < contrib[i].n; ++j) {
rweight += sp[pp[j].pixel] * pp[j].weight;
gweight += sp[pp[j].pixel+1] * pp[j].weight;
bweight += sp[pp[j].pixel+2] * pp[j].weight;
}
*p = CLAMP(rweight, 0, 255);
*(p+1) = CLAMP(gweight, 0, 255);
*(p+2) = CLAMP(bweight, 0, 255);
p += new_width*3;
}
}
free(sp);
/* free the memory allocated for vertical filter weights */
for(i = 0; i < dst->height; ++i) {
free(contrib[i].p);
free(contrib[i].p);
}
free(contrib);
RReleaseImage(tmp);
return dst;
}

View File

@@ -45,13 +45,13 @@ testDraw()
/* Standard gray tile gradient */
/*from.red = 0xa6;
from.green = 0xa6;
from.blue = 0xb6;
from.alpha = 0xff;
to.red = 0x51;
to.green = 0x55;
to.blue = 0x61;
to.alpha = 0xff;*/
from.green = 0xa6;
from.blue = 0xb6;
from.alpha = 0xff;
to.red = 0x51;
to.green = 0x55;
to.blue = 0x61;
to.alpha = 0xff;*/
/* Make the tile, and put it as a sample in the first place */
tile = RRenderGradient(64, 64, &from, &to, RGRD_DIAGONAL);
@@ -63,8 +63,8 @@ testDraw()
* in the second slot, and also save a copy for later use. */
icon = RLoadImage(ctx, "ballot_box.xpm", 0);
if (!icon) {
puts(RMessageForError(RErrorCode));
exit(1);
puts(RMessageForError(RErrorCode));
exit(1);
}
RCombineArea(img, icon, 0, 0, icon->width, icon->height, 8, 8);
RReleaseImage(icon);
@@ -230,13 +230,13 @@ testBevel()
/* Dark blue tile gradient */
/*from.red = 0x28;
from.green = 0x45;
from.blue = 0x69;
from.alpha = 0xff;
to.red = 0x08;
to.green = 0x24;
to.blue = 0x20;
to.alpha = 0xff;*/
from.green = 0x45;
from.blue = 0x69;
from.alpha = 0xff;
to.red = 0x08;
to.green = 0x24;
to.blue = 0x20;
to.alpha = 0xff;*/
/* Create Background */
img = RCreateImage(140, 140, True);
@@ -289,7 +289,7 @@ void testScale()
XSetWindowAttributes val;
Pixmap pix;
Window win;
val.background_pixel = ctx->black;
val.colormap = ctx->cmap;
win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, 140, 140,
@@ -297,13 +297,13 @@ void testScale()
CWColormap|CWBackPixel, &val);
XStoreName(dpy, win, "Scale");
pix = XCreatePixmap(ctx->dpy, ctx->drawable, 140, 140, ctx->depth);
image = RLoadImage(ctx, "ballot_box.xpm", 0);
if (!image) {
puts("couldnt load ballot_box.xpm");
return;
puts("couldnt load ballot_box.xpm");
return;
}
scaled = RScaleImage(image, 140, 140);
RReleaseImage(image);
@@ -326,23 +326,23 @@ void testRotate()
image = RLoadImage(ctx, "ballot_box.xpm", 0);
if (!image) {
puts("couldnt load ballot_box.xpm");
return;
puts("couldnt load ballot_box.xpm");
return;
}
image = RScaleImage(image, 90, 180);
val.background_pixel = ctx->black;
val.colormap = ctx->cmap;
win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, image->height,
image->width,
win = XCreateWindow(dpy, DefaultRootWindow(dpy), 10, 10, image->height,
image->width,
0, ctx->depth, InputOutput, ctx->visual,
CWColormap|CWBackPixel, &val);
XStoreName(dpy, win, "Rotate");
pix = XCreatePixmap(ctx->dpy, ctx->drawable, image->height, image->width,
ctx->depth);
ctx->depth);
rotated = RRotateImage(image, 90.0);
RReleaseImage(image);
@@ -474,8 +474,8 @@ drawClip()
ROperateLine(img, RAddOperation, 22, 63-1, 22, 63, &cdelta);
/*ROperateLine(img, RAddOperation, 22, 63-1, 22, 63, &cdelta);*/ /* the bevel arround them */
ROperateLine(img, RSubtractOperation, 0, 63-22, 1, 63-22, &cdelta1);
#endif
#endif
RConvertImage(ctx, img, &pix);
XCopyArea(dpy, pix, back, ctx->copy_gc, 0, 0, 64, 64, 0, 0);
RReleaseImage(img);
@@ -587,14 +587,14 @@ int main(int argc, char **argv)
ProgName = strrchr(argv[0],'/');
if (!ProgName)
ProgName = argv[0];
ProgName = argv[0];
else
ProgName++;
ProgName++;
dpy = XOpenDisplay("");
if (!dpy) {
puts("cant open display");
exit(1);
puts("cant open display");
exit(1);
}
attr.flags = RC_RenderMode | RC_ColorsPerChannel;
@@ -610,9 +610,9 @@ int main(int argc, char **argv)
ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
if (!ctx) {
printf("could not initialize graphics library context: %s\n",
RMessageForError(RErrorCode));
exit(1);
printf("could not initialize graphics library context: %s\n",
RMessageForError(RErrorCode));
exit(1);
}
/* Here are the things we want to test */
@@ -621,13 +621,14 @@ int main(int argc, char **argv)
testBevel();
drawClip();
testScale();
testRotate();
/* benchmark();*/
/* benchmark();*/
getchar();
return 0;
}

View File

@@ -49,9 +49,9 @@ int main(int argc, char **argv)
ProgName = strrchr(argv[0],'/');
if (!ProgName)
ProgName = argv[0];
ProgName = argv[0];
else
ProgName++;
ProgName++;
color_name = (char **) malloc(sizeof(char*) * argc);
if(color_name == NULL) {
@@ -60,7 +60,7 @@ int main(int argc, char **argv)
}
if (argc>1) {
for (i=1; i<argc; i++) {
for (i=1; i<argc; i++) {
if (strcmp(argv[i], "-m")==0) {
rmode = RBestMatchRendering;
} else if (strcmp(argv[i], "-d")==0) {
@@ -68,7 +68,7 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "-c")==0) {
i++;
if (i>=argc) {
fprintf(stderr, "too few arguments for %s\n", argv[i-1]);
fprintf(stderr, "too few arguments for %s\n", argv[i-1]);
exit(0);
}
if (sscanf(argv[i], "%i", &cpc)!=1) {
@@ -78,7 +78,7 @@ int main(int argc, char **argv)
} else if (strcmp(argv[i], "-v")==0) {
i++;
if (i>=argc) {
fprintf(stderr, "too few arguments for %s\n", argv[i-1]);
fprintf(stderr, "too few arguments for %s\n", argv[i-1]);
exit(0);
}
if (sscanf(argv[i], "%i", &visualID)!=1) {
@@ -91,7 +91,7 @@ int main(int argc, char **argv)
print_help();
exit(1);
}
}
}
}
if (ncolors == 0) {
@@ -101,8 +101,8 @@ int main(int argc, char **argv)
dpy = XOpenDisplay("");
if (!dpy) {
puts("cant open display");
exit(1);
puts("cant open display");
exit(1);
}
attr.flags = RC_RenderMode | RC_ColorsPerChannel;
@@ -117,9 +117,9 @@ int main(int argc, char **argv)
ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
if (!ctx) {
printf("could not initialize graphics library context: %s\n",
RMessageForError(RErrorCode));
exit(1);
printf("could not initialize graphics library context: %s\n",
RMessageForError(RErrorCode));
exit(1);
}
colors = malloc(sizeof(RColor*)*(ncolors+1));
@@ -159,32 +159,32 @@ int main(int argc, char **argv)
gettimeofday(&timev, NULL);
t = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
for (i=0; i<9; i++) {
if (i>0)
printf("\nrepeating...\n\n");
gettimeofday(&timev, NULL);
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
if (i%3==0)
imgh = RRenderMultiGradient(550, 550, colors, RGRD_HORIZONTAL);
else if (i%3==1)
imgh = RRenderMultiGradient(550, 550, colors, RGRD_VERTICAL);
else
imgh = RRenderMultiGradient(550, 550, colors, RGRD_DIAGONAL);
if (i>0)
printf("\nrepeating...\n\n");
gettimeofday(&timev, NULL);
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
if (i%3==0)
imgh = RRenderMultiGradient(550, 550, colors, RGRD_HORIZONTAL);
else if (i%3==1)
imgh = RRenderMultiGradient(550, 550, colors, RGRD_VERTICAL);
else
imgh = RRenderMultiGradient(550, 550, colors, RGRD_DIAGONAL);
gettimeofday(&timev, NULL);
t2 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
total = t2 - t1;
printf("gradient rendered in %f sec\n", total);
RConvertImage(ctx, imgh, &pix);
gettimeofday(&timev, NULL);
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
total = t1 - t2;
rt += total;
printf("image converted in %f sec\n", total);
gettimeofday(&timev, NULL);
t2 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
total = t2 - t1;
printf("gradient rendered in %f sec\n", total);
XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, 250, 250, 0, 0);
RConvertImage(ctx, imgh, &pix);
gettimeofday(&timev, NULL);
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
total = t1 - t2;
rt += total;
printf("image converted in %f sec\n", total);
XFlush(dpy);
XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, 250, 250, 0, 0);
XFlush(dpy);
}
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
printf("------------------------------------------\n");
@@ -210,3 +210,4 @@ int main(int argc, char **argv)
getchar();
return 0;
}

View File

@@ -22,8 +22,8 @@ int main(int argc, char **argv)
dpy = XOpenDisplay("");
if (!dpy) {
puts("cant open display");
exit(1);
puts("cant open display");
exit(1);
}
attr.flags = RC_RenderMode | RC_ColorsPerChannel;
@@ -31,39 +31,40 @@ int main(int argc, char **argv)
attr.colors_per_channel = 4;
ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
if (argc<2)
img = RGetImageFromXPMData(ctx, image_name);
if (argc<2)
img = RGetImageFromXPMData(ctx, image_name);
else
img = RLoadImage(ctx, argv[1], 0);
img = RLoadImage(ctx, argv[1], 0);
if (!img) {
puts(RMessageForError(RErrorCode));
exit(1);
puts(RMessageForError(RErrorCode));
exit(1);
}
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10,
MAX(img->width, img->height),
MAX(img->height, img->width), 0, 0, 0);
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10,
MAX(img->width, img->height),
MAX(img->height, img->width), 0, 0, 0);
XMapRaised(dpy, win);
XFlush(dpy);
a = 0;
while (1) {
RImage *tmp;
a = a + 1.0;
tmp = RRotateImage(img, a);
if (!RConvertImage(ctx, tmp, &pix)) {
puts(RMessageForError(RErrorCode));
exit(1);
}
RReleaseImage(tmp);
XSetWindowBackgroundPixmap(dpy, win, pix);
XFreePixmap(dpy, pix);
XClearWindow(dpy, win);
XSync(dpy, 0);
usleep(50000);
RImage *tmp;
a = a + 1.0;
tmp = RRotateImage(img, a);
if (!RConvertImage(ctx, tmp, &pix)) {
puts(RMessageForError(RErrorCode));
exit(1);
}
RReleaseImage(tmp);
XSetWindowBackgroundPixmap(dpy, win, pix);
XFreePixmap(dpy, pix);
XClearWindow(dpy, win);
XSync(dpy, 0);
usleep(50000);
}
exit(0);
}

View File

@@ -1,19 +1,19 @@
/* tiff.c - load TIFF image from file
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -48,100 +48,101 @@ RLoadTIFF(RContext *context, char *file, int index)
uint16 extrasamples;
uint16 *sampleinfo;
int ch;
tif = TIFFOpen(file, "r");
if (!tif)
return NULL;
return NULL;
/* seek index */
i = index;
while (i>0) {
if (!TIFFReadDirectory(tif)) {
RErrorCode = RERR_BADINDEX;
TIFFClose(tif);
return NULL;
}
i--;
if (!TIFFReadDirectory(tif)) {
RErrorCode = RERR_BADINDEX;
TIFFClose(tif);
return NULL;
}
i--;
}
/* get info */
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height);
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
&extrasamples, &sampleinfo);
&extrasamples, &sampleinfo);
alpha = (extrasamples == 1 &&
((sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA) || (sampleinfo[0] == EXTRASAMPLE_UNASSALPHA)));
((sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA) || (sampleinfo[0] == EXTRASAMPLE_UNASSALPHA)));
amode = (extrasamples == 1 && sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
if (width<1 || height<1) {
RErrorCode = RERR_BADIMAGEFILE;
TIFFClose(tif);
return NULL;
RErrorCode = RERR_BADIMAGEFILE;
TIFFClose(tif);
return NULL;
}
/* read data */
ptr = data = (uint32*)_TIFFmalloc(width * height * sizeof(uint32));
if (!data) {
RErrorCode = RERR_NOMEMORY;
RErrorCode = RERR_NOMEMORY;
} else {
if (!TIFFReadRGBAImage(tif, width, height, data, 0)) {
RErrorCode = RERR_BADIMAGEFILE;
} else {
/* convert data */
image = RCreateImage(width, height, alpha);
if (alpha)
ch = 4;
else
ch = 3;
if (image) {
int x, y;
r = image->data;
g = image->data+1;
b = image->data+2;
a = image->data+3;
if (!TIFFReadRGBAImage(tif, width, height, data, 0)) {
RErrorCode = RERR_BADIMAGEFILE;
} else {
/* data seems to be stored upside down */
data += width * (height-1);
for (y=0; y<height; y++) {
for (x=0; x<width; x++) {
*(r) = (*data) & 0xff;
*(g) = (*data >> 8) & 0xff;
*(b) = (*data >> 16) & 0xff;
/* convert data */
image = RCreateImage(width, height, alpha);
if (alpha) {
*(a) = (*data >> 24) & 0xff;
if (amode && (*a > 0)) {
*r = (*r * 255) / *(a);
*g = (*g * 255) / *(a);
*b = (*b * 255) / *(a);
}
a+=4;
}
r+=ch; g+=ch; b+=ch;
data++;
}
data -= 2*width;
}
}
}
_TIFFfree(ptr);
if (alpha)
ch = 4;
else
ch = 3;
if (image) {
int x, y;
r = image->data;
g = image->data+1;
b = image->data+2;
a = image->data+3;
/* data seems to be stored upside down */
data += width * (height-1);
for (y=0; y<height; y++) {
for (x=0; x<width; x++) {
*(r) = (*data) & 0xff;
*(g) = (*data >> 8) & 0xff;
*(b) = (*data >> 16) & 0xff;
if (alpha) {
*(a) = (*data >> 24) & 0xff;
if (amode && (*a > 0)) {
*r = (*r * 255) / *(a);
*g = (*g * 255) / *(a);
*b = (*b * 255) / *(a);
}
a+=4;
}
r+=ch; g+=ch; b+=ch;
data++;
}
data -= 2*width;
}
}
}
_TIFFfree(ptr);
}
TIFFClose(tif);
return image;
}
#endif /* USE_TIFF */

View File

@@ -18,8 +18,8 @@ main(int argc, char **argv)
dpy = XOpenDisplay("");
if (!dpy) {
puts("cant open display");
exit(1);
puts("cant open display");
exit(1);
}
attr.flags = RC_RenderMode | RC_ColorsPerChannel;
@@ -27,61 +27,61 @@ main(int argc, char **argv)
attr.colors_per_channel = 4;
ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
if (argc<2)
img = RGetImageFromXPMData(ctx, image_name);
if (argc<2)
img = RGetImageFromXPMData(ctx, image_name);
else
img = RLoadImage(ctx, argv[1], 0);
img = RLoadImage(ctx, argv[1], 0);
if (!img) {
puts(RMessageForError(RErrorCode));
exit(1);
puts(RMessageForError(RErrorCode));
exit(1);
}
if (argc > 2) {
RImage *tmp = img;
img = RScaleImage(tmp, tmp->width*atol(argv[2]),
RImage *tmp = img;
img = RScaleImage(tmp, tmp->width*atol(argv[2]),
tmp->height*atol(argv[2]));
/*img = RSmoothScaleImage(tmp, tmp->width*atol(argv[2]),
tmp->height*atol(argv[2]));
/*img = RSmoothScaleImage(tmp, tmp->width*atol(argv[2]),
tmp->height*atol(argv[2]));
*/
RReleaseImage(tmp);
RReleaseImage(tmp);
}
#if 0
if (argc > 2) {
img = RScaleImage(img, img->width*atof(argv[2]),
img->height*atof(argv[2]));
img = RScaleImage(img, img->width*atof(argv[2]),
img->height*atof(argv[2]));
}
{
RImage *tmp = RCreateImage(200, 200, True);
RColor col = {0,0,255,255};
if (img->format == RRGBAFormat)
puts("alpha");
else
puts("no alpha");
RClearImage(tmp, &col);
RCombineArea(tmp, img, 0, 0, 20, 20, 10, 10);
img = tmp;
RImage *tmp = RCreateImage(200, 200, True);
RColor col = {0,0,255,255};
if (img->format == RRGBAFormat)
puts("alpha");
else
puts("no alpha");
RClearImage(tmp, &col);
RCombineArea(tmp, img, 0, 0, 20, 20, 10, 10);
img = tmp;
}
#endif
if (!RConvertImage(ctx, img, &pix)) {
puts(RMessageForError(RErrorCode));
exit(1);
}
printf("%ix%i\n", img->width, img->height);
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10,
img->width, img->height, 0, 0, 0);
if (!RConvertImage(ctx, img, &pix)) {
puts(RMessageForError(RErrorCode));
exit(1);
}
printf("%ix%i\n", img->width, img->height);
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10,
img->width, img->height, 0, 0, 0);
XSetWindowBackgroundPixmap(dpy, win, pix);
XClearWindow(dpy, win);
XMapRaised(dpy, win);
@@ -90,3 +90,4 @@ main(int argc, char **argv)
return 0;
}

View File

@@ -1,18 +1,18 @@
/*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -20,15 +20,15 @@
/*
* Environment variables:
*
*
* WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
* gamma correction value. Must be greater than 0
* Only for PseudoColor visuals.
*
*
* Default:
* WRASTER_GAMMA 1/1/1
*
*
*
*
* If you want a specific value for a screen, append the screen number
* preceded by a hash to the variable name as in
* WRASTER_GAMMA#1
@@ -86,14 +86,14 @@ extern "C" {
/* std colormap usage/creation modes */
enum {
RUseStdColormap, /* default. fallbacks to RIgnore.. if
there is none defined */
RUseStdColormap, /* default. fallbacks to RIgnore.. if
there is none defined */
RCreateStdColormap,
RIgnoreStdColormap
};
typedef struct RContextAttributes {
int flags;
int render_mode;
@@ -101,10 +101,10 @@ typedef struct RContextAttributes {
float rgamma; /* gamma correction for red, */
float ggamma; /* green, */
float bgamma; /* and blue */
VisualID visualid; /* visual ID to use */
VisualID visualid; /* visual ID to use */
int use_shared_memory; /* True of False */
int scaling_filter;
int standard_colormap_mode; /* what to do with std cma */
int standard_colormap_mode; /* what to do with std cma */
} RContextAttributes;
@@ -117,17 +117,17 @@ typedef struct RContext {
Display *dpy;
int screen_number;
Colormap cmap;
RContextAttributes *attribs;
GC copy_gc;
Visual *visual;
int depth;
Window drawable; /* window to pass for XCreatePixmap().*/
/* generally = root */
Window drawable; /* window to pass for XCreatePixmap().*/
/* generally = root */
int vclass;
unsigned long black;
unsigned long white;
@@ -139,14 +139,14 @@ typedef struct RContext {
XStandardColormap *std_rgb_map; /* standard RGB colormap */
XStandardColormap *std_gray_map; /* standard grayscale colormap */
int ncolors; /* total number of colors we can use */
XColor *colors; /* internal colormap */
unsigned long *pixels; /* RContext->colors[].pixel */
struct {
unsigned int use_shared_pixmap:1;
unsigned int optimize_for_speed:1;
unsigned int use_shared_pixmap:1;
unsigned int optimize_for_speed:1;
} flags;
} RContext;
@@ -160,8 +160,8 @@ typedef struct RColor {
typedef struct RHSVColor {
unsigned short hue; /* 0-359 */
unsigned char saturation; /* 0-255 */
unsigned short hue; /* 0-359 */
unsigned char saturation; /* 0-255 */
unsigned char value; /* 0-255 */
} RHSVColor;
@@ -176,7 +176,7 @@ typedef struct RSegment {
int x1, y1, x2, y2;
} RSegment;
/* image formats */
enum RImageFormat {
@@ -190,9 +190,9 @@ enum RImageFormat {
*/
typedef struct RImage {
unsigned char *data; /* image data RGBA or RGB */
int width, height; /* size of the image */
int width, height; /* size of the image */
enum RImageFormat format;
RColor background; /* background color */
RColor background; /* background color */
int refCount;
} RImage;
@@ -221,21 +221,21 @@ enum {
/* smoothed scaling filter types */
enum {
RBoxFilter,
RTriangleFilter,
RBellFilter,
RBSplineFilter,
RLanczos3Filter,
RMitchellFilter
RTriangleFilter,
RBellFilter,
RBSplineFilter,
RLanczos3Filter,
RMitchellFilter
};
/* note that not all operations are supported in all functions */
enum {
RClearOperation, /* clear with 0 */
RCopyOperation,
RNormalOperation, /* same as combine */
RAddOperation,
RSubtractOperation
RClearOperation, /* clear with 0 */
RCopyOperation,
RNormalOperation, /* same as combine */
RAddOperation,
RSubtractOperation
};
@@ -247,8 +247,8 @@ enum {
enum {
RSunkenBevel = -1,
RNoBevel = 0,
RRaisedBevel = 1
RNoBevel = 0,
RRaisedBevel = 1
};
/* bw compat */
#define RBEV_SUNKEN RSunkenBevel
@@ -261,8 +261,8 @@ enum {
enum {
RHorizontalGradient = 2,
RVerticalGradient = 3,
RDiagonalGradient = 4
RVerticalGradient = 3,
RDiagonalGradient = 4
};
/* for backwards compatibility */
#define RGRD_HORIZONTAL RHorizontalGradient
@@ -284,7 +284,7 @@ enum {
#define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
#define RERR_STDCMAPFAIL 17 /* failed to created std colormap */
#define RERR_XERROR 127 /* internal X error */
#define RERR_INTERNAL 128 /* should not happen */
@@ -303,7 +303,7 @@ char *RGetImageFileFormat(char *file);
* Xlib contexts
*/
RContext *RCreateContext(Display *dpy, int screen_number,
RContextAttributes *attribs);
RContextAttributes *attribs);
void RDestroyContext(RContext *context);
@@ -317,7 +317,7 @@ RImage *RCreateImage(unsigned width, unsigned height, int alpha);
RImage *RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask);
RImage *RCreateImageFromDrawable(RContext *context, Drawable drawable,
Pixmap mask);
Pixmap mask);
RImage *RLoadImage(RContext *context, char *file, int index);
@@ -337,29 +337,29 @@ Bool RSaveImage(RImage *image, char *filename, char *format);
*/
RImage *RCloneImage(RImage *image);
RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
unsigned height);
RImage *RGetSubImage(RImage *image, int x, int y, unsigned width,
unsigned height);
void RCombineImageWithColor(RImage *image, RColor *color);
void RCombineImages(RImage *image, RImage *src);
void RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
unsigned height, int dx, int dy);
unsigned height, int dx, int dy);
void RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness);
void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
unsigned width, unsigned height, int dx, int dy,
int opaqueness);
void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
unsigned width, unsigned height, int dx, int dy,
int opaqueness);
RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
unsigned new_height);
RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
unsigned new_height);
RImage *RRotateImage(RImage *image, float angle);
RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);
@@ -375,27 +375,27 @@ void RPutPixel(RImage *image, int x, int y, RColor *color);
void ROperatePixel(RImage *image, int operation, int x, int y, RColor *color);
void RPutPixels(RImage *image, RPoint *points, int npoints, int mode,
RColor *color);
void RPutPixels(RImage *image, RPoint *points, int npoints, int mode,
RColor *color);
void ROperatePixels(RImage *image, int operation, RPoint *points,
int npoints, int mode, RColor *color);
void ROperatePixels(RImage *image, int operation, RPoint *points,
int npoints, int mode, RColor *color);
int RDrawLine(RImage *image, int x0, int y0, int x1, int y1, RColor *color);
int ROperateLine(RImage *image, int operation, int x0, int y0, int x1, int y1,
RColor *color);
RColor *color);
void RDrawLines(RImage *image, RPoint *points, int npoints, int mode,
RColor *color);
void RDrawLines(RImage *image, RPoint *points, int npoints, int mode,
RColor *color);
void ROperateLines(RImage *image, int operation, RPoint *points, int npoints,
int mode, RColor *color);
int mode, RColor *color);
void RDrawSegments(RImage *image, RSegment *segs, int nsegs, RColor *color);
void ROperateSegments(RImage *image, int operation, RSegment *segs, int nsegs,
RColor *color);
RColor *color);
/*
* Color convertion
@@ -409,20 +409,20 @@ void RHSVtoRGB(RHSVColor *hsv, RColor *rgb);
void RClearImage(RImage *image, RColor *color);
void RFillImage(RImage *image, RColor *color);
void RBevelImage(RImage *image, int bevel_type);
RImage *RRenderGradient(unsigned width, unsigned height, RColor *from,
RColor *to, int style);
RImage *RRenderGradient(unsigned width, unsigned height, RColor *from,
RColor *to, int style);
RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
int style);
RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
int style);
RImage *RRenderInterwovenGradient(unsigned width, unsigned height,
RColor colors1[2], int thickness1,
RColor colors2[2], int thickness2);
RColor colors1[2], int thickness1,
RColor colors2[2], int thickness2);
/*
@@ -431,24 +431,24 @@ RImage *RRenderInterwovenGradient(unsigned width, unsigned height,
int RConvertImage(RContext *context, RImage *image, Pixmap *pixmap);
int RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
Pixmap *mask, int threshold);
Pixmap *mask, int threshold);
/*
* misc. utilities
*/
RXImage *RCreateXImage(RContext *context, int depth,
unsigned width, unsigned height);
unsigned width, unsigned height);
RXImage *RGetXImage(RContext *context, Drawable d, int x, int y,
unsigned width, unsigned height);
unsigned width, unsigned height);
void RDestroyXImage(RContext *context, RXImage *ximage);
void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
int src_x, int src_y, int dest_x, int dest_y,
unsigned width, unsigned height);
void RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage,
int src_x, int src_y, int dest_x, int dest_y,
unsigned width, unsigned height);
/* do not free the returned string! */
const char *RMessageForError(int errorCode);
@@ -463,3 +463,4 @@ extern int RErrorCode;
#endif /* __cplusplus */
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/* xpixmap.c - Make RImage from Pixmap or XImage
*
*
* Raster graphics library
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
@@ -8,12 +8,12 @@
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -37,20 +37,20 @@ static int
get_shifts(unsigned long mask)
{
int i=0;
while (mask) {
mask>>=1;
i++;
mask>>=1;
i++;
}
return i;
}
#define NORMALIZE_RED(pixel) ((rshift>0) ? ((pixel) & rmask) >> rshift \
: ((pixel) & rmask) << -rshift)
: ((pixel) & rmask) << -rshift)
#define NORMALIZE_GREEN(pixel) ((gshift>0) ? ((pixel) & gmask) >> gshift \
: ((pixel) & gmask) << -gshift)
: ((pixel) & gmask) << -gshift)
#define NORMALIZE_BLUE(pixel) ((bshift>0) ? ((pixel) & bmask) >> bshift \
: ((pixel) & bmask) << -bshift)
: ((pixel) & bmask) << -bshift)
RImage*
RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask)
@@ -73,16 +73,16 @@ RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask)
/* I don't know why, but XGetImage() for pixmaps don't set the
* {red,green,blue}_mask values correctly.
*/
* {red,green,blue}_mask values correctly.
*/
if (context->depth==image->depth) {
rmask = context->visual->red_mask;
gmask = context->visual->green_mask;
bmask = context->visual->blue_mask;
rmask = context->visual->red_mask;
gmask = context->visual->green_mask;
bmask = context->visual->blue_mask;
} else {
rmask = image->red_mask;
gmask = image->green_mask;
bmask = image->blue_mask;
rmask = image->red_mask;
gmask = image->green_mask;
bmask = image->blue_mask;
}
/* how many bits to shift to normalize the color into 8bpp */
@@ -94,29 +94,29 @@ RCreateImageFromXImage(RContext *context, XImage *image, XImage *mask)
if (image->depth==1) {
for (y = 0; y < image->height; y++) {
for (x = 0; x < image->width; x++) {
pixel = XGetPixel(image, x, y);
if (pixel) {
*data++ = 0;
*data++ = 0;
*data++ = 0;
} else {
*data++ = 0xff;
*data++ = 0xff;
*data++ = 0xff;
for (x = 0; x < image->width; x++) {
pixel = XGetPixel(image, x, y);
if (pixel) {
*data++ = 0;
*data++ = 0;
*data++ = 0;
} else {
*data++ = 0xff;
*data++ = 0xff;
*data++ = 0xff;
}
if (mask) data++;
}
if (mask) data++;
}
}
} else {
for (y = 0; y < image->height; y++) {
for (x = 0; x < image->width; x++) {
pixel = XGetPixel(image, x, y);
*(data++) = NORMALIZE_RED(pixel);
*(data++) = NORMALIZE_GREEN(pixel);
*(data++) = NORMALIZE_BLUE(pixel);
if (mask) data++;
}
for (x = 0; x < image->width; x++) {
pixel = XGetPixel(image, x, y);
*(data++) = NORMALIZE_RED(pixel);
*(data++) = NORMALIZE_GREEN(pixel);
*(data++) = NORMALIZE_BLUE(pixel);
if (mask) data++;
}
}
}
@@ -160,33 +160,34 @@ RCreateImageFromDrawable(RContext *context, Drawable drawable, Pixmap mask)
assert(drawable!=None);
if (!XGetGeometry(context->dpy, drawable, &baz, &foo, &foo,
&w, &h, &bar, &bar)) {
printf("wrlib: invalid window or pixmap passed to RCreateImageFromPixmap\n");
return NULL;
if (!XGetGeometry(context->dpy, drawable, &baz, &foo, &foo,
&w, &h, &bar, &bar)) {
printf("wrlib: invalid window or pixmap passed to RCreateImageFromPixmap\n");
return NULL;
}
pimg = XGetImage(context->dpy, drawable, 0, 0, w, h, AllPlanes,
ZPixmap);
pimg = XGetImage(context->dpy, drawable, 0, 0, w, h, AllPlanes,
ZPixmap);
if (!pimg) {
RErrorCode = RERR_XERROR;
return NULL;
RErrorCode = RERR_XERROR;
return NULL;
}
mimg = NULL;
if (mask) {
if (XGetGeometry(context->dpy, mask, &baz, &foo, &foo,
&w, &h, &bar, &bar)) {
mimg = XGetImage(context->dpy, mask, 0, 0, w, h, AllPlanes,
ZPixmap);
}
if (XGetGeometry(context->dpy, mask, &baz, &foo, &foo,
&w, &h, &bar, &bar)) {
mimg = XGetImage(context->dpy, mask, 0, 0, w, h, AllPlanes,
ZPixmap);
}
}
image = RCreateImageFromXImage(context, pimg, mimg);
XDestroyImage(pimg);
if (mimg)
XDestroyImage(mimg);
XDestroyImage(mimg);
return image;
}

View File

@@ -1,19 +1,19 @@
/* xpm.c - load XPM image from file
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -43,111 +43,111 @@ RGetImageFromXPMData(RContext *context, char **xpmData)
unsigned char *data;
int *p;
int i;
i = XpmCreateXpmImageFromData(xpmData, &xpm, (XpmInfo *)NULL);
if (i!=XpmSuccess) {
switch (i) {
case XpmOpenFailed:
RErrorCode = RERR_OPEN;
break;
case XpmFileInvalid:
RErrorCode = RERR_BADIMAGEFILE;
break;
case XpmNoMemory:
RErrorCode = RERR_NOMEMORY;
break;
default:
RErrorCode = RERR_BADIMAGEFILE;
break;
}
return NULL;
switch (i) {
case XpmOpenFailed:
RErrorCode = RERR_OPEN;
break;
case XpmFileInvalid:
RErrorCode = RERR_BADIMAGEFILE;
break;
case XpmNoMemory:
RErrorCode = RERR_NOMEMORY;
break;
default:
RErrorCode = RERR_BADIMAGEFILE;
break;
}
return NULL;
}
if (xpm.height<1 || xpm.width < 1) {
RErrorCode = RERR_BADIMAGEFILE;
XpmFreeXpmImage(&xpm);
return NULL;
RErrorCode = RERR_BADIMAGEFILE;
XpmFreeXpmImage(&xpm);
return NULL;
}
if (xpm.colorTable==NULL) {
RErrorCode = RERR_BADIMAGEFILE;
XpmFreeXpmImage(&xpm);
return NULL;
RErrorCode = RERR_BADIMAGEFILE;
XpmFreeXpmImage(&xpm);
return NULL;
}
image = RCreateImage(xpm.width, xpm.height, True);
if (!image) {
XpmFreeXpmImage(&xpm);
return NULL;
XpmFreeXpmImage(&xpm);
return NULL;
}
/* make color table */
for (i=0; i<4; i++) {
color_table[i] = malloc(xpm.ncolors*sizeof(char));
if (!color_table[i]) {
for (i=i-1;i>=0; i--) {
if (color_table[i])
free(color_table[i]);
}
RReleaseImage(image);
RErrorCode = RERR_NOMEMORY;
XpmFreeXpmImage(&xpm);
return NULL;
}
color_table[i] = malloc(xpm.ncolors*sizeof(char));
if (!color_table[i]) {
for (i=i-1;i>=0; i--) {
if (color_table[i])
free(color_table[i]);
}
RReleaseImage(image);
RErrorCode = RERR_NOMEMORY;
XpmFreeXpmImage(&xpm);
return NULL;
}
}
for (i=0; i<xpm.ncolors; i++) {
XColor xcolor;
XColor xcolor;
char * color = NULL;
if (xpm.colorTable[i].c_color)
color = xpm.colorTable[i].c_color;
color = xpm.colorTable[i].c_color;
else if (xpm.colorTable[i].g_color)
color = xpm.colorTable[i].g_color;
color = xpm.colorTable[i].g_color;
else if (xpm.colorTable[i].g4_color)
color = xpm.colorTable[i].g4_color;
color = xpm.colorTable[i].g4_color;
else if (xpm.colorTable[i].m_color)
color = xpm.colorTable[i].m_color;
color = xpm.colorTable[i].m_color;
else if (xpm.colorTable[i].symbolic)
color = xpm.colorTable[i].symbolic;
color = xpm.colorTable[i].symbolic;
if (!color) {
color_table[0][i] = 0xbe;
color_table[1][i] = 0xbe;
color_table[2][i] = 0xbe;
color_table[3][i] = 0xff;
color_table[0][i] = 0xbe;
color_table[1][i] = 0xbe;
color_table[2][i] = 0xbe;
color_table[3][i] = 0xff;
continue;
}
if (strncmp(color,"None",4)==0) {
color_table[0][i]=0;
color_table[1][i]=0;
color_table[2][i]=0;
color_table[3][i]=0;
continue;
}
if (XParseColor(dpy, cmap, color, &xcolor)) {
color_table[0][i] = xcolor.red>>8;
color_table[1][i] = xcolor.green>>8;
color_table[2][i] = xcolor.blue>>8;
color_table[3][i] = 0xff;
} else {
color_table[0][i] = 0xbe;
color_table[1][i] = 0xbe;
color_table[2][i] = 0xbe;
color_table[3][i] = 0xff;
}
if (strncmp(color,"None",4)==0) {
color_table[0][i]=0;
color_table[1][i]=0;
color_table[2][i]=0;
color_table[3][i]=0;
continue;
}
if (XParseColor(dpy, cmap, color, &xcolor)) {
color_table[0][i] = xcolor.red>>8;
color_table[1][i] = xcolor.green>>8;
color_table[2][i] = xcolor.blue>>8;
color_table[3][i] = 0xff;
} else {
color_table[0][i] = 0xbe;
color_table[1][i] = 0xbe;
color_table[2][i] = 0xbe;
color_table[3][i] = 0xff;
}
}
/* convert pixmap to RImage */
p = (int*)xpm.data;
data = image->data;
for (i=0; i<xpm.width*xpm.height; i++) {
*(data++)=color_table[0][*p];
*(data++)=color_table[1][*p];
*(data++)=color_table[2][*p];
*(data++)=color_table[3][*p];
p++;
*(data++)=color_table[0][*p];
*(data++)=color_table[1][*p];
*(data++)=color_table[2][*p];
*(data++)=color_table[3][*p];
p++;
}
for(i=0; i<4; i++) {
free(color_table[i]);
free(color_table[i]);
}
XpmFreeXpmImage(&xpm);
return image;
@@ -166,113 +166,114 @@ RLoadXPM(RContext *context, char *file, int index)
unsigned char *data;
int *p;
int i;
i = XpmReadFileToXpmImage(file, &xpm, (XpmInfo *)NULL);
if (i!=XpmSuccess) {
switch (i) {
case XpmOpenFailed:
RErrorCode = RERR_OPEN;
break;
case XpmFileInvalid:
RErrorCode = RERR_BADIMAGEFILE;
break;
case XpmNoMemory:
RErrorCode = RERR_NOMEMORY;
break;
default:
RErrorCode = RERR_BADIMAGEFILE;
break;
}
return NULL;
switch (i) {
case XpmOpenFailed:
RErrorCode = RERR_OPEN;
break;
case XpmFileInvalid:
RErrorCode = RERR_BADIMAGEFILE;
break;
case XpmNoMemory:
RErrorCode = RERR_NOMEMORY;
break;
default:
RErrorCode = RERR_BADIMAGEFILE;
break;
}
return NULL;
}
if (xpm.height<1 || xpm.width < 1) {
RErrorCode = RERR_BADIMAGEFILE;
XpmFreeXpmImage(&xpm);
return NULL;
RErrorCode = RERR_BADIMAGEFILE;
XpmFreeXpmImage(&xpm);
return NULL;
}
if (xpm.colorTable==NULL) {
RErrorCode = RERR_BADIMAGEFILE;
XpmFreeXpmImage(&xpm);
return NULL;
RErrorCode = RERR_BADIMAGEFILE;
XpmFreeXpmImage(&xpm);
return NULL;
}
image = RCreateImage(xpm.width, xpm.height, True);
if (!image) {
XpmFreeXpmImage(&xpm);
return NULL;
XpmFreeXpmImage(&xpm);
return NULL;
}
/* make color table */
for (i=0; i<4; i++) {
color_table[i] = malloc(xpm.ncolors*sizeof(char));
if (!color_table[i]) {
for (i=i-1;i>=0; i--) {
if (color_table[i])
free(color_table[i]);
}
RReleaseImage(image);
RErrorCode = RERR_NOMEMORY;
XpmFreeXpmImage(&xpm);
return NULL;
}
color_table[i] = malloc(xpm.ncolors*sizeof(char));
if (!color_table[i]) {
for (i=i-1;i>=0; i--) {
if (color_table[i])
free(color_table[i]);
}
RReleaseImage(image);
RErrorCode = RERR_NOMEMORY;
XpmFreeXpmImage(&xpm);
return NULL;
}
}
for (i=0; i<xpm.ncolors; i++) {
XColor xcolor;
XColor xcolor;
char * color = NULL;
if (xpm.colorTable[i].c_color)
color = xpm.colorTable[i].c_color;
color = xpm.colorTable[i].c_color;
else if (xpm.colorTable[i].g_color)
color = xpm.colorTable[i].g_color;
color = xpm.colorTable[i].g_color;
else if (xpm.colorTable[i].g4_color)
color = xpm.colorTable[i].g4_color;
color = xpm.colorTable[i].g4_color;
else if (xpm.colorTable[i].m_color)
color = xpm.colorTable[i].m_color;
color = xpm.colorTable[i].m_color;
else if (xpm.colorTable[i].symbolic)
color = xpm.colorTable[i].symbolic;
color = xpm.colorTable[i].symbolic;
if (!color) {
color_table[0][i] = 0xbe;
color_table[1][i] = 0xbe;
color_table[2][i] = 0xbe;
color_table[3][i] = 0xff;
color_table[0][i] = 0xbe;
color_table[1][i] = 0xbe;
color_table[2][i] = 0xbe;
color_table[3][i] = 0xff;
continue;
}
if (strncmp(color,"None",4)==0) {
color_table[0][i]=0;
color_table[1][i]=0;
color_table[2][i]=0;
color_table[3][i]=0;
continue;
}
if (XParseColor(dpy, cmap, color, &xcolor)) {
color_table[0][i] = xcolor.red>>8;
color_table[1][i] = xcolor.green>>8;
color_table[2][i] = xcolor.blue>>8;
color_table[3][i] = 0xff;
} else {
color_table[0][i] = 0xbe;
color_table[1][i] = 0xbe;
color_table[2][i] = 0xbe;
color_table[3][i] = 0xff;
}
if (strncmp(color,"None",4)==0) {
color_table[0][i]=0;
color_table[1][i]=0;
color_table[2][i]=0;
color_table[3][i]=0;
continue;
}
if (XParseColor(dpy, cmap, color, &xcolor)) {
color_table[0][i] = xcolor.red>>8;
color_table[1][i] = xcolor.green>>8;
color_table[2][i] = xcolor.blue>>8;
color_table[3][i] = 0xff;
} else {
color_table[0][i] = 0xbe;
color_table[1][i] = 0xbe;
color_table[2][i] = 0xbe;
color_table[3][i] = 0xff;
}
}
/* convert pixmap to RImage */
p = (int*)xpm.data;
data = image->data;
for (i=0; i<xpm.width*xpm.height; i++, p++) {
*(data++)=color_table[0][*p];
*(data++)=color_table[1][*p];
*(data++)=color_table[2][*p];
*(data++)=color_table[3][*p];
*(data++)=color_table[0][*p];
*(data++)=color_table[1][*p];
*(data++)=color_table[2][*p];
*(data++)=color_table[3][*p];
}
for(i=0; i<4; i++) {
free(color_table[i]);
free(color_table[i]);
}
XpmFreeXpmImage(&xpm);
return image;
}
#endif /* USE_XPM */

View File

@@ -1,5 +1,5 @@
/* xutil.c - utility functions for X
*
*
* Raster graphics library
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
@@ -8,12 +8,12 @@
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -49,7 +49,7 @@ errorHandler(Display *dpy, XErrorEvent *err)
{
shmError=1;
if(err->error_code!=BadAccess)
(*oldErrorHandler)(dpy, err);
(*oldErrorHandler)(dpy, err);
return 0;
}
@@ -63,102 +63,102 @@ RCreateXImage(RContext *context, int depth, unsigned width, unsigned height)
{
RXImage *rximg;
Visual *visual = context->visual;
rximg = malloc(sizeof(RXImage));
if (!rximg) {
RErrorCode = RERR_NOMEMORY;
return NULL;
RErrorCode = RERR_NOMEMORY;
return NULL;
}
#ifndef XSHM
rximg->image = XCreateImage(context->dpy, visual, depth,
ZPixmap, 0, NULL, width, height, 8, 0);
ZPixmap, 0, NULL, width, height, 8, 0);
if (!rximg->image) {
free(rximg);
RErrorCode = RERR_XERROR;
return NULL;
free(rximg);
RErrorCode = RERR_XERROR;
return NULL;
}
rximg->image->data = malloc(rximg->image->bytes_per_line*height);
if (!rximg->image->data) {
XDestroyImage(rximg->image);
free(rximg);
RErrorCode = RERR_NOMEMORY;
return NULL;
XDestroyImage(rximg->image);
free(rximg);
RErrorCode = RERR_NOMEMORY;
return NULL;
}
#else /* XSHM */
#else /* XSHM */
if (!context->attribs->use_shared_memory) {
retry_without_shm:
context->attribs->use_shared_memory = 0;
rximg->is_shared = 0;
rximg->image = XCreateImage(context->dpy, visual, depth,
ZPixmap, 0, NULL, width, height, 8, 0);
if (!rximg->image) {
free(rximg);
RErrorCode = RERR_XERROR;
return NULL;
}
rximg->image->data = malloc(rximg->image->bytes_per_line*height);
if (!rximg->image->data) {
XDestroyImage(rximg->image);
free(rximg);
RErrorCode = RERR_NOMEMORY;
return NULL;
}
context->attribs->use_shared_memory = 0;
rximg->is_shared = 0;
rximg->image = XCreateImage(context->dpy, visual, depth,
ZPixmap, 0, NULL, width, height, 8, 0);
if (!rximg->image) {
free(rximg);
RErrorCode = RERR_XERROR;
return NULL;
}
rximg->image->data = malloc(rximg->image->bytes_per_line*height);
if (!rximg->image->data) {
XDestroyImage(rximg->image);
free(rximg);
RErrorCode = RERR_NOMEMORY;
return NULL;
}
} else {
rximg->is_shared = 1;
rximg->is_shared = 1;
rximg->info.readOnly = False;
rximg->info.readOnly = False;
rximg->image = XShmCreateImage(context->dpy, visual, depth,
ZPixmap, NULL, &rximg->info, width,
height);
rximg->image = XShmCreateImage(context->dpy, visual, depth,
ZPixmap, NULL, &rximg->info, width,
height);
rximg->info.shmid = shmget(IPC_PRIVATE,
rximg->image->bytes_per_line*height,
IPC_CREAT|0777);
if (rximg->info.shmid < 0) {
context->attribs->use_shared_memory = 0;
perror("wrlib: could not allocate shared memory segment");
XDestroyImage(rximg->image);
goto retry_without_shm;
}
rximg->info.shmaddr = shmat(rximg->info.shmid, 0, 0);
if (rximg->info.shmaddr == (void*)-1) {
context->attribs->use_shared_memory = 0;
if (shmctl(rximg->info.shmid, IPC_RMID, 0) < 0)
perror("wrlib: shmctl");
perror("wrlib: could not allocate shared memory");
XDestroyImage(rximg->image);
goto retry_without_shm;
}
shmError = 0;
XSync(context->dpy, False);
oldErrorHandler = XSetErrorHandler(errorHandler);
XShmAttach(context->dpy, &rximg->info);
XSync(context->dpy, False);
XSetErrorHandler(oldErrorHandler);
rximg->info.shmid = shmget(IPC_PRIVATE,
rximg->image->bytes_per_line*height,
IPC_CREAT|0777);
if (rximg->info.shmid < 0) {
context->attribs->use_shared_memory = 0;
perror("wrlib: could not allocate shared memory segment");
XDestroyImage(rximg->image);
goto retry_without_shm;
}
rximg->image->data = rximg->info.shmaddr;
/* rximg->image->obdata = &(rximg->info);*/
rximg->info.shmaddr = shmat(rximg->info.shmid, 0, 0);
if (rximg->info.shmaddr == (void*)-1) {
context->attribs->use_shared_memory = 0;
if (shmctl(rximg->info.shmid, IPC_RMID, 0) < 0)
perror("wrlib: shmctl");
perror("wrlib: could not allocate shared memory");
XDestroyImage(rximg->image);
goto retry_without_shm;
}
if (shmError) {
context->attribs->use_shared_memory = 0;
XDestroyImage(rximg->image);
if (shmdt(rximg->info.shmaddr) < 0)
perror("wrlib: shmdt");
if (shmctl(rximg->info.shmid, IPC_RMID, 0) < 0)
perror("wrlib: shmctl");
/* printf("wrlib:error attaching shared memory segment to XImage\n");
*/
goto retry_without_shm;
}
shmError = 0;
XSync(context->dpy, False);
oldErrorHandler = XSetErrorHandler(errorHandler);
XShmAttach(context->dpy, &rximg->info);
XSync(context->dpy, False);
XSetErrorHandler(oldErrorHandler);
rximg->image->data = rximg->info.shmaddr;
/* rximg->image->obdata = &(rximg->info);*/
if (shmError) {
context->attribs->use_shared_memory = 0;
XDestroyImage(rximg->image);
if (shmdt(rximg->info.shmaddr) < 0)
perror("wrlib: shmdt");
if (shmctl(rximg->info.shmid, IPC_RMID, 0) < 0)
perror("wrlib: shmctl");
/* printf("wrlib:error attaching shared memory segment to XImage\n");
*/
goto retry_without_shm;
}
}
#endif /* XSHM */
return rximg;
}
@@ -170,15 +170,15 @@ RDestroyXImage(RContext *context, RXImage *rximage)
XDestroyImage(rximage->image);
#else /* XSHM */
if (rximage->is_shared) {
XSync(context->dpy, False);
XShmDetach(context->dpy, &rximage->info);
XDestroyImage(rximage->image);
if (shmdt(rximage->info.shmaddr) < 0)
perror("wrlib: shmdt");
if (shmctl(rximage->info.shmid, IPC_RMID, 0) < 0)
perror("wrlib: shmctl");
XSync(context->dpy, False);
XShmDetach(context->dpy, &rximage->info);
XDestroyImage(rximage->image);
if (shmdt(rximage->info.shmaddr) < 0)
perror("wrlib: shmdt");
if (shmctl(rximage->info.shmid, IPC_RMID, 0) < 0)
perror("wrlib: shmctl");
} else {
XDestroyImage(rximage->image);
XDestroyImage(rximage->image);
}
#endif
free(rximage);
@@ -192,9 +192,9 @@ getDepth(Display *dpy, Drawable d)
int foo;
unsigned bar;
unsigned depth;
XGetGeometry(dpy, d, &w, &foo, &foo, &bar, &bar, &bar, &depth);
return depth;
}
@@ -202,43 +202,43 @@ getDepth(Display *dpy, Drawable d)
RXImage*
RGetXImage(RContext *context, Drawable d, int x, int y,
unsigned width, unsigned height)
unsigned width, unsigned height)
{
RXImage *ximg = NULL;
#ifdef XSHM
if (context->attribs->use_shared_memory && 0) {
ximg = RCreateXImage(context, getDepth(context->dpy, d),
width, height);
ximg = RCreateXImage(context, getDepth(context->dpy, d),
width, height);
if (ximg && !ximg->is_shared) {
RDestroyXImage(context, ximg);
ximg = NULL;
}
if (ximg) {
XShmGetImage(context->dpy, d, ximg->image, x, y, AllPlanes);
}
if (ximg && !ximg->is_shared) {
RDestroyXImage(context, ximg);
ximg = NULL;
}
if (ximg) {
XShmGetImage(context->dpy, d, ximg->image, x, y, AllPlanes);
}
}
if (!ximg) {
ximg = malloc(sizeof(RXImage));
if (!ximg) {
RErrorCode = RERR_NOMEMORY;
return NULL;
}
ximg->is_shared = 0;
ximg->image = XGetImage(context->dpy, d, x, y, width, height,
AllPlanes, ZPixmap);
ximg = malloc(sizeof(RXImage));
if (!ximg) {
RErrorCode = RERR_NOMEMORY;
return NULL;
}
ximg->is_shared = 0;
ximg->image = XGetImage(context->dpy, d, x, y, width, height,
AllPlanes, ZPixmap);
}
return ximg;
#else /* !XSHM */
ximg = malloc(sizeof(RXImage));
if (!ximg) {
RErrorCode = RERR_NOMEMORY;
return NULL;
RErrorCode = RERR_NOMEMORY;
return NULL;
}
ximg->image = XGetImage(context->dpy, d, x, y, width, height,
AllPlanes, ZPixmap);
AllPlanes, ZPixmap);
return ximg;
#endif /* !XSHM */
@@ -247,19 +247,19 @@ RGetXImage(RContext *context, Drawable d, int x, int y,
void
RPutXImage(RContext *context, Drawable d, GC gc, RXImage *ximage, int src_x,
int src_y, int dest_x, int dest_y,
unsigned int width, unsigned int height)
int src_y, int dest_x, int dest_y,
unsigned int width, unsigned int height)
{
#ifndef XSHM
XPutImage(context->dpy, d, gc, ximage->image, src_x, src_y, dest_x,
dest_y, width, height);
dest_y, width, height);
#else
if (ximage->is_shared) {
XShmPutImage(context->dpy, d, gc, ximage->image, src_x, src_y,
dest_x, dest_y, width, height, False);
XShmPutImage(context->dpy, d, gc, ximage->image, src_x, src_y,
dest_x, dest_y, width, height, False);
} else {
XPutImage(context->dpy, d, gc, ximage->image, src_x, src_y, dest_x,
dest_y, width, height);
XPutImage(context->dpy, d, gc, ximage->image, src_x, src_y, dest_x,
dest_y, width, height);
}
XFlush(context->dpy);
#endif /* XSHM */
@@ -272,10 +272,10 @@ R_CreateXImageMappedPixmap(RContext *context, RXImage *rximage)
{
Pixmap pix;
pix = XShmCreatePixmap(context->dpy, context->drawable,
rximage->image->data, &rximage->info,
rximage->image->width, rximage->image->height,
rximage->image->depth);
pix = XShmCreatePixmap(context->dpy, context->drawable,
rximage->image->data, &rximage->info,
rximage->image->width, rximage->image->height,
rximage->image->depth);
return pix;
}