bianbian coding life

便便代码人生: 关注技术, 翻译文档, 偶尔动动手

bianbian.org

[原] IE模拟鼠标右键双击事件

Posted by bianbian on 2008-03-25 01:10


本文Tags: , , ,

IE实在太垃圾了,再鄙视一次。。。鼠标右键双击居然没有。。。。
只好用onmouseup事件模拟一个(基于Prototype 1.6):

  1. if (Prototype.Browser.IE) {
  2.     mouseCount = 0;
  3.     Event.observe(document, 'mouseup', function(event) {
  4.         if (Event.isRightClick(event)) {
  5.             if (++mouseCount > 1) {
  6.                 mouseCount = 0;
  7.                 var pxy = Event.pointer(event);
  8.                 alert("right mouse double click on: " + pxy.x + ", " + pxy.y);
  9.             } else {
  10.                 setTimeout("mouseCount = 0", 1000);
  11.             }
  12.         }
  13.     });
  14. }
标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in JavaScript, Technology | 1 Comment »

[原] 自定义IDL调色板指南

Posted by bianbian on 2008-03-21 12:06


本文Tags: , ,

IDL的调色板功能很好很强大,以至于我还没琢磨透到底怎么调。。。。

不过一般都是用自己定义的调色板,就讲讲怎么往IDL里加入自己的调色板:
(加了以后在系统内LOADCT的时候,就能直接读取自定义的调色板,非常方便)

IDL提供了 MODIFYCT 命令用来更改或加入系统的预定义调色板:

MODIFYCT, Itab, Name, R, G, B [, FILE=filename]

Itab是索引值,0-40是系统的,一般都要41开始
Name是命名,32个字符内
R、G、B就是256长度的BYTE(单字节正数)数组
File是文件名,如果不制定就操作默认的(resouce目录的color1.tbl)

实际发现File指定了其他文件名,MODIFYCT会出错。看了源码,发现
MODIFYCT并没有处理文件读取错误(不存在)的异常。(不知道是不是IDL7.0的问题)

IDL也没有公开colortable的文件格式。不过我把MODIFYCT的源码结合color1.tbl
分析了一下,得到IDL的colortable文件格式:

总数 + R 256 + G 256 + B 256 + …. + 32长度名称(在文件末尾)

例(如果有两个表):[2][R..R][G..G][B..B][R..R][G..G][B..B][名称1][名称2]

这样就可以自己输出调色板文件了,不需要用IDL的默认文件(防止多用户冲突)。
之后可以用 LOADCT, 0, FILE=’mytable.tbl’ 动态载入

附C语言输出调色板文件代码:

  1. FILE *fp = fopen(file, "wb");
  2. BYTE n = 1;
  3. fwrite(&n, 1, 1, fp);
  4. fwrite(m_byteRGB, 1, 256 * 3, fp);
  5. fprintf(fp, "%-32s", "bianbian Default Table");
  6. fclose(fp);
标签: , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, ENVI & IDL, Technology | 2 Comments »

[原] IDL的数组存储是行顺序,下标引用是列在前

Posted by bianbian on 2008-03-17 13:29


本文Tags: , , ,

IDL的数组在内存中存储还是以行顺序的,只是多维下标引用的时候列为先。即:
A=
[r r r]
[g g g]
[b b b]
在内存中是 rrrgggbbb(和C是一样的!fortran是rgbrgbrgb)

而引用的时候列在前:(C是行在前!)
A[0,0] A[1,0] A[2,0]
A[0,1] A[1,1] A[2,1]
A[0,2] A[1,2] A[2,2]

三维的情况和C也一样(注意,IDL和C唯一的差别就是IDL的下标列在前,然后是行);存储结构一致也就意味着C里的多维数组内存块可以直接丢到IDL里处理。其实我觉得IDL在下标上太小白了,干嘛不和C保持一致?某IDL大牛说:之所以下标在前,是为了更直观的知道X方向上有几个、Y方向上有几个。比如:A[3, 2],X方向有3个,Y方向有2个(2行3列):Is IDL column-major or row-major?

某本书(似乎国内的书都不认真写 - -)说IDL是列顺序的,这是不对的。可以拿三维数据做简单试验(也便于对下标引用理解):

IDL> a=bindgen(3,3,3)
IDL> print,a
   0   1   2
   3   4   5
   6   7   8

   9  10  11
  12  13  14
  15  16  17

  18  19  20
  21  22  23
  24  25  26
IDL> print,a[1,0,*]
   1

  10

  19
IDL> print,a[*,1,1]
  12  13  14
标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, ENVI & IDL, Technology | 1 Comment »

[转] 再火星一把,这个好强。。。

Posted by bianbian on 2008-03-16 18:58


本文Tags:

Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn’t
mttaer in waht oredr the ltteers in a wrod are, the olny iprmoatnt tihng
is taht the frist and lsat ltteer be at the rghit pclae.The rset can be a
total mses and you can sitll raed it wouthit porbelm.

Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the
wrod as a wlohe.

No tag for this post.

相关日志

Posted in Not IT | 1 Comment »

[原] 减小nginx编译后的文件大小 (Reduce file size of nginx)

Posted by bianbian on 2008-03-13 10:21


本文Tags: , , ,

默认的nginx编译选项里居然是用debug模式(-g)的(debug模式会插入很多跟踪和ASSERT之类),编译以后一个nginx有好几兆。
去掉nginx的debug模式编译,编译以后只有375K(nginx-0.5.33, gcc4)。
在 auto/cc/gcc,最后几行有:
# debug
CFLAGS=”$CFLAGS -g”
注释掉或删掉这几行,重新编译即可。-g参数用法详见这篇blog:[原]Linux下的c/c++ GDB调试

Nginx uses debug mode (-g) in compiling by default, which result in several MB of it’s size.
After debug disabled, the file size of nginx reduced to 375K (nginx-0.5.33, gcc4).
open auto/cc/gcc, find this at last several lines:
# debug
CFLAGS=”$CFLAGS -g”
delete it, and recompile. More of -g: Linux c/c++ GDB debug

标签: , , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Posted in C/C++, Linux, Technology | No Comments »