mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
Fixed crashes in 24 and 32bpp after introduction of hermeslib support
This commit is contained in:
@@ -486,7 +486,7 @@ WMCreateInputPanel(WMScreen *scrPtr, WMWindow *owner, char *title, char *msg,
|
|||||||
static void
|
static void
|
||||||
handleKeyPress3(XEvent *event, void *clientData)
|
handleKeyPress3(XEvent *event, void *clientData)
|
||||||
{
|
{
|
||||||
WMGenericPanel *panel = (WMAlertPanel*)clientData;
|
WMGenericPanel *panel = (WMGenericPanel*)clientData;
|
||||||
KeySym ksym;
|
KeySym ksym;
|
||||||
|
|
||||||
XLookupString(&event->xkey, NULL, 0, &ksym, NULL);
|
XLookupString(&event->xkey, NULL, 0, &ksym, NULL);
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
- Fixed crashing for Pseudocolor visuals with BestMatchRendering
|
||||||
|
- Small speed improvement for 24 and 32 bpp, if internal converter is used
|
||||||
|
- Small speed improvement for generating gradients.
|
||||||
|
- Fixed RSaveXPM() to output correct xpm images.
|
||||||
|
|
||||||
- fixed code dependant on the order of evaluation. code like
|
- fixed code dependant on the order of evaluation. code like
|
||||||
*ptr++ = *ptr++ = *ptr++ = color;
|
*ptr++ = *ptr++ = *ptr++ = color;
|
||||||
is wrong, because there is no guarantee that ptr will be incremented
|
is wrong, because there is no guarantee that ptr will be incremented
|
||||||
|
|||||||
@@ -18,6 +18,12 @@
|
|||||||
* License along with this library; if not, write to the Free
|
* License along with this library; if not, write to the Free
|
||||||
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Problems:
|
||||||
|
* 1. Using Grayscale visual with Dithering crashes wmaker
|
||||||
|
* 2. Ghost dock/appicon is wrong in Pseudocolor, Staticgray, Grayscale
|
||||||
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -42,6 +48,8 @@ extern Pixmap R_CreateXImageMappedPixmap(RContext *context, RXImage *ximage);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define HAS_ALPHA(I) ((I)->format == RRGBAFormat)
|
||||||
|
|
||||||
|
|
||||||
typedef struct RConversionTable {
|
typedef struct RConversionTable {
|
||||||
unsigned short table[256];
|
unsigned short table[256];
|
||||||
@@ -254,6 +262,15 @@ image2TrueColor(RContext *ctx, RImage *image)
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
puts("true color match");
|
puts("true color match");
|
||||||
#endif
|
#endif
|
||||||
|
if (rmask==0xff && gmask==0xff && bmask==0xff) {
|
||||||
|
for (y=0; y < image->height; y++) {
|
||||||
|
for (x=0; x < image->width; x++, ptr+=channels) {
|
||||||
|
/* reduce pixel */
|
||||||
|
pixel = (*(ptr)<<roffs) | (*(ptr+1)<<goffs) | (*(ptr+2)<<boffs);
|
||||||
|
XPutPixel(ximg->image, x, y, pixel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for (y=0, ofs=0; y < image->height; y++) {
|
for (y=0, ofs=0; y < image->height; y++) {
|
||||||
for (x=0; x < image->width; x++, ofs+=channels-3) {
|
for (x=0; x < image->width; x++, ofs+=channels-3) {
|
||||||
/* reduce pixel */
|
/* reduce pixel */
|
||||||
@@ -264,6 +281,7 @@ image2TrueColor(RContext *ctx, RImage *image)
|
|||||||
XPutPixel(ximg->image, x, y, pixel);
|
XPutPixel(ximg->image, x, y, pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* dither */
|
/* dither */
|
||||||
const int dr=0xff/rmask;
|
const int dr=0xff/rmask;
|
||||||
@@ -427,7 +445,7 @@ image2PseudoColor(RContext *ctx, RImage *image)
|
|||||||
printf("pseudo color match with %d colors per channel\n", cpc);
|
printf("pseudo color match with %d colors per channel\n", cpc);
|
||||||
#endif
|
#endif
|
||||||
for (y=0; y<image->height; y++) {
|
for (y=0; y<image->height; y++) {
|
||||||
for (x=0; x<image->width; x++, ptr+=channels-1) {
|
for (x=0; x<image->width; x++, ptr+=channels-3) {
|
||||||
/* reduce pixel */
|
/* reduce pixel */
|
||||||
r = rtable[*ptr++];
|
r = rtable[*ptr++];
|
||||||
g = gtable[*ptr++];
|
g = gtable[*ptr++];
|
||||||
@@ -783,19 +801,31 @@ hermesConvert(RContext *context, RImage *image)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image->format == RRGBFormat) {
|
if (HAS_ALPHA(image)) {
|
||||||
source.b = 0x00ffffff;
|
if (ximage->image->byte_order==LSBFirst) {
|
||||||
source.g = 0xff00ffff;
|
source.r = 0x000000ff;
|
||||||
source.r = 0xffff00ff;
|
source.g = 0x0000ff00;
|
||||||
source.a = 0x00000000;
|
source.b = 0x00ff0000;
|
||||||
source.bits = 24;
|
|
||||||
} else {
|
|
||||||
source.b = 0x00ffffff;
|
|
||||||
source.g = 0xff00ffff;
|
|
||||||
source.r = 0xffff00ff;
|
|
||||||
source.a = 0xff000000;
|
source.a = 0xff000000;
|
||||||
|
} else {
|
||||||
|
source.r = 0xff000000;
|
||||||
|
source.g = 0x00ff0000;
|
||||||
|
source.b = 0x0000ff00;
|
||||||
|
source.a = 0x000000ff;
|
||||||
|
}
|
||||||
source.bits = 32;
|
source.bits = 32;
|
||||||
|
} else {
|
||||||
|
if (ximage->image->byte_order==LSBFirst) {
|
||||||
|
source.r = 0x0000ff;
|
||||||
|
source.g = 0x00ff00;
|
||||||
|
source.b = 0xff0000;
|
||||||
|
} else {
|
||||||
|
source.r = 0xff0000;
|
||||||
|
source.g = 0x00ff00;
|
||||||
|
source.b = 0x0000ff;
|
||||||
|
}
|
||||||
|
source.a = 0x000000;
|
||||||
|
source.bits = 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
source.indexed = 0;
|
source.indexed = 0;
|
||||||
@@ -805,7 +835,7 @@ hermesConvert(RContext *context, RImage *image)
|
|||||||
dest.g = context->visual->green_mask;
|
dest.g = context->visual->green_mask;
|
||||||
dest.b = context->visual->blue_mask;
|
dest.b = context->visual->blue_mask;
|
||||||
dest.a = 0;
|
dest.a = 0;
|
||||||
dest.bits = context->depth;
|
dest.bits = ximage->image->bits_per_pixel;
|
||||||
if (context->vclass == TrueColor)
|
if (context->vclass == TrueColor)
|
||||||
dest.indexed = 0;
|
dest.indexed = 0;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ renderHGradient(unsigned width, unsigned height, int r0, int g0, int b0,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned long r, g, b, dr, dg, db;
|
unsigned long r, g, b, dr, dg, db;
|
||||||
|
unsigned lineSize = width*3;
|
||||||
RImage *image;
|
RImage *image;
|
||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
|
|
||||||
@@ -144,7 +145,7 @@ renderHGradient(unsigned width, unsigned height, int r0, int g0, int b0,
|
|||||||
|
|
||||||
/* copy the first line to the other lines */
|
/* copy the first line to the other lines */
|
||||||
for (i=1; i<height; i++) {
|
for (i=1; i<height; i++) {
|
||||||
memcpy(&(image->data[i*width*3]), image->data, width*3);
|
memcpy(&(image->data[i*lineSize]), image->data, lineSize);
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -280,6 +281,7 @@ renderMHGradient(unsigned width, unsigned height, RColor **colors, int count)
|
|||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
unsigned long r, g, b, dr, dg, db;
|
unsigned long r, g, b, dr, dg, db;
|
||||||
|
unsigned lineSize = width*3;
|
||||||
RImage *image;
|
RImage *image;
|
||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
unsigned width2;
|
unsigned width2;
|
||||||
@@ -333,7 +335,7 @@ renderMHGradient(unsigned width, unsigned height, RColor **colors, int count)
|
|||||||
|
|
||||||
/* copy the first line to the other lines */
|
/* copy the first line to the other lines */
|
||||||
for (i=1; i<height; i++) {
|
for (i=1; i<height; i++) {
|
||||||
memcpy(&(image->data[i*width*3]), image->data, width*3);
|
memcpy(&(image->data[i*lineSize]), image->data, lineSize);
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -346,6 +348,7 @@ renderMVGradient(unsigned width, unsigned height, RColor **colors, int count)
|
|||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
unsigned long r, g, b, dr, dg, db;
|
unsigned long r, g, b, dr, dg, db;
|
||||||
|
unsigned lineSize = width*3;
|
||||||
RImage *image;
|
RImage *image;
|
||||||
unsigned char *ptr, *tmp;
|
unsigned char *ptr, *tmp;
|
||||||
unsigned height2;
|
unsigned height2;
|
||||||
@@ -426,8 +429,8 @@ renderMVGradient(unsigned width, unsigned height, RColor **colors, int count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (j=k+1; j<height; j++) {
|
for (j=k+1; j<height; j++) {
|
||||||
memcpy(ptr, tmp, width*3);
|
memcpy(ptr, tmp, lineSize);
|
||||||
ptr += width*3;
|
ptr += lineSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
47
wrlib/misc.c
47
wrlib/misc.c
@@ -91,30 +91,30 @@ RBevelImage(RImage *image, int bevel_type)
|
|||||||
void
|
void
|
||||||
RFillImage(RImage *image, RColor *color)
|
RFillImage(RImage *image, RColor *color)
|
||||||
{
|
{
|
||||||
if (image->format == RRGBAFormat) {
|
|
||||||
unsigned char *d = image->data;
|
unsigned char *d = image->data;
|
||||||
|
unsigned lineSize;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (image->format == RRGBAFormat) {
|
||||||
for (i = 0; i < image->width; i++) {
|
for (i = 0; i < image->width; i++) {
|
||||||
*d++ = color->red;
|
*d++ = color->red;
|
||||||
*d++ = color->green;
|
*d++ = color->green;
|
||||||
*d++ = color->blue;
|
*d++ = color->blue;
|
||||||
*d++ = color->alpha;
|
*d++ = color->alpha;
|
||||||
}
|
}
|
||||||
for (i = 1; i < image->height; i++, d += image->width*4) {
|
lineSize = image->width*4;
|
||||||
memcpy(d, image->data, image->width*4);
|
for (i = 1; i < image->height; i++, d+=lineSize) {
|
||||||
|
memcpy(d, image->data, lineSize);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned char *d = image->data;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < image->width; i++) {
|
for (i = 0; i < image->width; i++) {
|
||||||
*d++ = color->red;
|
*d++ = color->red;
|
||||||
*d++ = color->green;
|
*d++ = color->green;
|
||||||
*d++ = color->blue;
|
*d++ = color->blue;
|
||||||
}
|
}
|
||||||
for (i = 1; i < image->height; i++, d += image->width*3) {
|
lineSize = image->width*3;
|
||||||
memcpy(d, image->data, image->width*3);
|
for (i = 1; i < image->height; i++, d+=lineSize) {
|
||||||
|
memcpy(d, image->data, lineSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,41 +123,37 @@ RFillImage(RImage *image, RColor *color)
|
|||||||
void
|
void
|
||||||
RClearImage(RImage *image, RColor *color)
|
RClearImage(RImage *image, RColor *color)
|
||||||
{
|
{
|
||||||
if (color->alpha==255) {
|
|
||||||
if (image->format == RRGBAFormat) {
|
|
||||||
unsigned char *d = image->data;
|
unsigned char *d = image->data;
|
||||||
|
unsigned lineSize;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (color->alpha==255) {
|
||||||
|
if (image->format == RRGBAFormat) {
|
||||||
for (i = 0; i < image->width; i++) {
|
for (i = 0; i < image->width; i++) {
|
||||||
*d++ = color->red;
|
*d++ = color->red;
|
||||||
*d++ = color->green;
|
*d++ = color->green;
|
||||||
*d++ = color->blue;
|
*d++ = color->blue;
|
||||||
*d++ = 0xff;
|
*d++ = 0xff;
|
||||||
}
|
}
|
||||||
for (i = 1; i < image->height; i++, d += image->width*4) {
|
lineSize = image->width*4;
|
||||||
memcpy(d, image->data, image->width*4);
|
for (i = 1; i < image->height; i++, d+=lineSize) {
|
||||||
|
memcpy(d, image->data, lineSize);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned char *d = image->data;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < image->width; i++) {
|
for (i = 0; i < image->width; i++) {
|
||||||
*d++ = color->red;
|
*d++ = color->red;
|
||||||
*d++ = color->green;
|
*d++ = color->green;
|
||||||
*d++ = color->blue;
|
*d++ = color->blue;
|
||||||
}
|
}
|
||||||
for (i = 1; i < image->height; i++, d += image->width*3) {
|
lineSize = image->width*3;
|
||||||
memcpy(d, image->data, image->width*3);
|
for (i = 1; i < image->height; i++, d+=lineSize) {
|
||||||
|
memcpy(d, image->data, lineSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int bytes = image->width*image->height;
|
int bytes = image->width*image->height;
|
||||||
int i;
|
|
||||||
unsigned char *d;
|
|
||||||
int alpha, nalpha, r, g, b;
|
int alpha, nalpha, r, g, b;
|
||||||
|
|
||||||
d = image->data;
|
|
||||||
|
|
||||||
alpha = color->alpha;
|
alpha = color->alpha;
|
||||||
r = color->red * alpha;
|
r = color->red * alpha;
|
||||||
g = color->green * alpha;
|
g = color->green * alpha;
|
||||||
@@ -165,12 +161,9 @@ RClearImage(RImage *image, RColor *color)
|
|||||||
nalpha = 255 - alpha;
|
nalpha = 255 - alpha;
|
||||||
|
|
||||||
for (i=0; i<bytes; i++) {
|
for (i=0; i<bytes; i++) {
|
||||||
*d = (((int)*d * nalpha) + r)/256;
|
*d = (((int)*d * nalpha) + r)/256; d++;
|
||||||
d++;
|
*d = (((int)*d * nalpha) + g)/256; d++;
|
||||||
*d = (((int)*d * nalpha) + g)/256;
|
*d = (((int)*d * nalpha) + b)/256; d++;
|
||||||
d++;
|
|
||||||
*d = (((int)*d * nalpha) + b)/256;
|
|
||||||
d++;
|
|
||||||
if (image->format == RRGBAFormat) {
|
if (image->format == RRGBAFormat) {
|
||||||
d++;
|
d++;
|
||||||
}
|
}
|
||||||
|
|||||||
65
wrlib/nxpm.c
65
wrlib/nxpm.c
@@ -181,14 +181,9 @@ RGetImageFromXPMData(RContext *context, char **data)
|
|||||||
*b = color_table[2][k];
|
*b = color_table[2][k];
|
||||||
if (a) {
|
if (a) {
|
||||||
*a = color_table[3][k];
|
*a = color_table[3][k];
|
||||||
r += 4;
|
r += 4; g += 4; b += 4; a += 4;
|
||||||
g += 4;
|
|
||||||
b += 4;
|
|
||||||
a += 4;
|
|
||||||
} else {
|
} else {
|
||||||
r += 3;
|
r += 3; g += 3; b += 3;
|
||||||
g += 3;
|
|
||||||
b += 3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -208,14 +203,9 @@ RGetImageFromXPMData(RContext *context, char **data)
|
|||||||
*b = color_table[2][k];
|
*b = color_table[2][k];
|
||||||
if (a) {
|
if (a) {
|
||||||
*a = color_table[3][k];
|
*a = color_table[3][k];
|
||||||
r += 4;
|
r += 4; g += 4; b += 4; a += 4;
|
||||||
g += 4;
|
|
||||||
b += 4;
|
|
||||||
a += 4;
|
|
||||||
} else {
|
} else {
|
||||||
r += 3;
|
r += 3; g += 3; b += 3;
|
||||||
g += 3;
|
|
||||||
b += 3;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,11 +369,15 @@ RLoadXPM(RContext *context, char *file, int index)
|
|||||||
if (k==ccount)
|
if (k==ccount)
|
||||||
k = 0;
|
k = 0;
|
||||||
|
|
||||||
*(r++) = color_table[0][k];
|
*r = color_table[0][k];
|
||||||
*(g++) = color_table[1][k];
|
*g = color_table[1][k];
|
||||||
*(b++) = color_table[2][k];
|
*b = color_table[2][k];
|
||||||
if (a)
|
if (a) {
|
||||||
*(a++) = color_table[3][k];
|
*a = color_table[3][k];
|
||||||
|
r += 4; g += 4; b += 4; a += 4;
|
||||||
|
} else {
|
||||||
|
r += 3; g += 3; b += 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (j=1; j<=w*2; j++) {
|
for (j=1; j<=w*2; j++) {
|
||||||
@@ -398,11 +392,15 @@ RLoadXPM(RContext *context, char *file, int index)
|
|||||||
k = 0;
|
k = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(r++) = color_table[0][k];
|
*r = color_table[0][k];
|
||||||
*(g++) = color_table[1][k];
|
*g = color_table[1][k];
|
||||||
*(b++) = color_table[2][k];
|
*b = color_table[2][k];
|
||||||
if (a)
|
if (a) {
|
||||||
*(a++) = color_table[3][k];
|
*a = color_table[3][k];
|
||||||
|
r += 4; g += 4; b += 4; a += 4;
|
||||||
|
} else {
|
||||||
|
r += 3; g += 3; b += 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -594,11 +592,16 @@ RSaveXPM(RImage *image, char *filename)
|
|||||||
colorCount = 1;
|
colorCount = 1;
|
||||||
for (y = 0; y < image->height; y++) {
|
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 (!a || *a>127) {
|
||||||
if (!addcolor(&colormap, *r, *g, *b, &colorCount)) {
|
if (!addcolor(&colormap, *r, *g, *b, &colorCount)) {
|
||||||
goto uhoh;
|
goto uhoh;
|
||||||
}
|
}
|
||||||
r++; g++; b++;
|
}
|
||||||
|
if (a) {
|
||||||
|
r += 4; g += 4; b += 4; a += 4;
|
||||||
|
} else {
|
||||||
|
r += 3; g += 3; b += 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,7 +614,7 @@ RSaveXPM(RImage *image, char *filename)
|
|||||||
colorCount, charsPerPixel);
|
colorCount, charsPerPixel);
|
||||||
|
|
||||||
/* write colormap data */
|
/* write colormap data */
|
||||||
if (image->data[3]) {
|
if (a) {
|
||||||
for (i=0; i<charsPerPixel; i++)
|
for (i=0; i<charsPerPixel; i++)
|
||||||
transp[i] = ' ';
|
transp[i] = ' ';
|
||||||
transp[i] = 0;
|
transp[i] = 0;
|
||||||
@@ -638,7 +641,7 @@ RSaveXPM(RImage *image, char *filename)
|
|||||||
|
|
||||||
for (x = 0; x < image->width; x++) {
|
for (x = 0; x < image->width; x++) {
|
||||||
|
|
||||||
if (!a || *a++>127) {
|
if (!a || *a>127) {
|
||||||
tmpc = lookfor(colormap, (unsigned)*r<<16|(unsigned)*g<<8|(unsigned)*b);
|
tmpc = lookfor(colormap, (unsigned)*r<<16|(unsigned)*g<<8|(unsigned)*b);
|
||||||
|
|
||||||
fprintf(file, index2str(buf, tmpc->index, charsPerPixel));
|
fprintf(file, index2str(buf, tmpc->index, charsPerPixel));
|
||||||
@@ -646,7 +649,11 @@ RSaveXPM(RImage *image, char *filename)
|
|||||||
fprintf(file, transp);
|
fprintf(file, transp);
|
||||||
}
|
}
|
||||||
|
|
||||||
r++; g++; b++;
|
if (a) {
|
||||||
|
r += 4; g += 4; b += 4; a += 4;
|
||||||
|
} else {
|
||||||
|
r += 3; g += 3; b += 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y < image->height-1)
|
if (y < image->height-1)
|
||||||
|
|||||||
111
wrlib/raster.c
111
wrlib/raster.c
@@ -54,11 +54,8 @@ RCreateImage(unsigned width, unsigned height, int alpha)
|
|||||||
memset(image, 0, sizeof(RImage));
|
memset(image, 0, sizeof(RImage));
|
||||||
image->width = width;
|
image->width = width;
|
||||||
image->height = height;
|
image->height = height;
|
||||||
if (alpha) {
|
image->format = alpha ? RRGBAFormat : RRGBFormat;
|
||||||
image->format = RRGBAFormat;
|
|
||||||
} else {
|
|
||||||
image->format = RRGBFormat;
|
|
||||||
}
|
|
||||||
/* the +4 is to give extra bytes at the end of the buffer,
|
/* the +4 is to give extra bytes at the end of the buffer,
|
||||||
* so that we can optimize image conversion for MMX(tm).. see convert.c
|
* so that we can optimize image conversion for MMX(tm).. see convert.c
|
||||||
*/
|
*/
|
||||||
@@ -183,24 +180,18 @@ RCombineImages(RImage *image, RImage *src)
|
|||||||
for (i=0; i<image->height*image->width; i++) {
|
for (i=0; i<image->height*image->width; i++) {
|
||||||
alpha = *(s+3);
|
alpha = *(s+3);
|
||||||
calpha = 255 - alpha;
|
calpha = 255 - alpha;
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
|
||||||
d++; s++;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
|
||||||
d++; s++;
|
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
|
||||||
d++; s++;
|
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i=0; i<image->height*image->width; i++) {
|
for (i=0; i<image->height*image->width; i++) {
|
||||||
alpha = *(s+3);
|
alpha = *(s+3);
|
||||||
calpha = 255 - alpha;
|
calpha = 255 - alpha;
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
|
||||||
d++; s++;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; d++; s++;
|
||||||
d++; s++;
|
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
|
||||||
d++; s++;
|
|
||||||
*d++ |= *s++;
|
*d++ |= *s++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -225,59 +216,50 @@ RCombineImagesWithOpaqueness(RImage *image, RImage *src, int opaqueness)
|
|||||||
s = src->data;
|
s = src->data;
|
||||||
|
|
||||||
c_opaqueness = 255 - opaqueness;
|
c_opaqueness = 255 - opaqueness;
|
||||||
|
|
||||||
#define OP opaqueness
|
#define OP opaqueness
|
||||||
|
#define COP c_opaqueness
|
||||||
|
|
||||||
if (!HAS_ALPHA(src)) {
|
if (!HAS_ALPHA(src)) {
|
||||||
int dalpha = HAS_ALPHA(image);
|
int dalpha = HAS_ALPHA(image);
|
||||||
#define COP c_opaqueness
|
|
||||||
for (i=0; i < image->width*image->height; i++) {
|
for (i=0; i < image->width*image->height; i++) {
|
||||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; d++; s++;
|
||||||
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 = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; d++; s++;
|
||||||
d++; s++;
|
|
||||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
|
||||||
d++; s++;
|
|
||||||
if (dalpha) {
|
if (dalpha) {
|
||||||
d++;
|
d++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef COP
|
|
||||||
} else {
|
} else {
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
if (!HAS_ALPHA(image)) {
|
if (!HAS_ALPHA(image)) {
|
||||||
for (i=0; i<image->width*image->height; i++) {
|
for (i=0; i<image->width*image->height; i++) {
|
||||||
tmp = (*(s+3) * opaqueness)/256;
|
tmp = (*(s+3) * opaqueness)/256;
|
||||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
d++; s++;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
d++; s++;
|
|
||||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
|
||||||
d++; s++;
|
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (i=0; i<image->width*image->height; i++) {
|
for (i=0; i<image->width*image->height; i++) {
|
||||||
tmp = (*(s+3) * opaqueness)/256;
|
tmp = (*(s+3) * opaqueness)/256;
|
||||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
d++; s++;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
d++; s++;
|
|
||||||
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256;
|
|
||||||
d++; s++;
|
|
||||||
*d |= tmp;
|
*d |= tmp;
|
||||||
d++; s++;
|
d++; s++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef OP
|
#undef OP
|
||||||
|
#undef COP
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
calculateCombineArea(RImage *des, RImage *src,
|
calculateCombineArea(RImage *des, RImage *src, int *sx, int *sy,
|
||||||
int *sx, int *sy,
|
int *swidth, int *sheight, int *dx, int *dy)
|
||||||
int *swidth, int *sheight,
|
{
|
||||||
int *dx, int *dy) {
|
|
||||||
|
|
||||||
if (*dx < 0) {
|
if (*dx < 0) {
|
||||||
*sx = -*dx;
|
*sx = -*dx;
|
||||||
*swidth = *swidth + *dx;
|
*swidth = *swidth + *dx;
|
||||||
@@ -363,12 +345,9 @@ RCombineArea(RImage *image, RImage *src, int sx, int sy, unsigned width,
|
|||||||
for (x=0; x < width; x++) {
|
for (x=0; x < width; x++) {
|
||||||
alpha = *(s+3);
|
alpha = *(s+3);
|
||||||
calpha = 255 - alpha;
|
calpha = 255 - alpha;
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
|
||||||
s++; d++;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
*d = (((int)*d * calpha) + ((int)*s * alpha))/256; s++; d++;
|
||||||
s++; d++;
|
|
||||||
*d = (((int)*d * calpha) + ((int)*s * alpha))/256;
|
|
||||||
s++; d++;
|
|
||||||
s++;
|
s++;
|
||||||
if (dalpha)
|
if (dalpha)
|
||||||
d++;
|
d++;
|
||||||
@@ -387,8 +366,7 @@ RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
|
|||||||
{
|
{
|
||||||
int x, y, dwi, swi;
|
int x, y, dwi, swi;
|
||||||
int c_opaqueness;
|
int c_opaqueness;
|
||||||
unsigned char *d;
|
unsigned char *s, *d;
|
||||||
unsigned char *s;
|
|
||||||
int dalpha = HAS_ALPHA(image);
|
int dalpha = HAS_ALPHA(image);
|
||||||
int dch = (dalpha ? 4 : 3);
|
int dch = (dalpha ? 4 : 3);
|
||||||
|
|
||||||
@@ -399,27 +377,25 @@ RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
|
|||||||
dwi = (image->width - width)*dch;
|
dwi = (image->width - width)*dch;
|
||||||
|
|
||||||
c_opaqueness = 255 - opaqueness;
|
c_opaqueness = 255 - opaqueness;
|
||||||
|
|
||||||
#define OP opaqueness
|
#define OP opaqueness
|
||||||
if (!HAS_ALPHA(src)) {
|
|
||||||
#define COP c_opaqueness
|
#define COP c_opaqueness
|
||||||
|
|
||||||
|
if (!HAS_ALPHA(src)) {
|
||||||
|
|
||||||
s = src->data + sy*src->width*3;
|
s = src->data + sy*src->width*3;
|
||||||
swi = (src->width - width) * 3;
|
swi = (src->width - width) * 3;
|
||||||
|
|
||||||
for (y=0; y < height; y++) {
|
for (y=0; y < height; y++) {
|
||||||
for (x=0; x < width; x++) {
|
for (x=0; x < width; x++) {
|
||||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
|
||||||
s++; d++;
|
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
|
||||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256; s++; d++;
|
||||||
s++; d++;
|
|
||||||
*d = (((int)*d *(int)COP) + ((int)*s *(int)OP))/256;
|
|
||||||
s++; d++;
|
|
||||||
if (dalpha)
|
if (dalpha)
|
||||||
d++;
|
d++;
|
||||||
}
|
}
|
||||||
d += dwi; s += swi;
|
d += dwi; s += swi;
|
||||||
}
|
}
|
||||||
#undef COP
|
|
||||||
} else {
|
} else {
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
@@ -429,12 +405,9 @@ RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
|
|||||||
for (y=0; y < height; y++) {
|
for (y=0; y < height; y++) {
|
||||||
for (x=0; x < width; x++) {
|
for (x=0; x < width; x++) {
|
||||||
tmp = (*(s+3) * opaqueness)/256;
|
tmp = (*(s+3) * opaqueness)/256;
|
||||||
*d = (((int)*d *(int)(255-tmp)) + ((int)*s *(int)tmp))/256;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
d++; s++;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
*d = (((int)*d *(int)(255-tmp)) + ((int)*s *(int)tmp))/256;
|
*d = (((int)*d * (255-tmp)) + ((int)*s * tmp))/256; d++; s++;
|
||||||
d++; s++;
|
|
||||||
*d = (((int)*d *(int)(255-tmp)) + ((int)*s *(int)tmp))/256;
|
|
||||||
d++; s++;
|
|
||||||
s++;
|
s++;
|
||||||
if (dalpha)
|
if (dalpha)
|
||||||
d++;
|
d++;
|
||||||
@@ -443,6 +416,7 @@ RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef OP
|
#undef OP
|
||||||
|
#undef COP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -469,12 +443,9 @@ RCombineImageWithColor(RImage *image, RColor *color)
|
|||||||
alpha = *(d+3);
|
alpha = *(d+3);
|
||||||
nalpha = 255 - alpha;
|
nalpha = 255 - alpha;
|
||||||
|
|
||||||
*d = (((int)*d * alpha) + (r * nalpha))/256;
|
*d = (((int)*d * alpha) + (r * nalpha))/256; d++;
|
||||||
d++;
|
*d = (((int)*d * alpha) + (g * nalpha))/256; d++;
|
||||||
*d = (((int)*d * alpha) + (g * nalpha))/256;
|
*d = (((int)*d * alpha) + (b * nalpha))/256; d++;
|
||||||
d++;
|
|
||||||
*d = (((int)*d * alpha) + (b * nalpha))/256;
|
|
||||||
d++;
|
|
||||||
d++;
|
d++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#ifndef PI
|
#ifndef PI
|
||||||
#define PI 3.14159265
|
#define PI 3.141592654
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -412,6 +412,7 @@ CLIST *contrib; /* array of contribution lists */
|
|||||||
#define CLAMP(v,l,h) ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
|
#define CLAMP(v,l,h) ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
|
||||||
|
|
||||||
|
|
||||||
|
/* return of calloc is not checked if NULL in the function below! */
|
||||||
RImage*
|
RImage*
|
||||||
RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
|
RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user