From 8f68cfd8cd78536818e4014721683a054066ba08 Mon Sep 17 00:00:00 2001 From: kojima Date: Thu, 29 Apr 1999 23:05:16 +0000 Subject: [PATCH] bug fixes, performance enhancement for image rendering --- ChangeLog | 2 + TODO | 2 - WINGs/wballoon.c | 6 ++ WINGs/wtextfield.c | 1 + WPrefs.app/Preferences.c | 10 ++- src/dialog.c | 2 +- src/framewin.c | 103 +++++++++++++++---------- src/framewin.h | 6 +- src/menu.c | 2 +- src/screen.c | 5 +- src/wconfig.h.in | 2 +- src/window.c | 4 +- wrlib/context.c | 6 +- wrlib/convert.c | 197 +++++++++++++++++++++++++++++++++++++---------- wrlib/scale.c | 181 ++++++++++++++++++++++--------------------- wrlib/testdraw.c | 2 +- wrlib/testgrad.c | 12 +-- wrlib/view.c | 15 +++- wrlib/wraster.h | 3 +- 19 files changed, 370 insertions(+), 191 deletions(-) diff --git a/ChangeLog b/ChangeLog index cff90cad..8062625a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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: ............................. diff --git a/TODO b/TODO index d1afb832..fbf41ce3 100644 --- a/TODO +++ b/TODO @@ -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: =========== diff --git a/WINGs/wballoon.c b/WINGs/wballoon.c index 2f491b81..fbe06da4 100644 --- a/WINGs/wballoon.c +++ b/WINGs/wballoon.c @@ -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) { diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c index 1d22d6d5..d2804b4e 100644 --- a/WINGs/wtextfield.c +++ b/WINGs/wtextfield.c @@ -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; diff --git a/WPrefs.app/Preferences.c b/WPrefs.app/Preferences.c index 101fc3b4..d95ceba5 100644 --- a/WPrefs.app/Preferences.c +++ b/WPrefs.app/Preferences.c @@ -157,7 +157,11 @@ createPanel(Panel *p) WMResizeWidget(panel->sizeF, 240, 60); 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); diff --git a/src/dialog.c b/src/dialog.c index 1fba21f2..91266e6a 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -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; diff --git a/src/framewin.c b/src/framewin.c index d0218315..cbd8b3b2 100644 --- a/src/framewin.c +++ b/src/framewin.c @@ -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,13 +142,15 @@ 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) { wCoreConfigure(fwin->left_button, 0, 0, bsize, bsize); } - + if (fwin->right_button) { wCoreConfigure(fwin->right_button, width-bsize+1, 0, bsize, bsize); @@ -154,7 +160,7 @@ wFrameWindowUpdateBorders(WFrameWindow *fwin, int flags) wCoreConfigure(fwin->left_button, 3, (theight-bsize)/2, bsize, bsize); } - + if (fwin->right_button) { wCoreConfigure(fwin->right_button, width-bsize-3, (theight-bsize)/2, bsize, bsize); @@ -173,25 +179,25 @@ wFrameWindowUpdateBorders(WFrameWindow *fwin, int flags) if (fwin->left_button) wCoreDestroy(fwin->left_button); fwin->left_button = NULL; - + if (fwin->right_button) wCoreDestroy(fwin->right_button); fwin->right_button = NULL; - + wCoreDestroy(fwin->titlebar); fwin->titlebar = NULL; - + fwin->top_width = 0; } } else { /* if we didn't have a titlebar and are being requested for * one, create it */ - if (flags & WFF_TITLEBAR) { + if (flags & WFF_TITLEBAR) { fwin->top_width = theight; - + fwin->flags.titlebar = 1; fwin->titlebar = wCoreCreate(fwin->core, 0, 0, width+1, theight); - + if (flags & WFF_LEFT_BUTTON) { fwin->flags.left_button = 1; if (wPreferences.new_style) { @@ -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,31 +735,42 @@ 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); } } if (fwin->flags.need_texture_change) { fwin->flags.need_texture_change = 0; - + updateTexture(fwin); } @@ -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) { diff --git a/src/framewin.h b/src/framewin.h index f74f736d..ea670451 100644 --- a/src/framewin.h +++ b/src/framewin.h @@ -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; diff --git a/src/menu.c b/src/menu.c index a576f947..3b45c8b1 100644 --- a/src/menu.c +++ b/src/menu.c @@ -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); diff --git a/src/screen.c b/src/screen.c index 5040875b..9ec23758 100644 --- a/src/screen.c +++ b/src/screen.c @@ -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; diff --git a/src/wconfig.h.in b/src/wconfig.h.in index 62aef7de..8928721e 100644 --- a/src/wconfig.h.in +++ b/src/wconfig.h.in @@ -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 *** */ diff --git a/src/window.c b/src/window.c index e4dbcc1d..79e1c442 100644 --- a/src/window.c +++ b/src/window.c @@ -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) diff --git a/wrlib/context.c b/wrlib/context.c index 11bdafcd..aded9003 100644 --- a/wrlib/context.c +++ b/wrlib/context.c @@ -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 */ diff --git a/wrlib/convert.c b/wrlib/convert.c index cc1e2066..91641f33 100644 --- a/wrlib/convert.c +++ b/wrlib/convert.c @@ -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; xwidth; 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; yheight; y++) { + if (yheight-1) { + int x1; + for (x=0, x1=ofs+image->width; xwidth; 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; xwidth; 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<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,12 +737,18 @@ RConvertImage(RContext *context, RImage *image, Pixmap *pixmap) assert(pixmap!=NULL); /* clear error message */ - if (context->vclass == TrueColor) - ximg = image2TrueColor(context, image); - else if (context->vclass == PseudoColor || context->vclass == StaticColor) - ximg = image2PseudoColor(context, image); + 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) + ximg = image2PseudoColor(context, image); else if (context->vclass == GrayScale || context->vclass == StaticGray) - ximg = image2GrayScale(context, image); + ximg = image2GrayScale(context, image); if (!ximg) { #ifdef C_ALLOCA @@ -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; } + diff --git a/wrlib/scale.c b/wrlib/scale.c index 3e7d48fa..15291aeb 100644 --- a/wrlib/scale.c +++ b/wrlib/scale.c @@ -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); + dst = RCreateImage(new_width, new_height, src->data[3]!=NULL); - img = RCreateImage(new_width, new_height, image->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; - - dr = img->data[0]; - dg = img->data[1]; - db = img->data[2]; - da = img->data[3]; - - if (image->data[3]!=NULL) { - int ot; - ot = -1; - for (y=0; ywidth*(py>>16); - - sr = image->data[0]+t; - sg = image->data[1]+t; - sb = image->data[2]+t; - sa = image->data[3]+t; - - ot = t; - ox = 0; - px = 0; - for (x=0; xdata[0]; + sg = src->data[1]; + sb = src->data[2]; + sa = src->data[3]; + + dr = dst->data[0]; + dg = dst->data[1]; + db = dst->data[2]; + da = dst->data[3]; + + if (sa == NULL) { + 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; + + 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++; + e -= xd2; + } + e += xs; + } + while (ee >= 0) { + ys++; + ee -= h2; } - py += dy; + ee += ddy; } } else { - int ot; - ot = -1; - for (y=0; ywidth*(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; xdata[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; - - t = (px-ox)>>16; - ox += t<<16; - - sr += t; - sg += t; - sb += t; + *(da++) = *sa; + + while (e >= 0) { + sr++; + sg++; + sb++; + sa++; + e -= xd2; + } + e += xs; + } + 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); diff --git a/wrlib/testdraw.c b/wrlib/testdraw.c index 0cf1781c..7594092b 100644 --- a/wrlib/testdraw.c +++ b/wrlib/testdraw.c @@ -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) { diff --git a/wrlib/testgrad.c b/wrlib/testgrad.c index cf02fee0..2624f113 100644 --- a/wrlib/testgrad.c +++ b/wrlib/testgrad.c @@ -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) { @@ -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); diff --git a/wrlib/view.c b/wrlib/view.c index 16d8a445..31a74eef 100644 --- a/wrlib/view.c +++ b/wrlib/view.c @@ -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,6 +33,7 @@ int main(int argc, char **argv) puts(RMessageForError(RErrorCode)); exit(1); } + /* if (argc > 2) { RImage *tmp = img; @@ -38,11 +41,19 @@ int main(int argc, char **argv) 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); diff --git a/wrlib/wraster.h b/wrlib/wraster.h index 37002318..cef890a9 100644 --- a/wrlib/wraster.h +++ b/wrlib/wraster.h @@ -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); -- 2.11.4.GIT