1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 04:48:06 +01:00

bug fixes, performance enhancement for image rendering

This commit is contained in:
kojima
1999-04-29 23:05:16 +00:00
parent d6f2dd663e
commit 8f68cfd8cd
19 changed files with 371 additions and 192 deletions

View File

@@ -21,8 +21,10 @@ Changes since version 0.53.0:
- added high-quality filtered rescaling (smoothed rescaling) to wrlib/wmsetbg
- added SmoothWorkspaceBack
- fixed crash bug in Paths section of WPrefs
- optimized image rendering for 15/16 bpp
- user menus' paths were changed. See NEWS.
Changes since version 0.52.0:
.............................

2
TODO
View File

@@ -8,9 +8,7 @@ Do ASAP:
- blink border of clients with UrgencyHint set between red and black
- finish session stuff
- add multiline support for balloons
- move/add balloon to WINGs
- finish XStandardColormap stuff in wrlib
- finish menu editor/other stuff in wprefs
Need to do:
===========

View File

@@ -188,6 +188,12 @@ W_BalloonHandleLeaveView(WMView *view)
}
/*
* botar balao perto do cursor
* so mapear balao se o mouse ficar parado pelo delay
*
*/
static void
showBalloon(void *data)
{

View File

@@ -1180,6 +1180,7 @@ handleTextFieldActionEvents(XEvent *event, void *data)
if (tPtr->flags.pointerGrabbed) {
tPtr->flags.pointerGrabbed = 0;
XUngrabPointer(WMScreenDisplay(W_VIEW(tPtr)->screen), CurrentTime);
break;
}
move = 1;

View File

@@ -158,6 +158,10 @@ createPanel(Panel *p)
WMMoveWidget(panel->sizeF, 20, 10);
WMSetFrameTitle(panel->sizeF, _("Size Display"));
WMSetBalloonTextForView(WMWidgetView(panel->posiF),
_("The position or style of the window size\n"
"display that's shown when a window is resized."));
panel->sizeP = WMCreatePopUpButton(panel->sizeF);
WMResizeWidget(panel->sizeP, 180, 20);
WMMoveWidget(panel->sizeP, 32, 24);
@@ -174,6 +178,10 @@ createPanel(Panel *p)
WMMoveWidget(panel->posiF, 20, 75);
WMSetFrameTitle(panel->posiF, _("Position Display"));
WMSetBalloonTextForView(WMWidgetView(panel->posiF),
_("The position or style of the window position\n"
"display that's shown when a window is moved."));
panel->posiP = WMCreatePopUpButton(panel->posiF);
WMResizeWidget(panel->posiP, 180, 20);
WMMoveWidget(panel->posiP, 32, 24);

View File

@@ -862,7 +862,7 @@ handleLogoPush(XEvent *event, void *data)
clicks++;
if (!panel->timer && !broken && clicks > 2) {
if (!panel->timer && !broken && clicks > 0) {
char *file;
char *path;

View File

@@ -57,6 +57,10 @@ static void paintButton(WCoreWindow *button, WTexture *texture,
static void updateTitlebar(WFrameWindow *fwin);
static void remakeTexture(WFrameWindow *fwin, int state, int newWidth);
static void updateTexture(WFrameWindow *fwin);
WFrameWindow*
wFrameWindowCreate(WScreen *scr, int wlevel, int x, int y,
@@ -138,7 +142,9 @@ wFrameWindowUpdateBorders(WFrameWindow *fwin, int flags)
if (flags & WFF_TITLEBAR) {
fwin->top_width = theight;
fwin->flags.need_texture_remake = 1;
fwin->flags.need_texture1_remake = 1;
fwin->flags.need_texture2_remake = 1;
fwin->flags.need_texture3_remake = 1;
if (wPreferences.new_style) {
if (fwin->left_button) {
@@ -245,7 +251,9 @@ wFrameWindowUpdateBorders(WFrameWindow *fwin, int flags)
XMapRaised(dpy, fwin->titlebar->window);
fwin->flags.need_texture_remake = 1;
fwin->flags.need_texture1_remake = 1;
fwin->flags.need_texture2_remake = 1;
fwin->flags.need_texture3_remake = 1;
}
}
checkTitleSize(fwin);
@@ -272,7 +280,9 @@ wFrameWindowUpdateBorders(WFrameWindow *fwin, int flags)
XMapWindow(dpy, fwin->resizebar->window);
XLowerWindow(dpy, fwin->resizebar->window);
fwin->flags.need_texture_remake = 1;
fwin->flags.need_texture1_remake = 1;
fwin->flags.need_texture2_remake = 1;
fwin->flags.need_texture3_remake = 1;
} else {
if (height+fwin->top_width+fwin->bottom_width != fwin->core->height) {
wCoreConfigure(fwin->resizebar, 0, height + fwin->top_width,
@@ -405,8 +415,11 @@ updateTitlebar(WFrameWindow *fwin)
}
}
if (wPreferences.new_style || fwin->titlebar->width!=w)
fwin->flags.need_texture_remake = 1;
if (wPreferences.new_style || fwin->titlebar->width!=w) {
fwin->flags.need_texture1_remake = 1;
fwin->flags.need_texture2_remake = 1;
fwin->flags.need_texture3_remake = 1;
}
wCoreConfigure(fwin->titlebar, x, 0, w, theight);
}
@@ -646,12 +659,13 @@ updateTexture(WFrameWindow *fwin)
handleButtonExpose(&fwin->right_button->descriptor, NULL);
}
}
XFlush(dpy);
}
static void
remakeTexture(WFrameWindow *fwin, int state)
remakeTexture(WFrameWindow *fwin, int state, int newWidth)
{
Pixmap pmap, lpmap, rpmap;
@@ -672,7 +686,7 @@ remakeTexture(WFrameWindow *fwin, int state)
right = fwin->right_button && !fwin->flags.hide_right_button
&& !fwin->flags.rbutton_dont_fit;
width = fwin->core->width+1;
width = newWidth+1;
renderTexture(fwin->screen_ptr, fwin->title_texture[state],
width, fwin->titlebar->height,
@@ -687,7 +701,7 @@ remakeTexture(WFrameWindow *fwin, int state)
}
}
if (fwin->resizebar_texture && fwin->resizebar_texture[0]
&& fwin->resizebar && state == 0) {
&& fwin->resizebar && state == fwin->flags.state) {
FREE_PIXMAP(fwin->resizebar_back[0]);
@@ -695,8 +709,7 @@ remakeTexture(WFrameWindow *fwin, int state)
renderResizebarTexture(fwin->screen_ptr,
fwin->resizebar_texture[0],
fwin->resizebar->width,
fwin->resizebar->height,
newWidth, fwin->resizebar->height,
fwin->resizebar_corner_width,
&pmap);
@@ -722,25 +735,36 @@ wFrameWindowPaint(WFrameWindow *fwin)
if (fwin->flags.is_client_window_frame)
fwin->flags.justification = wPreferences.title_justification;
if (fwin->flags.need_texture_remake) {
int i;
fwin->flags.need_texture_remake = 0;
fwin->flags.need_texture_change = 0;
if (fwin->flags.need_texture1_remake || fwin->flags.need_texture2_remake
|| fwin->flags.need_texture3_remake) {
if (fwin->flags.single_texture) {
remakeTexture(fwin, 0);
updateTexture(fwin);
} else {
/* first render the texture for the current state... */
remakeTexture(fwin, fwin->flags.state);
/* ... and paint it */
updateTexture(fwin);
for (i=0; i < 3; i++) {
if (i!=fwin->flags.state)
remakeTexture(fwin, i);
}
fwin->flags.need_texture_change = 1;
fwin->flags.need_texture1_remake = 0;
fwin->flags.need_texture2_remake = 0;
fwin->flags.need_texture3_remake = 0;
remakeTexture(fwin, 0, fwin->core->width);
} else if (fwin->flags.state==0 && fwin->flags.need_texture1_remake) {
fwin->flags.need_texture_change = 1;
fwin->flags.need_texture1_remake = 0;
remakeTexture(fwin, fwin->flags.state, fwin->core->width);
} else if (fwin->flags.state==1 && fwin->flags.need_texture2_remake) {
fwin->flags.need_texture_change = 1;
fwin->flags.need_texture2_remake = 0;
remakeTexture(fwin, fwin->flags.state, fwin->core->width);
} else if (fwin->flags.state==2 && fwin->flags.need_texture3_remake) {
fwin->flags.need_texture_change = 1;
fwin->flags.need_texture3_remake = 0;
remakeTexture(fwin, fwin->flags.state, fwin->core->width);
}
}
@@ -853,7 +877,7 @@ wFrameWindowPaint(WFrameWindow *fwin)
}
#ifdef TITLE_TEXT_SHADOW
if(wPreferences.title_shadow){
if(wPreferences.title_shadow) {
int shadowx,shadowy;
XSetForeground(dpy, *fwin->title_gc,
fwin->title_pixel[fwin->flags.state+3]);
@@ -904,7 +928,6 @@ reconfigure(WFrameWindow *fwin, int x, int y, int width, int height,
height - fwin->resizebar->height);
*/
if (fwin->core->width != width) {
fwin->flags.need_texture_remake = 1;
resizedHorizontally = 1;
}
@@ -973,12 +996,14 @@ reconfigure(WFrameWindow *fwin, int x, int y, int width, int height,
}
}
void
wFrameWindowConfigure(WFrameWindow *fwin, int x, int y, int width, int height)
{
reconfigure(fwin, x, y, width, height, False);
}
void
wFrameWindowResize(WFrameWindow *fwin, int width, int height)
{

View File

@@ -98,7 +98,11 @@ typedef struct WFrameWindow {
unsigned int resizebar:1;
unsigned int left_button:1;
unsigned int right_button:1;
unsigned int need_texture_remake:1;
unsigned int need_texture1_remake:1;
unsigned int need_texture2_remake:1;
unsigned int need_texture3_remake:1;
unsigned int single_texture:1;
unsigned int hide_left_button:1;

View File

@@ -118,7 +118,7 @@ appearanceObserver(void *self, WMNotification *notif)
wMenuRealize(menu);
}
if (flags & WTextureSettings) {
menu->frame->flags.need_texture_remake = 1;
menu->frame->flags.need_texture1_remake = 1;
}
if (flags & (WColorSettings|WTextureSettings))
wFrameWindowPaint(menu->frame);

View File

@@ -714,7 +714,10 @@ wScreenInit(int screen_number)
/* screen descriptor for raster graphic library */
rattr.flags = RC_RenderMode | RC_ColorsPerChannel;
rattr.render_mode = wPreferences.no_dithering?RM_MATCH:RM_DITHER;
rattr.render_mode = wPreferences.no_dithering
? RBestMatchRendering
: RDitheredRendering;
rattr.colors_per_channel = wPreferences.cmap_size;
if (rattr.colors_per_channel<2)
rattr.colors_per_channel = 2;

View File

@@ -363,7 +363,7 @@
#define MENU_SELECT_DELAY 200
/* delay for jumpback of scrolled menus */
#define MENU_JUMP_BACK_DELAY 300
#define MENU_JUMP_BACK_DELAY 400
/* *** animation speed constants *** */

View File

@@ -144,7 +144,9 @@ appearanceObserver(void *self, WMNotification *notif)
wWindowConfigureBorders(wwin);
}
if (flags & WTextureSettings) {
wwin->frame->flags.need_texture_remake = 1;
wwin->frame->flags.need_texture1_remake = 1;
wwin->frame->flags.need_texture2_remake = 1;
wwin->frame->flags.need_texture3_remake = 1;
}
if (flags & (WTextureSettings | WColorSettings)) {
if (wwin->frame->titlebar)

View File

@@ -42,7 +42,7 @@ static Bool bestContext(Display *dpy, int screen_number, RContext *context);
static RContextAttributes DEFAULT_CONTEXT_ATTRIBS = {
RC_UseSharedMemory|RC_RenderMode|RC_ColorsPerChannel, /* flags */
RM_DITHER, /* render_mode */
RDitheredRendering, /* render_mode */
4, /* colors_per_channel */
0,
0,
@@ -204,7 +204,7 @@ allocateGrayScale(RContext *ctx)
if (ncolors>=256 && ctx->vclass==StaticGray) {
/* don't need dithering for 256 levels of gray in StaticGray visual */
ctx->attribs->render_mode = RM_MATCH;
ctx->attribs->render_mode = RBestMatchRendering;
}
colors = malloc(sizeof(XColor)*ncolors);
@@ -491,7 +491,7 @@ RCreateContext(Display *dpy, int screen_number, RContextAttributes *attribs)
context->blue_offset = count_offset(context->visual->blue_mask);
/* disable dithering on 24 bits visuals */
if (context->depth >= 24)
context->attribs->render_mode = RM_MATCH;
context->attribs->render_mode = RBestMatchRendering;
}
/* check avaiability of MIT-SHM */

View File

@@ -93,6 +93,147 @@ computeTable(unsigned short mask)
}
static RXImage*
image2TrueColorD16(RContext *ctx, RImage *image)
{
RXImage *ximg;
register int x, y, r, g, b;
unsigned char *red, *grn, *blu;
unsigned short rmask, gmask, bmask;
unsigned short roffs, goffs, boffs;
unsigned short *rtable, *gtable, *btable;
int ofs;
ximg = RCreateXImage(ctx, ctx->depth, image->width, image->height);
if (!ximg) {
return NULL;
}
red = image->data[0];
grn = image->data[1];
blu = image->data[2];
roffs = ctx->red_offset;
goffs = ctx->green_offset;
boffs = ctx->blue_offset;
rmask = ctx->visual->red_mask >> roffs;
gmask = ctx->visual->green_mask >> goffs;
bmask = ctx->visual->blue_mask >> boffs;
rtable = computeTable(rmask);
gtable = computeTable(gmask);
btable = computeTable(bmask);
if (rtable==NULL || gtable==NULL || btable==NULL) {
RErrorCode = RERR_NOMEMORY;
RDestroyXImage(ctx, ximg);
return NULL;
}
{
/* dither */
short *rerr, *gerr, *berr;
short *nrerr, *ngerr, *nberr;
short *terr;
unsigned short *dataP;
int line_offset;
int rer, ger, ber;
const int dr=0xff/rmask;
const int dg=0xff/gmask;
const int db=0xff/bmask;
rerr = (short*)alloca((image->width+2)*sizeof(short));
gerr = (short*)alloca((image->width+2)*sizeof(short));
berr = (short*)alloca((image->width+2)*sizeof(short));
nrerr = (short*)alloca((image->width+2)*sizeof(short));
ngerr = (short*)alloca((image->width+2)*sizeof(short));
nberr = (short*)alloca((image->width+2)*sizeof(short));
if (!rerr || !gerr || !berr || !nrerr || !ngerr || !nberr) {
RErrorCode = RERR_NOMEMORY;
RDestroyXImage(ctx, ximg);
return NULL;
}
for (x=0; x<image->width; x++) {
rerr[x] = red[x];
gerr[x] = grn[x];
berr[x] = blu[x];
}
rerr[x] = gerr[x] = berr[x] = 0;
dataP = (unsigned short*)ximg->image->data;
line_offset = ximg->image->bytes_per_line - image->width * 2;
/* convert and dither the image to XImage */
for (y=0, ofs=0; y<image->height; y++) {
if (y<image->height-1) {
int x1;
for (x=0, x1=ofs+image->width; x<image->width; x++, x1++) {
nrerr[x] = red[x1];
ngerr[x] = grn[x1];
nberr[x] = blu[x1];
}
/* last column */
x1--;
nrerr[x] = red[x1];
ngerr[x] = grn[x1];
nberr[x] = blu[x1];
}
for (x=0; x<image->width; x++) {
/* reduce pixel */
if (rerr[x]>0xff) rerr[x]=0xff; else if (rerr[x]<0) rerr[x]=0;
if (gerr[x]>0xff) gerr[x]=0xff; else if (gerr[x]<0) gerr[x]=0;
if (berr[x]>0xff) berr[x]=0xff; else if (berr[x]<0) berr[x]=0;
r = rtable[rerr[x]];
g = gtable[gerr[x]];
b = btable[berr[x]];
*(dataP++) = (r<<roffs) | (g<<goffs) | (b<<boffs);
/* calc error */
rer = rerr[x] - r*dr;
ger = gerr[x] - g*dg;
ber = berr[x] - b*db;
/* distribute error */
r = (rer*3)/8;
g = (ger*3)/8;
b = (ber*3)/8;
/* x+1, y */
rerr[x+1]+=r;
gerr[x+1]+=g;
berr[x+1]+=b;
/* x, y+1 */
nrerr[x]+=r;
ngerr[x]+=g;
nberr[x]+=b;
/* x+1, y+1 */
nrerr[x+1]+=rer-2*r;
ngerr[x+1]+=ger-2*g;
nberr[x+1]+=ber-2*b;
}
ofs += image->width;
(char*)dataP += line_offset;
/* skip to next line */
terr = rerr;
rerr = nrerr;
nrerr = terr;
terr = gerr;
gerr = ngerr;
ngerr = terr;
terr = berr;
berr = nberr;
nberr = terr;
}
}
return ximg;
}
static RXImage*
image2TrueColor(RContext *ctx, RImage *image)
{
@@ -151,7 +292,7 @@ image2TrueColor(RContext *ctx, RImage *image)
return NULL;
}
if (ctx->attribs->render_mode==RM_MATCH) {
if (ctx->attribs->render_mode==RBestMatchRendering) {
/* fake match */
#ifdef DEBUG
puts("true color match");
@@ -264,6 +405,8 @@ image2TrueColor(RContext *ctx, RImage *image)
}
static RXImage*
image2PseudoColor(RContext *ctx, RImage *image)
{
@@ -303,7 +446,7 @@ image2PseudoColor(RContext *ctx, RImage *image)
return NULL;
}
if (ctx->attribs->render_mode == RM_MATCH) {
if (ctx->attribs->render_mode == RBestMatchRendering) {
/* fake match */
#ifdef DEBUG
printf("pseudo color match with %d colors per channel\n", cpc);
@@ -477,7 +620,7 @@ image2GrayScale(RContext *ctx, RImage *image)
return NULL;
}
if (ctx->attribs->render_mode == RM_MATCH) {
if (ctx->attribs->render_mode == RBestMatchRendering) {
/* fake match */
#ifdef DEBUG
printf("grayscale match with %d colors per channel\n", cpc);
@@ -594,9 +737,15 @@ RConvertImage(RContext *context, RImage *image, Pixmap *pixmap)
assert(pixmap!=NULL);
/* clear error message */
if (context->vclass == TrueColor)
if (context->vclass == TrueColor) {
if (context->attribs->render_mode == RDitheredRendering
&& (context->depth == 15 || context->depth == 16))
ximg = image2TrueColorD16(context, image);
else
ximg = image2TrueColor(context, image);
else if (context->vclass == PseudoColor || context->vclass == StaticColor)
} else if (context->vclass == PseudoColor || context->vclass == StaticColor)
ximg = image2PseudoColor(context, image);
else if (context->vclass == GrayScale || context->vclass == StaticGray)
ximg = image2GrayScale(context, image);
@@ -696,37 +845,6 @@ RConvertImageMask(RContext *context, RImage *image, Pixmap *pixmap,
}
int
RSmoothScaleBorderConvertImage(RContext *context, RImage *image,
int newWidth, int newHeight, int borderType,
Pixmap *pixmap)
{
return False;
}
int
RScaleBorderConvertImage(RContext *context, RImage *image,
int newWidth, int newHeight, int borderType,
Pixmap *pixmap)
{
return False;
}
Bool
RGetClosestXColor(RContext *context, RColor *color, XColor *retColor)
{
@@ -801,3 +919,4 @@ RGetClosestXColor(RContext *context, RColor *color, XColor *retColor)
return True;
}

View File

@@ -48,102 +48,101 @@
*----------------------------------------------------------------------
*/
RImage*
RScaleImage(RImage *image, unsigned new_width, unsigned new_height)
RScaleImage(RImage *src, unsigned new_width, unsigned new_height)
{
int ox;
int px, py;
register int x, y, t;
int dx, dy;
int ddy, ee;
int h2;
int yd;
int xd, xs;
RImage *dst;
int e, xd2;
unsigned char *sr, *sg, *sb, *sa;
unsigned char *dr, *dg, *db, *da;
RImage *img;
int ys = 0;
assert(new_width >= 0 && new_height >= 0);
if (new_width == image->width && new_height == image->height)
return RCloneImage(image);
img = RCreateImage(new_width, new_height, image->data[3]!=NULL);
dst = RCreateImage(new_width, new_height, src->data[3]!=NULL);
if (!img)
return NULL;
ddy = src->height/2;
ee = (ddy/2) - dst->height;
h2 = new_height/2;
/* fixed point math idea taken from Imlib by
* Carsten Haitzler (Rasterman) */
dx = (image->width<<16)/new_width;
dy = (image->height<<16)/new_height;
xd = dst->width;
xs = src->width/2;
e = (src->width/2)-xd;
xd2 = xd/2;
py = 0;
sr = src->data[0];
sg = src->data[1];
sb = src->data[2];
sa = src->data[3];
dr = img->data[0];
dg = img->data[1];
db = img->data[2];
da = img->data[3];
dr = dst->data[0];
dg = dst->data[1];
db = dst->data[2];
da = dst->data[3];
if (image->data[3]!=NULL) {
int ot;
ot = -1;
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
if (sa == NULL) {
for (yd = 0; yd < new_height; yd++) {
int x;
sr = image->data[0]+t;
sg = image->data[1]+t;
sb = image->data[2]+t;
sa = image->data[3]+t;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
ot = t;
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
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;
}
} else {
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;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
*(da++) = *sa;
t = (px - ox)>>16;
ox += t<<16;
sr += t;
sg += t;
sb += t;
sa += t;
while (e >= 0) {
sr++;
sg++;
sb++;
sa++;
e -= xd2;
}
py += dy;
e += xs;
}
} else {
int ot;
ot = -1;
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
sr = image->data[0]+t;
sg = image->data[1]+t;
sb = image->data[2]+t;
ot = t;
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
t = (px-ox)>>16;
ox += t<<16;
sr += t;
sg += t;
sb += t;
while (ee >= 0) {
ys++;
ee -= h2;
}
py += dy;
ee += ddy;
}
}
return img;
return dst;
}
@@ -159,7 +158,7 @@ RScaleImage(RImage *image, unsigned new_width, unsigned new_height)
/*
* filter function definitions
*/
#if 0
#define filter_support (1.0)
static double
@@ -171,7 +170,7 @@ double t;
if(t < 1.0) return((2.0 * t - 3.0) * t * t + 1.0);
return(0.0);
}
#endif
#define box_support (0.5)
static double
@@ -304,8 +303,8 @@ _wraster_change_filter(int type)
break;
default:
case RMitchellFilter:
filterf = Mitchell_support;
fwidth = Mitchell_filter;
filterf = Mitchell_filter;
fwidth = Mitchell_support;
break;
}
}
@@ -332,7 +331,7 @@ CLIST *contrib; /* array of contribution lists */
RImage*
RSmoothScaleImage(RImage *src, int newWidth, int newHeight)
RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
{
RImage *tmp; /* intermediate image */
double xscale, yscale; /* zoom scale factors */
@@ -345,19 +344,19 @@ RSmoothScaleImage(RImage *src, int newWidth, int newHeight)
unsigned char *rp, *gp, *bp;
unsigned char *rsp, *gsp, *bsp;
dst = RCreateImage(newWidth, newHeight, False);
dst = RCreateImage(new_width, new_height, False);
/* create intermediate image to hold horizontal zoom */
tmp = RCreateImage(dst->width, src->height, False);
xscale = (double)newWidth / (double)src->width;
yscale = (double)newHeight / (double)src->height;
xscale = (double)new_width / (double)src->width;
yscale = (double)new_height / (double)src->height;
/* pre-calculate filter contributions for a row */
contrib = (CLIST *)calloc(newWidth, sizeof(CLIST));
contrib = (CLIST *)calloc(new_width, sizeof(CLIST));
if (xscale < 1.0) {
width = fwidth / xscale;
fscale = 1.0 / xscale;
for (i = 0; i < newWidth; ++i) {
for (i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int)(width * 2 + 1),
sizeof(CONTRIB));
@@ -380,7 +379,7 @@ RSmoothScaleImage(RImage *src, int newWidth, int newHeight)
}
}
} else {
for(i = 0; i < newWidth; ++i) {
for(i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
@@ -490,7 +489,7 @@ RSmoothScaleImage(RImage *src, int newWidth, int newHeight)
gsp = malloc(tmp->height);
bsp = malloc(tmp->height);
for(k = 0; k < newWidth; ++k) {
for(k = 0; k < new_width; ++k) {
rp = dst->data[0] + k;
gp = dst->data[1] + k;
bp = dst->data[2] + k;
@@ -516,7 +515,7 @@ RSmoothScaleImage(RImage *src, int newWidth, int newHeight)
*d++ = *p;
}
}
for(i = 0; i < newHeight; ++i) {
for(i = 0; i < new_height; ++i) {
rweight = gweight = bweight = 0.0;
for(j = 0; j < contrib[i].n; ++j) {
rweight += rsp[contrib[i].p[j].pixel] * contrib[i].p[j].weight;
@@ -526,9 +525,9 @@ RSmoothScaleImage(RImage *src, int newWidth, int newHeight)
*rp = CLAMP(rweight, 0, 255);
*gp = CLAMP(gweight, 0, 255);
*bp = CLAMP(bweight, 0, 255);
rp += newWidth;
gp += newWidth;
bp += newWidth;
rp += new_width;
gp += new_width;
bp += new_width;
}
}
free(rsp);

View File

@@ -526,7 +526,7 @@ int main(int argc, char **argv)
attr.flags = RC_RenderMode | RC_ColorsPerChannel;
attr.render_mode = RM_DITHER;
attr.render_mode = RDitheredRendering;
attr.colors_per_channel = 4;
if (visualID >= 0) {

View File

@@ -34,7 +34,7 @@ int main(int argc, char **argv)
{
RContextAttributes attr;
RColor **colors = NULL;
int i, rmode = RM_DITHER, ncolors = 0, cpc = 4;
int i, rmode = RDitheredRendering, ncolors = 0, cpc = 4;
char **color_name;
XColor color;
XSetWindowAttributes val;
@@ -59,9 +59,9 @@ int main(int argc, char **argv)
if (argc>1) {
for (i=1; i<argc; i++) {
if (strcmp(argv[i], "-m")==0) {
rmode = RM_MATCH;
rmode = RBestMatchRendering;
} else if (strcmp(argv[i], "-d")==0) {
rmode = RM_DITHER;
rmode = RDitheredRendering;
} else if (strcmp(argv[i], "-c")==0) {
i++;
if (i>=argc) {
@@ -161,11 +161,11 @@ int main(int argc, char **argv)
gettimeofday(&timev, NULL);
t1 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);
if (i%3==0)
imgh = RRenderMultiGradient(250, 250, colors, RGRD_HORIZONTAL);
imgh = RRenderMultiGradient(550, 550, colors, RGRD_HORIZONTAL);
else if (i%3==1)
imgh = RRenderMultiGradient(250, 250, colors, RGRD_VERTICAL);
imgh = RRenderMultiGradient(550, 550, colors, RGRD_VERTICAL);
else
imgh = RRenderMultiGradient(250, 250, colors, RGRD_DIAGONAL);
imgh = RRenderMultiGradient(550, 550, colors, RGRD_DIAGONAL);
gettimeofday(&timev, NULL);
t2 = (double)timev.tv_sec + (((double)timev.tv_usec)/1000000);

View File

@@ -9,6 +9,8 @@ RContext *ctx;
RImage *img;
Pixmap pix;
int main(int argc, char **argv)
{
RContextAttributes attr;
@@ -19,7 +21,7 @@ int main(int argc, char **argv)
exit(1);
}
attr.flags = RC_RenderMode | RC_ColorsPerChannel;
attr.render_mode = RM_DITHER;
attr.render_mode = RDitheredRendering;
attr.colors_per_channel = 4;
ctx = RCreateContext(dpy, DefaultScreen(dpy), &attr);
if (argc<2)
@@ -31,18 +33,27 @@ int main(int argc, char **argv)
puts(RMessageForError(RErrorCode));
exit(1);
}
/*
if (argc > 2) {
RImage *tmp = img;
img = RSmoothScaleImage(tmp, tmp->width*atol(argv[2]),
tmp->height*atol(argv[2]));
RDestroyImage(tmp);
}
*/
if (argc > 2) {
img = RScaleImage(img, img->width*atof(argv[2]),
img->height*atof(argv[2]));
}
if (!RConvertImage(ctx, img, &pix)) {
puts(RMessageForError(RErrorCode));
exit(1);
}
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, img->width,
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10,
img->width,
img->height, 0, 0, 0);
RDestroyImage(img);
XSetWindowBackgroundPixmap(dpy, win, pix);

View File

@@ -322,7 +322,8 @@ void RCombineAreaWithOpaqueness(RImage *image, RImage *src, int sx, int sy,
RImage *RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
RImage *RSmoothScaleImage(RImage *src, int newWidth, int newHeight);
RImage *RSmoothScaleImage(RImage *src, unsigned new_width,
unsigned new_height);
RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);