"matrix multiplication, efficient TrueColor raster alpha-transparency"
Brought to you by:
johnston
|
From: <ivt...@li...> - 2002-05-07 20:39:28
|
Patch: ivtools-020507-johnston-048
For: ivtools-1.0.3
Author: joh...@us...
Subject: matrix multiplication, efficient TrueColor raster alpha-transparency
Requires:
This is an intermediate patch to ivtools-1.0.3. To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:
patch -p0 <ThisFile
Summary of Changes:
- add matrix multiplication to comterp
- greatly improve the efficiency of rendering alpha-transparent
rasters with a TrueColor visual. Prior to this each input color was
being looked up in a table that could be as long as 2 to the 24th,
then the weighed average computed in floating point, then the result
rescaled into a TrueColor color. Now everything is done with nothing
more than 32 bit integer multiplies, adds, and shifts. Performance
has gone from a multi-second lag to adequately interactive.
- rename "Custom Tools" to "Extra Tools".
- migrate Attribute, Annotate, and GraphicLoc to "Extra Tools".
- add a :next flag to comdraw's import func. It attempts to
auto-increment the numerics in the last URL and import again.
Index: comterp/README
diff -c comterp/README:1.4 comterp/README:1.5
*** comterp/README:1.4 Thu Mar 21 16:14:56 2002
--- src/comterp_/README Tue May 7 13:26:16 2002
***************
*** 166,171 ****
--- 166,173 ----
matrix=xpose(matrix) -- transpose an arbitrary matrix
+ matrix=matrix*matrix -- matrix multiplication
+
STATISTICAL/RANDOM COMMANDS:
val=sum(val1[,val2[,...,valn]]) -- return sum of values
Index: src_x11/xwindow.c
diff -c src_x11/xwindow.c:1.2 src_x11/xwindow.c:1.3
*** src_x11/xwindow.c:1.2 Wed Feb 20 11:53:28 2002
--- src/IV-X11/xwindow.c Tue May 7 13:26:17 2002
***************
*** 1592,1597 ****
--- 1592,1598 ----
set_shift(v.red_mask, red_, red_shift_);
set_shift(v.green_mask, green_, green_shift_);
set_shift(v.blue_mask, blue_, blue_shift_);
+ bytesize_ = red_ == 0xff && green_ == 0xff && blue_ == 0xff;
break;
default:
rgbtable_ = new RGBTable(512);
***************
*** 1656,1662 ****
*/
void WindowVisual::find_color(unsigned long pixel, XColor& xc) {
! if (!ctable_->find(xc, pixel)) {
xc.pixel = pixel;
XQueryColor(info_.display_, info_.cmap_, &xc);
ctable_->insert(pixel, xc);
--- 1657,1668 ----
*/
void WindowVisual::find_color(unsigned long pixel, XColor& xc) {
! if (bytesize_) {
! xc.pixel = pixel;
! xc.red = (pixel & 0xff0000)>>8 | (pixel & 0xff0000)>>16;
! xc.green = (pixel & 0x00ff00) | (pixel & 0x00ff00)>>8;
! xc.blue = (pixel & 0x0000ff)<<8 | (pixel & 0x0000ff);
! } else if (!ctable_->find(xc, pixel)) {
xc.pixel = pixel;
XQueryColor(info_.display_, info_.cmap_, &xc);
ctable_->insert(pixel, xc);
***************
*** 1694,1708 ****
unsigned long r, g, b;
switch (info_.visual_->c_class) {
case TrueColor:
! r = rescale(red, 0xffff, red_);
! g = rescale(green, 0xffff, green_);
! b = rescale(blue, 0xffff, blue_);
! xc.pixel = (
(r << red_shift_) | (g << green_shift_) | (b << blue_shift_)
! );
! xc.red = (unsigned short)rescale(r, red_, 0xffff);
! xc.green = (unsigned short)rescale(g, green_, 0xffff);
! xc.blue = (unsigned short)rescale(b, blue_, 0xffff);
break;
default:
RGBTableEntry rgb;
--- 1700,1721 ----
unsigned long r, g, b;
switch (info_.visual_->c_class) {
case TrueColor:
! xc.red = red;
! xc.green = green;
! xc.blue = blue;
! if (bytesize_) {
! xc.pixel =
! ((red & 0xff00) << 8) |
! (green & 0xff00) |
! ((blue & 0xff00) >> 8 );
! } else {
! r = rescale(red, 0xffff, red_);
! g = rescale(green, 0xffff, green_);
! b = rescale(blue, 0xffff, blue_);
! xc.pixel = (
(r << red_shift_) | (g << green_shift_) | (b << blue_shift_)
! );
! }
break;
default:
RGBTableEntry rgb;
Index: OverlayUnidraw/ovkit.c
diff -c OverlayUnidraw/ovkit.c:1.3 OverlayUnidraw/ovkit.c:1.4
*** OverlayUnidraw/ovkit.c:1.3 Fri Apr 19 09:49:19 2002
--- src/OverlayUnidraw/ovkit.c Tue May 7 13:26:24 2002
***************
*** 516,527 ****
ToolButton* rotate;
ToolButton* reshape;
ToolButton* magnify;
- ToolButton* attribute;
_toolbars = layout.deck(1);
! PolyGlyph* vb = layout.vbox(19);
_toolbar_vbox = new Glyph*[2];
_toolbar_vbox[0] = vb;
--- 516,526 ----
ToolButton* rotate;
ToolButton* reshape;
ToolButton* magnify;
_toolbars = layout.deck(1);
! PolyGlyph* vb = layout.vbox();
_toolbar_vbox = new Glyph*[2];
_toolbar_vbox[0] = vb;
***************
*** 686,697 ****
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
layout.hcenter(gcspl)),
_tg, _ed->MouseDocObservable(), mouse_cspl));
vb->append(MakeTool(new AnnotateTool(new ControlInfo("Annotate", "A", "A")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
layout.hcenter(anno)), _tg, _ed->MouseDocObservable(), mouse_anno));
! vb->append(attribute = MakeTool(new AttributeTool(new ControlInfo("Attribute", "T", "T")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
! layout.hcenter(attr)), _tg, _ed->MouseDocObservable(), mouse_attr));
#ifdef CLIPPOLY
vb->append(MakeTool(new ClipRectTool(new ControlInfo("ClipRect", "C", "C")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
--- 685,709 ----
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
layout.hcenter(gcspl)),
_tg, _ed->MouseDocObservable(), mouse_cspl));
+
+ _toolbars->append(vb);
+ vb = layout.vbox();
+ _toolbar_vbox[1] = vb;
+ vb->append(select);
+ vb->append(move);
+ vb->append(scale);
+ vb->append(rotate);
+ vb->append(reshape);
+ vb->append(magnify);
+ vb->append(MakeTool(new AttributeTool(new ControlInfo("Attribute", "T", "T")),
+ layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
+ layout.hcenter(attr)), _tg, _ed->MouseDocObservable(), mouse_attr));
vb->append(MakeTool(new AnnotateTool(new ControlInfo("Annotate", "A", "A")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
layout.hcenter(anno)), _tg, _ed->MouseDocObservable(), mouse_anno));
! vb->append(MakeTool(new GrLocTool(new ControlInfo("GraphicLoc", "", "")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
! layout.hcenter(grloc)), _tg, _ed->MouseDocObservable(), mouse_grloc));
#ifdef CLIPPOLY
vb->append(MakeTool(new ClipRectTool(new ControlInfo("ClipRect", "C", "C")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
***************
*** 699,723 ****
vb->append(MakeTool(new ClipPolyTool(new ControlInfo("ClipPoly")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
layout.hcenter(clipp)), _tg, _ed->MouseDocObservable(), mouse_clipp));
if (!bintest("qhull"))
vb->append(MakeTool(new ConvexHullTool(new ControlInfo("ConvexHull")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
layout.hcenter(hull)), _tg, _ed->MouseDocObservable(), mouse_convexhull));
- #endif
- vb->append(MakeTool(new GrLocTool(new ControlInfo("GraphicLoc", "", "")),
- layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
- layout.hcenter(grloc)), _tg, _ed->MouseDocObservable(), mouse_grloc));
-
- _toolbars->append(vb);
- vb = layout.vbox();
- _toolbar_vbox[1] = vb;
- vb->append(select);
- vb->append(move);
- vb->append(scale);
- vb->append(rotate);
- vb->append(reshape);
- vb->append(magnify);
- vb->append(attribute);
_toolbars->append(vb);
_toolbars->flip_to(0);
_toolbar = new Patch(_toolbars);
--- 711,721 ----
vb->append(MakeTool(new ClipPolyTool(new ControlInfo("ClipPoly")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
layout.hcenter(clipp)), _tg, _ed->MouseDocObservable(), mouse_clipp));
+ #endif
if (!bintest("qhull"))
vb->append(MakeTool(new ConvexHullTool(new ControlInfo("ConvexHull")),
layout.overlay(layout.hcenter(layout.hspace(_maxwidth)),
layout.hcenter(hull)), _tg, _ed->MouseDocObservable(), mouse_convexhull));
_toolbars->append(vb);
_toolbars->flip_to(0);
_toolbar = new Patch(_toolbars);
***************
*** 1471,1477 ****
MenuItem *mbi = kit.menubar_item(kit.label("Tools"));
mbi->menu(kit.pulldown());
! MenuItem* menu_item = kit.menu_item(kit.label("Custom Tools"));
menu_item->action(new ActionCallback(OverlayKit)(this, &OverlayKit::toolbar1));
mbi->menu()->append_item(menu_item);
--- 1469,1475 ----
MenuItem *mbi = kit.menubar_item(kit.label("Tools"));
mbi->menu(kit.pulldown());
! MenuItem* menu_item = kit.menu_item(kit.label("Extra Tools"));
menu_item->action(new ActionCallback(OverlayKit)(this, &OverlayKit::toolbar1));
mbi->menu()->append_item(menu_item);
Index: OverlayUnidraw/ovpainter.c
diff -c OverlayUnidraw/ovpainter.c:1.5 OverlayUnidraw/ovpainter.c:1.6
*** OverlayUnidraw/ovpainter.c:1.5 Wed Feb 13 09:32:52 2002
--- src/OverlayUnidraw/ovpainter.c Tue May 7 13:26:24 2002
***************
*** 1185,1194 ****
boolean transparent_val = 0;
! if (r_r->alphaval()<1.0 || transparent_val) {
/* WITH alpha-tranparency */
/* adjust pwidth and pheight, because they might be in error */
XWindow win_ret;
int x_ret, y_ret;
--- 1185,1197 ----
boolean transparent_val = 0;
! if (r_r->alphaval()<1.0 /* || transparent_val */ ) {
/* WITH alpha-tranparency */
+ unsigned long alpha = (unsigned long)(r_r->alphaval() * 65535);
+ unsigned long beta = 65535 - alpha;
+
/* adjust pwidth and pheight, because they might be in error */
XWindow win_ret;
int x_ret, y_ret;
***************
*** 1218,1239 ****
XColor xc1, xc2;
d.rep()->default_visual_->find_color(val1, xc1);
d.rep()->default_visual_->find_color(val2, xc2);
! float alpha = r_r->alphaval();
! float beta = 1.0 - alpha;
if (!(transparent_val &&
xc1.red==0xffff &&
xc1.green==0xffff &&
xc1.blue==0xffff)) {
! unsigned short newred = (short unsigned)(xc1.red*alpha+xc2.red*beta);
! unsigned short newgreen = (short unsigned)(xc1.green*alpha+xc2.green*beta);
! unsigned short newblue = (short unsigned)(xc1.blue*alpha+xc2.blue*beta);
XColor newcolor;
d.rep()->default_visual_->find_color((short unsigned int)newred, (short unsigned int)newgreen, (short unsigned int)newblue, newcolor);
XPutPixel(im1, i, j, newcolor.pixel);
} else {
XPutPixel(im1, i, j, xc2.pixel);
}
}
}
--- 1221,1247 ----
XColor xc1, xc2;
d.rep()->default_visual_->find_color(val1, xc1);
d.rep()->default_visual_->find_color(val2, xc2);
! #if 0
if (!(transparent_val &&
xc1.red==0xffff &&
xc1.green==0xffff &&
xc1.blue==0xffff)) {
! #endif
! unsigned short newred =
! (unsigned short)((xc1.red*alpha+xc2.red*beta)>>16);
! unsigned short newgreen =
! (unsigned short)((xc1.green*alpha+xc2.green*beta)>>16);
! unsigned short newblue =
! (unsigned short)((xc1.blue*alpha+xc2.blue*beta)>>16);
XColor newcolor;
d.rep()->default_visual_->find_color((short unsigned int)newred, (short unsigned int)newgreen, (short unsigned int)newblue, newcolor);
XPutPixel(im1, i, j, newcolor.pixel);
+ #if 0
} else {
XPutPixel(im1, i, j, xc2.pixel);
}
+ #endif
}
}
Index: ComUnidraw/unifunc.c
diff -c ComUnidraw/unifunc.c:1.2 ComUnidraw/unifunc.c:1.3
*** ComUnidraw/unifunc.c:1.2 Wed Dec 19 15:14:26 2001
--- src/ComUnidraw/unifunc.c Tue May 7 13:26:26 2002
***************
*** 277,291 ****
}
void ImportFunc::execute() {
ComValue pathnamev(stack_arg(0));
static int popen_symid = symbol_add("popen");
boolean popen_flag = stack_key(popen_symid).is_true();
reset_stack();
OvImportCmd* cmd;
if (!pathnamev.is_array()) {
! if (nargs()==1) {
! if ((cmd = import(pathnamev.string_ptr(), popen_flag)) && cmd->component()) {
ComValue compval(((OverlayComp*)cmd->component())->classid(),
new ComponentView(cmd->component()));
delete cmd;
--- 277,318 ----
}
void ImportFunc::execute() {
+ static char* lastpath = nil;
+
ComValue pathnamev(stack_arg(0));
static int popen_symid = symbol_add("popen");
boolean popen_flag = stack_key(popen_symid).is_true();
+ static int next_symid = symbol_add("next");
+ boolean next_flag = stack_key(next_symid).is_true();
reset_stack();
+
+ if (next_flag) {
+ if (lastpath) {
+ char* ptr = lastpath + strlen(lastpath) - 1;
+ while ((*ptr < '0' || *ptr > '9') && ptr > lastpath ) ptr--;
+ if (*ptr >= '0' && *ptr <= '9') {
+ do {
+ if (*ptr >= '0' && *ptr <= '8') *ptr = ++*ptr;
+ else *ptr = '0';
+ } while (*ptr == '0' && --ptr > lastpath);
+ }
+ } else {
+ lastpath = strnew(pathnamev.string_ptr());
+ }
+ } else {
+ delete lastpath;
+ lastpath = nil;
+ }
+
+ if (!next_flag && pathnamev.is_string())
+ lastpath = strnew(pathnamev.string_ptr());
+
OvImportCmd* cmd;
if (!pathnamev.is_array()) {
! if (nargs()==1 || next_flag) {
! if ((cmd = import(next_flag ? lastpath : pathnamev.string_ptr(),
! popen_flag)) && cmd->component()) {
ComValue compval(((OverlayComp*)cmd->component())->classid(),
new ComponentView(cmd->component()));
delete cmd;
Index: ComUnidraw/unifunc.h
diff -c ComUnidraw/unifunc.h:1.2 ComUnidraw/unifunc.h:1.3
*** ComUnidraw/unifunc.h:1.2 Wed Dec 19 15:14:26 2001
--- src/ComUnidraw/unifunc.h Tue May 7 13:26:26 2002
***************
*** 123,129 ****
};
//: command to import a graphic file
! // compview=import(pathname :popen) -- import graphic file from pathname or URL, or from a command if :popen.
class ImportFunc : public UnidrawFunc {
public:
ImportFunc(ComTerp*,Editor*);
--- 123,130 ----
};
//: command to import a graphic file
! // compview=import(pathname :popen :next) -- import graphic file from pathname or URL, or from a command if :popen
! // (:next imports next in numeric series).
class ImportFunc : public UnidrawFunc {
public:
ImportFunc(ComTerp*,Editor*);
***************
*** 131,137 ****
// helper method to import from path
virtual void execute();
virtual const char* docstring() {
! return "compview=%s(pathname :popen) -- import graphic file from pathname or URL, or from a command if :popen"; }
};
--- 132,138 ----
// helper method to import from path
virtual void execute();
virtual const char* docstring() {
! return "compview=%s(pathname :popen :next) -- import graphic file from pathname or URL, or from a command if :popen\n(:next imports next in numeric series)"; }
};
Index: comdraw/README
diff -c comdraw/README:1.7 comdraw/README:1.8
*** comdraw/README:1.7 Thu Jan 31 10:20:48 2002
--- src/comdraw/README Tue May 7 13:26:27 2002
***************
*** 84,90 ****
update() -- update viewer
error=save([pathstr]) -- command to save document (to pathname)
! compview=import(pathstr :popen) -- import graphic file from pathname or URL, or from a command if :popen
export(compview[,compview[,...compview]] [path] :host host_str :port port_int :socket :string|:str :eps :idraw) -- remote in drawtool (or other) format
compview=paste(compview [xscale yscale xoff yoff | a00,a01,a10,a11,a20,a21]) -- paste graphic into the viewer
val=pastemode([val] :get) -- toggle or set paste mode, default is 0, always paste new graphics
--- 84,91 ----
update() -- update viewer
error=save([pathstr]) -- command to save document (to pathname)
! compview=import(pathstr :popen :next) -- import graphic file from pathname or URL, or from a command if :popen
! (:next imports next in numeric series)
export(compview[,compview[,...compview]] [path] :host host_str :port port_int :socket :string|:str :eps :idraw) -- remote in drawtool (or other) format
compview=paste(compview [xscale yscale xoff yoff | a00,a01,a10,a11,a20,a21]) -- paste graphic into the viewer
val=pastemode([val] :get) -- toggle or set paste mode, default is 0, always paste new graphics
Index: include_x11/xwindow.h
diff -c include_x11/xwindow.h:1.1 include_x11/xwindow.h:1.2
*** include_x11/xwindow.h:1.1 Fri Nov 2 13:07:29 2001
--- src/include/IV-X11/xwindow.h Tue May 7 13:26:30 2002
***************
*** 101,106 ****
--- 101,107 ----
unsigned long blue_shift_;
unsigned long white_;
unsigned long xor_;
+ boolean bytesize_;
static void find_visual_by_class_name(const String&, WindowVisualInfo&);
static boolean find_layer(const String&, int& layer);
Index: man1_ivtools/comdraw.1
diff -c man1_ivtools/comdraw.1:1.7 man1_ivtools/comdraw.1:1.8
*** man1_ivtools/comdraw.1:1.7 Thu Jan 31 10:20:57 2002
--- src/man/man1/comdraw.1 Tue May 7 13:26:33 2002
***************
*** 93,99 ****
update() -- update viewer
error=save([pathstr]) -- command to save document (to pathname)
! compview=import(pathstr :popen) -- import graphic file from pathname or URL, or from a command if :popen
export(compview[,compview[,...compview]] [path] :host host_str :port port_int :socket :string|:str :eps :idraw) -- remote in drawtool (or other) format
compview=paste(compview [xscale yscale xoff yoff | a00,a01,a10,a11,a20,a21]) -- paste graphic into the viewer
val=pastemode([val] :get) -- toggle or set paste mode, default is 0, always paste new graphics
--- 93,100 ----
update() -- update viewer
error=save([pathstr]) -- command to save document (to pathname)
! compview=import(pathstr :popen :next) -- import graphic file from pathname or URL, or from a command if :popen
! (:next imports next in numeric series)
export(compview[,compview[,...compview]] [path] :host host_str :port port_int :socket :string|:str :eps :idraw) -- remote in drawtool (or other) format
compview=paste(compview [xscale yscale xoff yoff | a00,a01,a10,a11,a20,a21]) -- paste graphic into the viewer
val=pastemode([val] :get) -- toggle or set paste mode, default is 0, always paste new graphics
Index: man1_ivtools/comterp.1
diff -c man1_ivtools/comterp.1:1.4 man1_ivtools/comterp.1:1.5
*** man1_ivtools/comterp.1:1.4 Thu Mar 21 16:15:20 2002
--- src/man/man1/comterp.1 Tue May 7 13:26:33 2002
***************
*** 177,182 ****
--- 177,184 ----
matrix=xpose(matrix) -- transpose an arbitrary matrix
+ matrix=matrix*matrix -- matrix multiplication
+
.SH STATISTICAL/RANDOM COMMANDS:
sum(val1[,val2[,...,valn]]) -- return sum of values
*** /dev/null Tue May 7 13:26:35 PDT 2002
--- patches/ivtools-020507-johnston-048
*************** patches/ivtools-020507-johnston-048
*** 0 ****
--- 1 ----
+ ivtools-020507-johnston-048
|