1.畫面顯示只有256色
Disable fast jpeg
include/device.h
#define FASTJPEG 0 /* =1 fot temp quick jpeg 8bpp*/
2.載入大檔案時 nano-X 結束.
# /tmp/nxview /phone/media/picture/DSC_0251.JPG
Improper call to JPEG library in state 202
nxclient: lost connection to Nano-X server
Trace之後發現是memory不夠了,malloc失敗.
之後nano-X操作jpeglib的程序有問題
engine/image_jpeg.c
int
GdDecodeJPEG(buffer_t * src, PMWIMAGEHDR pimage, PSD psd, MWBOOL fast_grayscale)
{
.....
.....
.....
/* Step 5: Start decompressor */
jpeg_start_decompress (&cinfo);
/* Step 6: while (scan lines remain to be read) */
while(cinfo.output_scanline < cinfo.output_height) {
JSAMPROW rowptr[1];
rowptr[0] = (JSAMPROW)(pimage->imagebits +
cinfo.output_scanline * pimage->pitch);
jpeg_read_scanlines (&cinfo, rowptr, 1);
}
ret = 1;
#if 1 /*Modify by Steve*/ <<--改到這裡就OK啦
/* Step 7: Finish decompression */
jpeg_finish_decompress (&cinfo);
#endif
err:
#if 0 /*Modify by Steve*/ <<--就是這裡囉
/* Step 7: Finish decompression */
jpeg_finish_decompress (&cinfo);
#endif
/* Step 8: Release JPEG decompression object */
jpeg_destroy_decompress (&cinfo);
/* May want to check to see whether any corrupt-data
* warnings occurred (test whether jerr.pub.num_warnings is nonzero).
*/
return ret;
}
#endif /* MW_FEATURE_IMAGES && defined(HAVE_JPEG_SUPPORT)*/
3.圖檔太大會因為memory不夠而無法顯示
解決方式是在jepglib decompress 時作 scaling
engine/image_jpeg.c
int
GdDecodeJPEG(buffer_t * src, PMWIMAGEHDR pimage, PSD psd, MWBOOL fast_grayscale)
{
.....
.....
.....
jpeg_calc_output_dimensions(&cinfo);
#if 1
int wfac, hfac, fac;
wfac = cinfo.output_width / psd->xres;
hfac = cinfo.output_height / psd->yres;
fac = wfac;
if(fac > hfac)
fac = hfac;
if(fac > 8) fac = 8; /* 1/8 */
else if(fac > 4) fac = 4; /* 1/4 */
else if(fac > 2) fac = 2; /* 1/2 */
else fac = 1; /*No scaling*/
cinfo.scale_num = 1;
cinfo.scale_denom = fac;
cinfo.dct_method = JDCT_FASTEST;
cinfo.do_fancy_upsampling = FALSE;
jpeg_calc_output_dimensions(&cinfo);
#endif
.....
.....
.....
}
#endif /* MW_FEATURE_IMAGES && defined(HAVE_JPEG_SUPPORT)*/
2008年12月24日 星期三
2008年12月23日 星期二
Redirect printf to file
#include <stdio.h>
#include <stdlib.h>
FILE *fp;
fp = freopen("/tmp/dock.log", "w", stdout);
printf("printf to /tmp/dock.log ...\n");
fclose(fp);
#include <stdlib.h>
FILE *fp;
fp = freopen("/tmp/dock.log", "w", stdout);
printf("printf to /tmp/dock.log ...\n");
fclose(fp);
2008年12月10日 星期三
nano-X Window Manager
nano-X並沒有自動處理視窗在screen繪圖的動作,例如A視窗有部份區域與B視窗重疊,當A視窗結束消失,B視窗被A視窗覆蓋的部份會是一片空白.
在nano-X上實作一個Window Manager才能解決上述的問題.
nano-X中的nanowm可作為參考.
nano-X 提供了Graphic UI所需要的基礎功能,大致上可分為
1.操作繪圖區域
GrNewWindow
GrNewPixmap
GrMapWindow
GrUnmapWindow
GrReparentWindow
GrCopyArea
GrClearArea
2.繪圖物件 Graphic Context
GrNewGC
GrCopyGC
GrForeground
GrBackground
GrSetGCFont
3.繪圖工具
GrLine
GrRect
GrPoly
GrFillRect
GrFillPoly
4.繪圖區域狀態管理,回報視窗顯示,子視窗狀態更新等
GrCheckNextEvent
實做Window Manager之前必須了解的事情
0.視窗具有父子階層的關係,子視窗的x,y軸位置是相對於父視窗.父視窗的大小範圍就是子視窗的可視繪圖範圍
1.GR_ROOT_WINDOW_ID代表系統中最底層的視窗即root window,可當作桌面來看待.
2.視窗分為兩種Container Window與Client Window,
Container Window其父視窗為root window.
Client window其父視窗為Container Window.
3.Window Manager需要處理視窗Event.
此功能為實做Window Manager最重要的部份.關係到視窗的正確顯示.
GR_EVENT_TYPE_EXPOSURE :
視窗需要重繪.
GR_EVENT_TYPE_CHLD_UPDATE :
子視窗狀態改變了.
若子視窗隱藏(unmap),父視窗為Container Window則重繪父視窗.
在nano-X上實作一個Window Manager才能解決上述的問題.
nano-X中的nanowm可作為參考.
nano-X 提供了Graphic UI所需要的基礎功能,大致上可分為
1.操作繪圖區域
GrNewWindow
GrNewPixmap
GrMapWindow
GrUnmapWindow
GrReparentWindow
GrCopyArea
GrClearArea
2.繪圖物件 Graphic Context
GrNewGC
GrCopyGC
GrForeground
GrBackground
GrSetGCFont
3.繪圖工具
GrLine
GrRect
GrPoly
GrFillRect
GrFillPoly
4.繪圖區域狀態管理,回報視窗顯示,子視窗狀態更新等
GrCheckNextEvent
實做Window Manager之前必須了解的事情
0.視窗具有父子階層的關係,子視窗的x,y軸位置是相對於父視窗.父視窗的大小範圍就是子視窗的可視繪圖範圍
1.GR_ROOT_WINDOW_ID代表系統中最底層的視窗即root window,可當作桌面來看待.
2.視窗分為兩種Container Window與Client Window,
Container Window其父視窗為root window.
Client window其父視窗為Container Window.
3.Window Manager需要處理視窗Event.
此功能為實做Window Manager最重要的部份.關係到視窗的正確顯示.
GR_EVENT_TYPE_EXPOSURE :
視窗需要重繪.
GR_EVENT_TYPE_CHLD_UPDATE :
子視窗狀態改變了.
若子視窗隱藏(unmap),父視窗為Container Window則重繪父視窗.
2008年12月5日 星期五
軟體開發文章
閱讀他人的程式碼(1)─讀懂程式碼,使心法皆為我所用
http://www.ithome.com.tw/itadm/article.php?c=47717
不會寫程式但是在做系統分析 有沒有不會寫程式卻在做系統分析的? [精華]
http://funp.com/push/index.php?tag=%E7%A8%8B%E5%BC%8F&hot=&stars=1&page=11#p=81693
強化程式可讀性,以提升開發的效率
http://www.ithome.com.tw/itadm/article.php?c=52029
管理者要懂得如何用嘴巴寫程式
http://www.ithome.com.tw/itadm/article.php?c=51771
註解不是換句話說,是補程式的不足
http://www.ithome.com.tw/itadm/article.php?c=51597
打造穩固程式碼,先從思路方向著手
http://www.ithome.com.tw/itadm/article.php?c=51397
當程式人「晉升」至管理階級
http://www.ithome.com.tw/itadm/article.php?c=51133
程式設計的2大面向:演算和架構
http://www.ithome.com.tw/itadm/article.php?c=49841
GUI的開發瓶頸
http://www.ithome.com.tw/itadm/article.php?c=49436
漫談程式碼的相依性 (1)時時關注類別的相依程度、持續改善
http://www.ithome.com.tw/itadm/article.php?c=49179
程式碼的演化之路(1)持續讓程式碼保持進步的能力
http://www.ithome.com.tw/itadm/article.php?c=48746
程式設計2.0 (1)善用優質網站資源,快速上手新技術
http://www.ithome.com.tw/itadm/article.php?c=47405
物件導向程式設計常見的錯誤(1)抽離作用重複的程式碼,重構品質
http://www.ithome.com.tw/itadm/article.php?c=45745
物件導向與封裝
http://www.ithome.com.tw/itadm/article.php?c=45903
http://www.ithome.com.tw/itadm/article.php?c=47717
不會寫程式但是在做系統分析 有沒有不會寫程式卻在做系統分析的? [精華]
http://funp.com/push/index.php?tag=%E7%A8%8B%E5%BC%8F&hot=&stars=1&page=11#p=81693
強化程式可讀性,以提升開發的效率
http://www.ithome.com.tw/itadm/article.php?c=52029
管理者要懂得如何用嘴巴寫程式
http://www.ithome.com.tw/itadm/article.php?c=51771
註解不是換句話說,是補程式的不足
http://www.ithome.com.tw/itadm/article.php?c=51597
打造穩固程式碼,先從思路方向著手
http://www.ithome.com.tw/itadm/article.php?c=51397
當程式人「晉升」至管理階級
http://www.ithome.com.tw/itadm/article.php?c=51133
程式設計的2大面向:演算和架構
http://www.ithome.com.tw/itadm/article.php?c=49841
GUI的開發瓶頸
http://www.ithome.com.tw/itadm/article.php?c=49436
漫談程式碼的相依性 (1)時時關注類別的相依程度、持續改善
http://www.ithome.com.tw/itadm/article.php?c=49179
程式碼的演化之路(1)持續讓程式碼保持進步的能力
http://www.ithome.com.tw/itadm/article.php?c=48746
程式設計2.0 (1)善用優質網站資源,快速上手新技術
http://www.ithome.com.tw/itadm/article.php?c=47405
物件導向程式設計常見的錯誤(1)抽離作用重複的程式碼,重構品質
http://www.ithome.com.tw/itadm/article.php?c=45745
物件導向與封裝
http://www.ithome.com.tw/itadm/article.php?c=45903
2008年11月18日 星期二
Microwindows with alpha blending support
Reference
http://hi.baidu.com/chenzhuoyou/blog/item/5ad45a3d9c057ceb3d6d97a2.html
http://hi.baidu.com/chenzhuoyou/blog/item/ee1f57607c7d5fdb8cb10d63.html
1.範例程式參考
src/demos/nanox/nxalpha.c
2.Patch microwindow-0.91
diff -Nur microwindows-0.91.org/src/demos/nanox/Makefile microwindows-0.91/src/demos/nanox/Makefile
--- microwindows-0.91.org/src/demos/nanox/Makefile 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/demos/nanox/Makefile 2008-11-18 22:13:45.000000000 +0800
@@ -57,6 +57,7 @@
$(MW_DIR_BIN)/ntetris \
$(MW_DIR_BIN)/getselection \
$(MW_DIR_BIN)/setselection \
+ $(MW_DIR_BIN)/nxalpha \
$(MW_DIR_BIN)/dashdemo \
$(MW_DIR_BIN)/pcfdemo \
$(MW_DIR_BIN)/fontdemo \
diff -Nur microwindows-0.91.org/src/demos/nanox/nxalpha.c microwindows-0.91/src/demos/nanox/nxalpha.c
--- microwindows-0.91.org/src/demos/nanox/nxalpha.c 1970-01-01 08:00:00.000000000 +0800
+++ microwindows-0.91/src/demos/nanox/nxalpha.c 2008-11-19 13:20:49.000000000 +0800
@@ -0,0 +1,192 @@
+/* Alpha blending demo
+ By Jordan Crouse
+
+ This takes our favorite penguin and alpha blends him
+ against the background. Hit the + and - keys to adjust the
+ alpha.
+*/
+
+#include
+#include
+#include
+
+#define BGCOLOR GR_RGB(24, 125, 148)
+//#define BGCOLOR GR_RGB(0, 0, 0)
+
+int sw, sh;
+int iw = 91, ih = 100;
+
+int g_alpha = 128;
+GR_WINDOW_ID g_wid, g_pixmap, g_image;
+
+void do_alpha_blit(int x, int y, int w, int h, unsigned long mode) {
+
+ GR_GC_ID gc = GrNewGC();
+ GrSetGCForeground(gc, BGCOLOR);
+
+ /* Clear the holding buffer */
+ GrFillRect(g_pixmap, gc, 0, 0, w, h);
+#if 0
+ /* Alpha blend the image in */
+ GrCopyArea(g_pixmap, gc, 0, 0, w, h, g_image, 0, 0, MWROP_SRCCOPY);
+
+ GrFillRect(g_pixmap, gc, 10, 10, 50, 50);
+
+ GrCopyArea(g_pixmap, gc, 10, 10, 50, 50, g_image, 10, 10, mode);
+#endif
+#if 1
+ /* Alpha blend the image in */
+ GrCopyArea(g_pixmap, gc, 0, 0, w, h, g_image, 0, 0, mode);
+#endif
+ /* Copy the holding buffer to the screen */
+ GrCopyArea(g_wid, gc, x, y, w, h, g_pixmap, 0, 0, MWROP_SRCCOPY);
+ GrDestroyGC(gc);
+}
+
+void draw_window(int alpha) {
+
+ int xpos;
+
+ GR_GC_ID gc = GrNewGC();
+ GrSetGCForeground(gc, GR_RGB(255,255,255));
+ GrSetGCBackground(gc, BGCOLOR);
+ xpos = (sw - ((5 * iw) + 30)) / 2;
+
+ GrText(g_wid, gc, 5, 5, "Press + / - to change the alpha value", -1,
+ GR_TFTOP);
+
+ GrText(g_wid, gc, xpos, ((sh - ih) / 2) - 20, "Original", -1, 0);
+ GrCopyArea(g_wid, gc, xpos, (sh - ih) / 2, iw, ih, g_image,
+ 0, 0, MWROP_SRCCOPY);
+
+ xpos += iw + 10;
+
+ GrText(g_wid, gc, xpos, ((sh - ih) / 2) - 20, "Blend", -1, 0);
+ do_alpha_blit(xpos, (sh - ih) / 2, iw, ih, MWROP_BLEND | (alpha & 0xFF));
+
+ xpos += iw + 10;
+
+ GrText(g_wid, gc, xpos, (sh - ih) / 2 - 20, "Add", -1, 0);
+ do_alpha_blit(xpos, (sh - ih) / 2, iw, ih, MWROP_BLENDADD | (alpha & 0xFF));
+
+ xpos += iw + 10;
+
+ GrText(g_wid, gc, xpos, (sh - ih) / 2 - 20, "Subtract", -1, 0);
+ do_alpha_blit(xpos, (sh - ih) / 2, iw, ih, MWROP_BLENDSUBTRACT | (alpha & 0xFF));
+
+ xpos += iw + 10;
+
+ GrText(g_wid, gc, xpos, (sh - ih) / 2 - 20, "Reshade", -1, 0);
+ do_alpha_blit(xpos, (sh - ih) / 2, iw, ih, MWROP_BLENDRESHADE | (alpha & 0xFF));
+
+ GrDestroyGC(gc);
+}
+
+void handle_events(GR_EVENT *event) {
+
+ switch(event->type) {
+ case GR_EVENT_TYPE_EXPOSURE:
+ draw_window(g_alpha);
+ break;
+
+ case GR_EVENT_TYPE_KEY_DOWN:
+ switch(event->keystroke.ch & 0x1) {
+ //case '=':
+ case 0:
+ g_alpha += 5;
+ if (g_alpha > 255) g_alpha = 255;
+ break;
+
+ //case '-':
+ case 1:
+ g_alpha -= 5;
+ if (g_alpha < 0) g_alpha = 0;
+ break;
+ }
+
+ printf("Alpha: %3.3d\r", g_alpha);
+ fflush(stdout);
+
+ draw_window(g_alpha);
+ break;
+
+ case GR_EVENT_TYPE_CLOSE_REQ:
+ exit(0);
+ }
+}
+
+int load_image(char *filename) {
+
+ GR_IMAGE_INFO iinfo;
+
+ GR_GC_ID gc = GrNewGC();
+ GR_IMAGE_ID image = GrLoadImageFromFile(filename, 0);
+
+ if (!image) return(-1);
+
+ GrGetImageInfo(image, &iinfo);
+
+ iw = iinfo.width;
+ ih = iinfo.height;
+
+ /* Make the pixmaps that will buffer the draw */
+ g_pixmap = GrNewPixmap(iw, ih, 0);
+ g_image = GrNewPixmap(iw, ih, 0);
+
+ GrSetGCForeground(gc, BGCOLOR);
+ GrFillRect(g_image, gc, 0, 0, iw, ih);
+
+ GrDrawImageToFit(g_image, gc, 0, 0, -1, -1, image);
+
+ GrDestroyGC(gc);
+ GrFreeImage(image);
+ return(0);
+}
+
+int main(int argc, char **argv) {
+
+ GR_SCREEN_INFO sinfo;
+
+ g_alpha = 128;
+
+ if (GrOpen() == -1) return(-1);
+
+ if (argc < 2) {
+ if(load_image("tux.gif") == -1) {
+ printf("Unable to open the image [tux.gif]\n");
+ GrClose();
+ return(-1);
+ }
+ }
+ else {
+ if (load_image(argv[1]) == -1) {
+ printf("Unable to open the image [%s]\n", argv[1]);
+ GrClose();
+ return(-1);
+ }
+ }
+
+ GrGetScreenInfo(&sinfo);
+
+ sw = sinfo.cols - 20;
+ sh = sinfo.rows - 20;
+
+ g_wid = GrNewWindow(GR_ROOT_WINDOW_ID,
+ 10, 10, sw, sh, 0, BGCOLOR, 0);
+
+ GrSelectEvents(g_wid,
+ GR_EVENT_MASK_KEY_DOWN |
+ GR_EVENT_MASK_EXPOSURE |
+ GR_EVENT_MASK_CLOSE_REQ);
+
+ GrMapWindow(g_wid);
+
+ fflush(stdout);
+
+ while(1) {
+ GR_EVENT event;
+ GrGetNextEvent(&event);
+
+ handle_events(&event);
+ }
+}
diff -Nur microwindows-0.91.org/src/drivers/fblin16.c microwindows-0.91/src/drivers/fblin16.c
--- microwindows-0.91.org/src/drivers/fblin16.c 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/drivers/fblin16.c 2008-11-18 22:09:45.000000000 +0800
@@ -166,49 +166,90 @@
src += srcx + srcy * slinelen;
#if ALPHABLEND
- if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
- goto stdblit;
+
+#define R_VAL(p) ((unsigned char *)(p))[2]
+#define G_VAL(p) ((unsigned char *)(p))[1]
+#define B_VAL(p) ((unsigned char *)(p))[0]
+
+#include
+
+ if((op & MWROP_EXTENSION) < MWROP_BLEND) goto stdblit;
alpha = op & 0xff;
- if (dstpsd->pixtype == MWPF_TRUECOLOR565) {
- while(--h >= 0) {
- for(i=0; i
- unsigned int s = *src++;
- unsigned int d = *dst;
- unsigned int t = d & 0xf800;
- unsigned int m1, m2, m3;
- m1 = (((((s & 0xf800) - t)*alpha)>>8) & 0xf800) + t;
- t = d & 0x07e0;
- m2 = (((((s & 0x07e0) - t)*alpha)>>8) & 0x07e0) + t;
- t = d & 0x001f;
- m3 = (((((s & 0x001f) - t)*alpha)>>8) & 0x001f) + t;
- *dst++ = m1 | m2 | m3;
- }
- dst += dlinelen - w;
- src += slinelen - w;
- }
+ if (dstpsd->pixtype == MWPF_TRUECOLOR565) { /* 565 format */
+ while(--h >= 0) {
+ for(i=0; i
+ unsigned long tmp;
+
+ unsigned long in = (*src & 0xf800) << 8 | (*src & 0x07e0) << 5 | (*src & 0x001f) << 3;
+ unsigned long out = (*dst & 0xf800) << 8 | (*dst & 0x07e0) << 5 | (*dst & 0x001f) << 3;
+
+ unsigned long *ptr = &out;
+
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ default:
+ BLEND(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+ }
+
+ src++;
+ *dst++ = ((R_VAL(ptr) & 0xF8) << 8) | ((G_VAL(ptr) & 0xFC) << 3) | ((B_VAL(ptr) & 0xF8) >> 3);
+ }
+
+ dst += dlinelen - w;
+ src += slinelen - w;
+ }
} else {
- /* 5/5/5 format*/
- while(--h >= 0) {
- for(i=0; i
- unsigned int s = *src++;
- unsigned int d = *dst;
- unsigned int t = d & 0x7c00;
- unsigned int m1, m2, m3;
- m1 = (((((s & 0x7c00) - t)*alpha)>>8) & 0x7c00) + t;
- t = d & 0x03e0;
- m2 = (((((s & 0x03e0) - t)*alpha)>>8) & 0x03e0) + t;
- t = d & 0x001f;
- m3 = (((((s & 0x001f) - t)*alpha)>>8) & 0x001f) + t;
- *dst++ = m1 | m2 | m3;
- }
- dst += dlinelen - w;
- src += slinelen - w;
- }
+
+ while(--h >= 0) {
+ for(i=0; i
+ unsigned long tmp;
+
+ unsigned long in = (*src & 0x7c00) << 9 | (*src & 0x03e0) << 6 | (*src & 0x001f) << 3;
+ unsigned long out = (*dst & 0x7c00) << 9 | (*dst & 0x03e0) << 6 | (*dst & 0x001f) << 3;
+
+ unsigned long *ptr = &out;
+
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ default:
+ BLEND(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+ }
+ src++;
+ *dst++ = ((R_VAL(ptr) & 0xF8) << 7) | ((G_VAL(ptr) & 0xF8) << 2) | ((B_VAL(ptr) & 0xF8) >> 3);
+ }
+
+ dst += dlinelen - w;
+ src += slinelen - w;
+ }
}
DRAWOFF;
return;
-stdblit:
+ stdblit:
#endif
if (op == MWROP_COPY) {
diff -Nur microwindows-0.91.org/src/drivers/fblin24.c microwindows-0.91/src/drivers/fblin24.c
--- microwindows-0.91.org/src/drivers/fblin24.c 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/drivers/fblin24.c 2008-11-18 22:09:45.000000000 +0800
@@ -172,25 +172,45 @@
src += (srcx + srcy * srcpsd->linelen) * 3;
#if ALPHABLEND
- if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
+#define R_VAL(p) ((unsigned char *)(p))[2]
+#define G_VAL(p) ((unsigned char *)(p))[1]
+#define B_VAL(p) ((unsigned char *)(p))[0]
+
+#include
+
+ if((op & MWROP_EXTENSION) < MWROP_BLEND)
goto stdblit;
alpha = op & 0xff;
-
+
while(--h >= 0) {
- for(i=0; i
- unsigned long s = *src++;
- unsigned long d = *dst;
- *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- s = *src++;
- d = *dst;
- *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- s = *src++;
- d = *dst;
- *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- }
- dst += dlinelen_minus_w;
- src += slinelen_minus_w;
+ for(i=0; i
+ unsigned long tmp;
+
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+
+ default:
+ BLEND(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+ }
+
+ src++;
+ dst++;
+ }
+
+ dst += dlinelen_minus_w;
+ src += slinelen_minus_w;
}
+
DRAWOFF;
return;
stdblit:
diff -Nur microwindows-0.91.org/src/drivers/fblin32.c microwindows-0.91/src/drivers/fblin32.c
--- microwindows-0.91.org/src/drivers/fblin32.c 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/drivers/fblin32.c 2008-11-19 13:36:20.000000000 +0800
@@ -119,14 +119,12 @@
linear32_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
{
- ADDR8 dst8, src8;
ADDR32 dst = dstpsd->addr;
ADDR32 src = srcpsd->addr;
int i;
int dlinelen = dstpsd->linelen;
int slinelen = srcpsd->linelen;
- int dlinelen_minus_w4;
- int slinelen_minus_w4;
+
#if ALPHABLEND
unsigned int alpha;
#endif
@@ -149,35 +147,44 @@
src += srcx + srcy * slinelen;
#if ALPHABLEND
- if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
- goto stdblit;
- alpha = op & 0xff;
-
- src8 = (ADDR8)src;
- dst8 = (ADDR8)dst;
- dlinelen_minus_w4 = (dlinelen - w) * 4;
- slinelen_minus_w4 = (slinelen - w) * 4;
- while(--h >= 0) {
- for(i=0; i
- /* FIXME: This doesn't look endian-neutral.
- * I don't think this'll work on PowerPC,
- * but I don't have one to test it.
- */
- register unsigned long s = *src8++;
- register unsigned long d = *dst8;
- *dst8++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- s = *src8++;
- d = *dst8;
- *dst8++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- s = *src8;
- d = *dst8;
- *dst8 = (unsigned char)(((s - d)*alpha)>>8) + d;
- dst8 += 2;
- src8 += 2;
- }
- dst8 += dlinelen_minus_w4;
- src8 += slinelen_minus_w4;
- }
+
+ #define R_VAL(p) ((unsigned char *)(p))[2]
+ #define G_VAL(p) ((unsigned char *)(p))[1]
+ #define B_VAL(p) ((unsigned char *)(p))[0]
+
+ #include
+
+ if((op & MWROP_EXTENSION) < MWROP_BLEND)goto stdblit;
+ alpha = op & 0xff;
+
+ while(--h >= 0) {
+ for(i=0; i
+ unsigned long tmp;
+
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+
+ default:
+ BLEND(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+ }
+
+ src++;
+ dst++;
+ }
+
+ dst += dlinelen - w;
+ src += slinelen - w;
+ }
DRAWOFF;
return;
stdblit:
diff -Nur microwindows-0.91.org/src/drivers/fblin8.c microwindows-0.91/src/drivers/fblin8.c
--- microwindows-0.91.org/src/drivers/fblin8.c 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/drivers/fblin8.c 2008-11-18 22:09:45.000000000 +0800
@@ -19,6 +19,11 @@
#include "device.h"
#include "fb.h"
+/* FIXME: This table lookup does not scale well
+ We now have 4 alpha blending modes, which would result in 256 * 256 * 4 entries
+ which IMHO is not acceptable. This needs to be re thought
+*/
+
#if ALPHABLEND
/*
* Alpha lookup tables for 256 color palette systems
@@ -164,37 +169,86 @@
src = ((ADDR8)srcpsd->addr) + srcx + srcy * slinelen;
#if ALPHABLEND
- if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
+
+#define R_VAL(p) ((unsigned char *)(p))[2]
+#define G_VAL(p) ((unsigned char *)(p))[1]
+#define B_VAL(p) ((unsigned char *)(p))[0]
+
+#include
+
+ if((op & MWROP_EXTENSION) < MWROP_BLEND)
goto stdblit;
srcalpha = op & 0xff;
/* FIXME create lookup table after palette is stabilized...*/
- if(!rgb_to_palindex || !alpha_to_rgb) {
- init_alpha_lookup();
- if(!rgb_to_palindex || !alpha_to_rgb)
- goto stdblit;
- }
+ /* We should only do this for palette mode - truecolor 332
+ can compute it on the fly */
- /* Create 5 bit alpha value index for 256 color indexing*/
-
- /* destination alpha is (1 - source) alpha*/
- dstalpha = ((srcalpha>>3) ^ 31) << 8;
- srcalpha = (srcalpha>>3) << 8;
-
- while(--h >= 0) {
+ if (dstpsd->pixtype == MWPF_PALETTE) {
+ if(!rgb_to_palindex || !alpha_to_rgb) {
+ init_alpha_lookup();
+ if(!rgb_to_palindex || !alpha_to_rgb)
+ goto stdblit;
+ }
+
+ /* Create 5 bit alpha value index for 256 color indexing*/
+
+ /* destination alpha is (1 - source) alpha*/
+ dstalpha = ((srcalpha>>3) ^ 31) << 8;
+ srcalpha = (srcalpha>>3) << 8;
+
+ while(--h >= 0) {
int i;
for(i=0; i
- /* Get source RGB555 value for source alpha value*/
- unsigned short s = alpha_to_rgb[srcalpha + *src++];
+ /* Get source RGB555 value for source alpha value*/
+ unsigned short s = alpha_to_rgb[srcalpha + *src++];
+
+ /* Get destination RGB555 value for dest alpha value*/
+ unsigned short d = alpha_to_rgb[dstalpha + *dst];
+
+ /* Add RGB values together and get closest palette index to it*/
+ *dst++ = rgb_to_palindex[s + d];
+ }
+ dst += dlinelen - w;
+ src += slinelen - w;
+ }
+ }
+ else { /* Truecolor 332 mode */
+ unsigned long tmp;
+
+ while(--h >= 0) {
+ int i;
+ for(i=0; i
+ unsigned long in = (*src & 0xE0) << 16 | (*src & 0x16) << 11 | (*src & 0x03) << 6;
+ unsigned long out = (*dst & 0xE0) << 16 | (*dst & 0x16) << 11 | (*dst & 0x03) << 6;
- /* Get destination RGB555 value for dest alpha value*/
- unsigned short d = alpha_to_rgb[dstalpha + *dst];
+ unsigned long *ptr = &out;
- /* Add RGB values together and get closest palette index to it*/
- *dst++ = rgb_to_palindex[s + d];
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(&in), G_VAL(&in), B_VAL(&in), srcalpha, ptr);
+ break;
+
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(&in), G_VAL(&in), B_VAL(&in), srcalpha, ptr);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(&in), G_VAL(&in), B_VAL(&in), srcalpha, ptr);
+ break;
+
+ default:
+ BLEND(R_VAL(&in), G_VAL(&in), B_VAL(&in), srcalpha, ptr);
+ break;
+ }
+
+ src++;
+ *dst++ = ((R_VAL(ptr) & 0x07) << 5) | ((G_VAL(ptr) & 0x07) << 2) | (B_VAL(ptr) & 0x03);
}
+
dst += dlinelen - w;
src += slinelen - w;
+ }
}
DRAWOFF;
return;
diff -Nur microwindows-0.91.org/src/include/alpha.h microwindows-0.91/src/include/alpha.h
--- microwindows-0.91.org/src/include/alpha.h 1970-01-01 08:00:00.000000000 +0800
+++ microwindows-0.91/src/include/alpha.h 2008-11-18 22:09:45.000000000 +0800
@@ -0,0 +1,296 @@
+/*
+ * Copied and inspired by imlib2/src/blend.h
+ * most routines by Raster (raster@rasterman.com).
+ *
+ * IMBLIB2 Copyright (C) 1999 Carsten Haitzler and various contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies of the Software, its documentation and marketing & publicity
+ * materials, and acknowledgment shall be given in the documentation, materials
+ * and software packages that this Software was used.
+ */
+
+/* I have included Rasters excellent comments at the bottom of this file. These
+ routines and alogrithms are his. Thank you so much Raster (and special props to Chris Ross,
+ who pointed these out to me). The only changes I made are to refect the fact that we don't
+ currently have a alpha channel, so we don't need to worry about merging / saturating the
+ destination alpha channel.
+*/
+
+/* Note: The macros R_VAL, G_VAL and B_VAL need to be defined for the appropriate depth */
+
+#if !defined(R_VAL) || !defined(G_VAL) || !defined(B_VAL)
+#error You have to define R_VAL, G_VAL and B_VAL for your depth
+#endif
+
+/* Saturate values in the range [0, 512) */
+#define SATURATE_UPPER(nc, v) nc = ((v) | (-((v) >> 8)))
+
+/* Saturate values in the range (-256, 256) */
+#define SATURATE_LOWER(nc, v) nc = (v) & (~((v) >> 8))
+
+/* Saturate values in the range (-256, 512) */
+#define SATURATE_BOTH(nc, v) nc = ((v) | (-((v) >> 8))) & (~((v) >> 9))
+
+#define BLEND_COLOR(a, nc, c, cc) \
+tmp = ((c) - (cc)) * (a); \
+nc = (cc) + ((tmp + (tmp >> 8) + 0x80) >> 8);
+
+#define ADD_COLOR_WITH_ALPHA(a, nc, c, cc) \
+tmp = (cc) + (((c) * (a)) >> 8); \
+SATURATE_UPPER(nc, tmp);
+
+#define ADD_COLOR(nc, c, cc) \
+tmp = (cc) + (c); \
+SATURATE_UPPER(nc, tmp);
+
+#define SUB_COLOR_WITH_ALPHA(a, nc, c, cc) \
+tmp = (cc) - (((c) * (a)) >> 8); \
+SATURATE_LOWER((nc), (tmp));
+
+#define SUB_COLOR(nc, c, cc) \
+tmp = (cc) - (c); \
+SATURATE_LOWER(nc, tmp);
+
+#define RESHADE_COLOR_WITH_ALPHA(a, nc, c, cc) \
+tmp = (cc) + ((((c) - 127) * (a)) >> 7); \
+SATURATE_BOTH(nc, tmp);
+
+#define RESHADE_COLOR(nc, c, cc) \
+tmp = (cc) + (((c) - 127) << 1); \
+SATURATE_BOTH(nc, tmp);
+
+#define BLEND(r1, g1, b1, a1, dest) \
+BLEND_COLOR(a1, R_VAL(dest), r1, R_VAL(dest)); \
+BLEND_COLOR(a1, G_VAL(dest), g1, G_VAL(dest)); \
+BLEND_COLOR(a1, B_VAL(dest), b1, B_VAL(dest));
+
+#define BLEND_ADD(r1, g1, b1, a1, dest) \
+ADD_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
+ADD_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
+ADD_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
+
+#define BLEND_SUB(r1, g1, b1, a1, dest) \
+SUB_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
+SUB_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
+SUB_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
+
+#define BLEND_RE(r1, g1, b1, a1, dest) \
+RESHADE_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
+RESHADE_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
+RESHADE_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
+
+/*
+ * 1) Basic Saturation - 8 bit unsigned
+ *
+ * The add, subtract, and reshade operations generate new color values that may
+ * be out of range for an unsigned 8 bit quantity. Therefore, we will want to
+ * saturate the values into the range [0, 255]. Any value < 0 will become 0,
+ * and any value > 255 will become 255. Or simply:
+ *
+ * saturated = (value < 0) ? 0 : ((value > 255) ? 255 : value)
+ *
+ * Of course the above isn't the most efficient means of saturating. Sometimes
+ * due to the nature of a calculation, we know we only need to saturate from
+ * above (> 255) or just from below (< 0). Or simply:
+ *
+ * saturated = (value < 0) ? 0 : value
+ * saturated = (value > 255) ? 255 : value
+ *
+ * 2) Alternate Forms of Saturation
+ *
+ * The methods of saturation described above use testing/branching operations,
+ * which are not necessarily efficient on all platforms. There are other means
+ * of performing saturation using just simple arithmetic operations
+ * (+, -, >>, <<, ~). A discussion of these saturation techniques follows.
+ *
+ * A) Saturation in the range [0, 512), or "from above".
+ *
+ * Assuming we have an integral value in the range [0, 512), the following
+ * formula evaluates to either 0, or 255:
+ *
+ * (value & 255) - ((value & 256) >> 8)
+ *
+ * This is easy to show. Notice that if the value is in the range [0, 256)
+ * the 9th bit is 0, and we get (0 - 0), which is 0. And if the value is in
+ * the range [256, 512) the 9th bit is 1, and we get (256 - 1), which is 255.
+ *
+ * Now, using the above information and the fact that assigning an integer to
+ * an 8 bit unsigned value will truncate to the lower 8 bits of the integer,
+ * the following properly saturates:
+ *
+ * 8bit_value = value | (value & 256) - ((value & 256) >> 8)
+ *
+ * To prove this to yourself, just think about what the lower 8 bits look like
+ * in the ranges [0, 256) and [256, 512). In particular, notice that the value
+ * in the range [0, 256) are unchanged, and values in the range [256, 512)
+ * always give you 255. Just what we want!
+ *
+ * B) Saturation in the range (-256, 256), or "from below".
+ *
+ * Assuming we have an integral value in the range (-256, 256), the following
+ * formula evaluates to either 0, or -1:
+ *
+ * ~(value >> 8)
+ *
+ * Here's why. If the value is in the range [0, 256), then shifting right by
+ * 8 bits gives us all 0 bits, or 0. And thus inverting the bits gives all
+ * 1 bits, which is -1. If the value is in the range (-256, 0), then the 9th
+ * bit and higher bits are all 1. So, when we shift right by 8 bits (with
+ * signed extension), we get a value with all 1 bits. Which when inverted is
+ * all 0 bits, or 0.
+ *
+ * Now, using the above information the following properly saturates:
+ *
+ * 8bit_value = value & (~(value >> 8))
+ *
+ * To prove this to yourself, noticed that values in the range (-256, 0) will
+ * always be AND'd with 0, and thus map to 0. Further, values in the range
+ * [0, 256) will always be AND'd with a value that is all 1 bits, and thus
+ * be unchanged. Just what we want!
+ *
+ * C) Saturation in the range (-256, 512), or "from above and below".
+ *
+ * The short of it is the following works:
+ *
+ * 8bit_value = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9))
+ *
+ * We leave it to the reader to prove. Looks very similar to the techniques
+ * used above, eh? :)
+ */
+
+/*
+ * 1) Operations
+ *
+ * There are 4 operations supported:
+ *
+ * Copy, Add, Subtract, and Reshade
+ *
+ * For each operation there are 3 different variations that can be made:
+ *
+ * a) Use "blend" or "copy" in the calculations? A "blend" uses the alpha
+ * value of the source pixel to lighten the source pixel values. Where
+ * as "copy" ignores the alpha value and uses the raw source pixel values.
+ * b) Include source alpha in the calculation for new destination alpha?
+ * If source alpha is not used, then destination alpha is preserved.
+ * If source alpha is used, a "copy" sets the new alpha to the source
+ * alpha, and a "blend" adds them together (with saturation).
+ * c) Should the source pixels be passed through a color modifier before the
+ * calculations are performed?
+ *
+ * All together we have 4*2*2*2 = 32 combinations.
+ *
+ * 2) Copy operation
+ *
+ * The "copy" version of this operation copies the source image onto the
+ * destination image.
+ *
+ * The "blend" version of this operation blends the source image color 'c' with
+ * the destination image color 'cc' using 'a' (in the range [0, 1]) according
+ * to the following formula. Also notice that saturation is not needed for
+ * this calculation, the output is in the range [0, 255]:
+ *
+ * nc = c * alpha + (1 - alpha) * cc
+ * = c * alpha - cc * alpha + cc
+ * = (c - cc) * alpha + cc;
+ *
+ * A discussion of how we're calculating this value follows:
+ *
+ * We're using 'a', an integer, in the range [0, 255] for alpha (and for 'c'
+ * and 'cc', BTW). Therefore, we need to slightly modify the equation to take
+ * that into account. To get into the range [0, 255] we need to divide 'a'
+ * by 255:
+ *
+ * nc = ((c - cc) * a) / 255 + cc
+ *
+ * Notice that it is faster to divide by 256 (bit shifting), however without a
+ * fudge factor 'x' to balance things this isn't horribly accurate. So, let's
+ * solve for 'x'. The equality is:
+ *
+ * ((c - cc) * a) / 256 + cc + x = ((c - cc) * a) / 255 + cc
+ *
+ * The 'cc' terms cancel, and multiply both sides by 255*256 to remove the
+ * fractions:
+ *
+ * ((c - cc) * a) * 255 + 255 * 256 * x = ((c - cc) * a) * 256
+ *
+ * Get the 'x' term alone:
+ *
+ * 255 * 256 * x = ((c - cc) * a)
+ *
+ * Divide both sides by 255 * 256 to solve for 'x':
+ *
+ * x = ((c - cc) * a) / (255 * 256)
+ *
+ * And putting 'x' back into the equation we get:
+ *
+ * nc = ((c - cc) * a) / 256 + cc + ((c - cc) * a) / (255 * 256)
+ *
+ * And if we let 'tmp' represent the value '(c - cc) * a', and do a little
+ * regrouping we get:
+ *
+ * nc = tmp / 256 + tmp / (255 * 256) + cc
+ * = (tmp + tmp / 255) / 256 + cc
+ *
+ * We'll be using integer arithmetic, and over the range of values tmp takes
+ * (in [-255*255, 255*255]) the term tmp/(255*256) is pretty much the same as
+ * tmp/(256*256). So we get:
+ *
+ * nc = (tmp + tmp / 256) / 256 + cc
+ *
+ * And because the division of the sum uses integer arithmetic, it always
+ * rounds up/down even if that isn't the "best" choice. If we add .5 to the
+ * sum, we can get standard rounding: Like so:
+ *
+ * nc = (tmp + tmp / 256 + 128) / 256 + cc
+ *
+ * 3) Add operation
+ *
+ * The "copy" version of this operation sums the source image pixel values
+ * with the destination image pixel values, saturating at 255 (from above).
+ *
+ * The "blend" version of this operation sums the source image pixel values,
+ * after taking into account alpha transparency (e.g. a percentage), with the
+ * destination image pixel values, saturating at 255 (from above).
+ *
+ * 4) Subtract operation
+ *
+ * This operation is the same as the Add operation, except the source values
+ * are subtracted from the destination values (instead of added). Further,
+ * the result must be saturated at 0 (from below).
+ *
+ * 5) Reshade operation
+ *
+ * This operation uses the source image color values to lighten/darken color
+ * values in the destination image using the following formula:
+ *
+ * nc = cc + ((c - middle_value) * 2 * alpha)
+ *
+ * Recall our pixel color and alpha values are in the range [0, 255]. So, the
+ * "blend" version of this operation can be calculated as:
+ *
+ * nc = cc + ((c - 127) * 2 * (a / 255))
+ *
+ * And in an integer arithmetic friendly form is:
+ *
+ * nc = cc + (((c - 127) * a) >> 7)
+ *
+ * The "copy" version of this operation treats alpha as 1.0 (or a/255), and in
+ * integer arithmetic friendly form is:
+ *
+ * nc = cc + ((c - 127) << 1)
+ *
+ * Notice the color values created by this operation are in the range
+ * (-256, 512), and thus must be saturated at 0 and 255 (from above and below).
+ */
+
+
+
+
diff -Nur microwindows-0.91.org/src/include/mwtypes.h microwindows-0.91/src/include/mwtypes.h
--- microwindows-0.91.org/src/include/mwtypes.h 2008-11-17 20:36:14.000000000 +0800
+++ microwindows-0.91/src/include/mwtypes.h 2008-11-18 22:28:44.000000000 +0800
@@ -132,7 +132,7 @@
#define MWROP_SRCTRANSCOPY 0x21000000L
/* alpha blend src -> dst with constant alpha, alpha value in low 8 bits*/
-#define MWROP_BLENDCONSTANT 0x22000000L
+/*#define MWROP_BLENDCONSTANT 0x22000000L*/
/* alpha blend fg/bg color -> dst with src as alpha channel*/
#define MWROP_BLENDFGBG 0x23000000L
@@ -143,6 +143,18 @@
/* stretch src -> dst*/
#define MWROP_STRETCH 0x25000000L
+ /* alpha blend src & dst with constant alpha, alpha value in low 8 bits*/
+
+#define MWROP_BLEND 0x26000000L
+#define MWROP_BLENDCONSTANT MWROP_BLEND
+
+/* alpha blend src + dst with constant alpha, alpha value in low 8 bits */
+#define MWROP_BLENDADD 0x27000000L
+/* alpha blend src - dst with constant alpha, alpha value in low 8 bits */
+#define MWROP_BLENDSUBTRACT 0x28000000L
+/* Use src to lighten / darken dst value, alpha value in low 8 bits */
+#define MWROP_BLENDRESHADE 0x29000000L
+
/* Use the MWMODE value in the graphics context
* to choose the appropriate MWROP value.
* (This is only valid in calls to the Nano-X API,
http://hi.baidu.com/chenzhuoyou/blog/item/5ad45a3d9c057ceb3d6d97a2.html
http://hi.baidu.com/chenzhuoyou/blog/item/ee1f57607c7d5fdb8cb10d63.html
1.範例程式參考
src/demos/nanox/nxalpha.c
2.Patch microwindow-0.91
diff -Nur microwindows-0.91.org/src/demos/nanox/Makefile microwindows-0.91/src/demos/nanox/Makefile
--- microwindows-0.91.org/src/demos/nanox/Makefile 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/demos/nanox/Makefile 2008-11-18 22:13:45.000000000 +0800
@@ -57,6 +57,7 @@
$(MW_DIR_BIN)/ntetris \
$(MW_DIR_BIN)/getselection \
$(MW_DIR_BIN)/setselection \
+ $(MW_DIR_BIN)/nxalpha \
$(MW_DIR_BIN)/dashdemo \
$(MW_DIR_BIN)/pcfdemo \
$(MW_DIR_BIN)/fontdemo \
diff -Nur microwindows-0.91.org/src/demos/nanox/nxalpha.c microwindows-0.91/src/demos/nanox/nxalpha.c
--- microwindows-0.91.org/src/demos/nanox/nxalpha.c 1970-01-01 08:00:00.000000000 +0800
+++ microwindows-0.91/src/demos/nanox/nxalpha.c 2008-11-19 13:20:49.000000000 +0800
@@ -0,0 +1,192 @@
+/* Alpha blending demo
+ By Jordan Crouse
+
+ This takes our favorite penguin and alpha blends him
+ against the background. Hit the + and - keys to adjust the
+ alpha.
+*/
+
+#include
+#include
+#include
+
+#define BGCOLOR GR_RGB(24, 125, 148)
+//#define BGCOLOR GR_RGB(0, 0, 0)
+
+int sw, sh;
+int iw = 91, ih = 100;
+
+int g_alpha = 128;
+GR_WINDOW_ID g_wid, g_pixmap, g_image;
+
+void do_alpha_blit(int x, int y, int w, int h, unsigned long mode) {
+
+ GR_GC_ID gc = GrNewGC();
+ GrSetGCForeground(gc, BGCOLOR);
+
+ /* Clear the holding buffer */
+ GrFillRect(g_pixmap, gc, 0, 0, w, h);
+#if 0
+ /* Alpha blend the image in */
+ GrCopyArea(g_pixmap, gc, 0, 0, w, h, g_image, 0, 0, MWROP_SRCCOPY);
+
+ GrFillRect(g_pixmap, gc, 10, 10, 50, 50);
+
+ GrCopyArea(g_pixmap, gc, 10, 10, 50, 50, g_image, 10, 10, mode);
+#endif
+#if 1
+ /* Alpha blend the image in */
+ GrCopyArea(g_pixmap, gc, 0, 0, w, h, g_image, 0, 0, mode);
+#endif
+ /* Copy the holding buffer to the screen */
+ GrCopyArea(g_wid, gc, x, y, w, h, g_pixmap, 0, 0, MWROP_SRCCOPY);
+ GrDestroyGC(gc);
+}
+
+void draw_window(int alpha) {
+
+ int xpos;
+
+ GR_GC_ID gc = GrNewGC();
+ GrSetGCForeground(gc, GR_RGB(255,255,255));
+ GrSetGCBackground(gc, BGCOLOR);
+ xpos = (sw - ((5 * iw) + 30)) / 2;
+
+ GrText(g_wid, gc, 5, 5, "Press + / - to change the alpha value", -1,
+ GR_TFTOP);
+
+ GrText(g_wid, gc, xpos, ((sh - ih) / 2) - 20, "Original", -1, 0);
+ GrCopyArea(g_wid, gc, xpos, (sh - ih) / 2, iw, ih, g_image,
+ 0, 0, MWROP_SRCCOPY);
+
+ xpos += iw + 10;
+
+ GrText(g_wid, gc, xpos, ((sh - ih) / 2) - 20, "Blend", -1, 0);
+ do_alpha_blit(xpos, (sh - ih) / 2, iw, ih, MWROP_BLEND | (alpha & 0xFF));
+
+ xpos += iw + 10;
+
+ GrText(g_wid, gc, xpos, (sh - ih) / 2 - 20, "Add", -1, 0);
+ do_alpha_blit(xpos, (sh - ih) / 2, iw, ih, MWROP_BLENDADD | (alpha & 0xFF));
+
+ xpos += iw + 10;
+
+ GrText(g_wid, gc, xpos, (sh - ih) / 2 - 20, "Subtract", -1, 0);
+ do_alpha_blit(xpos, (sh - ih) / 2, iw, ih, MWROP_BLENDSUBTRACT | (alpha & 0xFF));
+
+ xpos += iw + 10;
+
+ GrText(g_wid, gc, xpos, (sh - ih) / 2 - 20, "Reshade", -1, 0);
+ do_alpha_blit(xpos, (sh - ih) / 2, iw, ih, MWROP_BLENDRESHADE | (alpha & 0xFF));
+
+ GrDestroyGC(gc);
+}
+
+void handle_events(GR_EVENT *event) {
+
+ switch(event->type) {
+ case GR_EVENT_TYPE_EXPOSURE:
+ draw_window(g_alpha);
+ break;
+
+ case GR_EVENT_TYPE_KEY_DOWN:
+ switch(event->keystroke.ch & 0x1) {
+ //case '=':
+ case 0:
+ g_alpha += 5;
+ if (g_alpha > 255) g_alpha = 255;
+ break;
+
+ //case '-':
+ case 1:
+ g_alpha -= 5;
+ if (g_alpha < 0) g_alpha = 0;
+ break;
+ }
+
+ printf("Alpha: %3.3d\r", g_alpha);
+ fflush(stdout);
+
+ draw_window(g_alpha);
+ break;
+
+ case GR_EVENT_TYPE_CLOSE_REQ:
+ exit(0);
+ }
+}
+
+int load_image(char *filename) {
+
+ GR_IMAGE_INFO iinfo;
+
+ GR_GC_ID gc = GrNewGC();
+ GR_IMAGE_ID image = GrLoadImageFromFile(filename, 0);
+
+ if (!image) return(-1);
+
+ GrGetImageInfo(image, &iinfo);
+
+ iw = iinfo.width;
+ ih = iinfo.height;
+
+ /* Make the pixmaps that will buffer the draw */
+ g_pixmap = GrNewPixmap(iw, ih, 0);
+ g_image = GrNewPixmap(iw, ih, 0);
+
+ GrSetGCForeground(gc, BGCOLOR);
+ GrFillRect(g_image, gc, 0, 0, iw, ih);
+
+ GrDrawImageToFit(g_image, gc, 0, 0, -1, -1, image);
+
+ GrDestroyGC(gc);
+ GrFreeImage(image);
+ return(0);
+}
+
+int main(int argc, char **argv) {
+
+ GR_SCREEN_INFO sinfo;
+
+ g_alpha = 128;
+
+ if (GrOpen() == -1) return(-1);
+
+ if (argc < 2) {
+ if(load_image("tux.gif") == -1) {
+ printf("Unable to open the image [tux.gif]\n");
+ GrClose();
+ return(-1);
+ }
+ }
+ else {
+ if (load_image(argv[1]) == -1) {
+ printf("Unable to open the image [%s]\n", argv[1]);
+ GrClose();
+ return(-1);
+ }
+ }
+
+ GrGetScreenInfo(&sinfo);
+
+ sw = sinfo.cols - 20;
+ sh = sinfo.rows - 20;
+
+ g_wid = GrNewWindow(GR_ROOT_WINDOW_ID,
+ 10, 10, sw, sh, 0, BGCOLOR, 0);
+
+ GrSelectEvents(g_wid,
+ GR_EVENT_MASK_KEY_DOWN |
+ GR_EVENT_MASK_EXPOSURE |
+ GR_EVENT_MASK_CLOSE_REQ);
+
+ GrMapWindow(g_wid);
+
+ fflush(stdout);
+
+ while(1) {
+ GR_EVENT event;
+ GrGetNextEvent(&event);
+
+ handle_events(&event);
+ }
+}
diff -Nur microwindows-0.91.org/src/drivers/fblin16.c microwindows-0.91/src/drivers/fblin16.c
--- microwindows-0.91.org/src/drivers/fblin16.c 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/drivers/fblin16.c 2008-11-18 22:09:45.000000000 +0800
@@ -166,49 +166,90 @@
src += srcx + srcy * slinelen;
#if ALPHABLEND
- if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
- goto stdblit;
+
+#define R_VAL(p) ((unsigned char *)(p))[2]
+#define G_VAL(p) ((unsigned char *)(p))[1]
+#define B_VAL(p) ((unsigned char *)(p))[0]
+
+#include
+
+ if((op & MWROP_EXTENSION) < MWROP_BLEND) goto stdblit;
alpha = op & 0xff;
- if (dstpsd->pixtype == MWPF_TRUECOLOR565) {
- while(--h >= 0) {
- for(i=0; i
- unsigned int s = *src++;
- unsigned int d = *dst;
- unsigned int t = d & 0xf800;
- unsigned int m1, m2, m3;
- m1 = (((((s & 0xf800) - t)*alpha)>>8) & 0xf800) + t;
- t = d & 0x07e0;
- m2 = (((((s & 0x07e0) - t)*alpha)>>8) & 0x07e0) + t;
- t = d & 0x001f;
- m3 = (((((s & 0x001f) - t)*alpha)>>8) & 0x001f) + t;
- *dst++ = m1 | m2 | m3;
- }
- dst += dlinelen - w;
- src += slinelen - w;
- }
+ if (dstpsd->pixtype == MWPF_TRUECOLOR565) { /* 565 format */
+ while(--h >= 0) {
+ for(i=0; i
+ unsigned long tmp;
+
+ unsigned long in = (*src & 0xf800) << 8 | (*src & 0x07e0) << 5 | (*src & 0x001f) << 3;
+ unsigned long out = (*dst & 0xf800) << 8 | (*dst & 0x07e0) << 5 | (*dst & 0x001f) << 3;
+
+ unsigned long *ptr = &out;
+
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ default:
+ BLEND(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+ }
+
+ src++;
+ *dst++ = ((R_VAL(ptr) & 0xF8) << 8) | ((G_VAL(ptr) & 0xFC) << 3) | ((B_VAL(ptr) & 0xF8) >> 3);
+ }
+
+ dst += dlinelen - w;
+ src += slinelen - w;
+ }
} else {
- /* 5/5/5 format*/
- while(--h >= 0) {
- for(i=0; i
- unsigned int s = *src++;
- unsigned int d = *dst;
- unsigned int t = d & 0x7c00;
- unsigned int m1, m2, m3;
- m1 = (((((s & 0x7c00) - t)*alpha)>>8) & 0x7c00) + t;
- t = d & 0x03e0;
- m2 = (((((s & 0x03e0) - t)*alpha)>>8) & 0x03e0) + t;
- t = d & 0x001f;
- m3 = (((((s & 0x001f) - t)*alpha)>>8) & 0x001f) + t;
- *dst++ = m1 | m2 | m3;
- }
- dst += dlinelen - w;
- src += slinelen - w;
- }
+
+ while(--h >= 0) {
+ for(i=0; i
+ unsigned long tmp;
+
+ unsigned long in = (*src & 0x7c00) << 9 | (*src & 0x03e0) << 6 | (*src & 0x001f) << 3;
+ unsigned long out = (*dst & 0x7c00) << 9 | (*dst & 0x03e0) << 6 | (*dst & 0x001f) << 3;
+
+ unsigned long *ptr = &out;
+
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+
+ default:
+ BLEND(R_VAL(&in), G_VAL(&in), B_VAL(&in), alpha, ptr);
+ break;
+ }
+ src++;
+ *dst++ = ((R_VAL(ptr) & 0xF8) << 7) | ((G_VAL(ptr) & 0xF8) << 2) | ((B_VAL(ptr) & 0xF8) >> 3);
+ }
+
+ dst += dlinelen - w;
+ src += slinelen - w;
+ }
}
DRAWOFF;
return;
-stdblit:
+ stdblit:
#endif
if (op == MWROP_COPY) {
diff -Nur microwindows-0.91.org/src/drivers/fblin24.c microwindows-0.91/src/drivers/fblin24.c
--- microwindows-0.91.org/src/drivers/fblin24.c 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/drivers/fblin24.c 2008-11-18 22:09:45.000000000 +0800
@@ -172,25 +172,45 @@
src += (srcx + srcy * srcpsd->linelen) * 3;
#if ALPHABLEND
- if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
+#define R_VAL(p) ((unsigned char *)(p))[2]
+#define G_VAL(p) ((unsigned char *)(p))[1]
+#define B_VAL(p) ((unsigned char *)(p))[0]
+
+#include
+
+ if((op & MWROP_EXTENSION) < MWROP_BLEND)
goto stdblit;
alpha = op & 0xff;
-
+
while(--h >= 0) {
- for(i=0; i
- unsigned long s = *src++;
- unsigned long d = *dst;
- *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- s = *src++;
- d = *dst;
- *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- s = *src++;
- d = *dst;
- *dst++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- }
- dst += dlinelen_minus_w;
- src += slinelen_minus_w;
+ for(i=0; i
+ unsigned long tmp;
+
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+
+ default:
+ BLEND(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+ }
+
+ src++;
+ dst++;
+ }
+
+ dst += dlinelen_minus_w;
+ src += slinelen_minus_w;
}
+
DRAWOFF;
return;
stdblit:
diff -Nur microwindows-0.91.org/src/drivers/fblin32.c microwindows-0.91/src/drivers/fblin32.c
--- microwindows-0.91.org/src/drivers/fblin32.c 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/drivers/fblin32.c 2008-11-19 13:36:20.000000000 +0800
@@ -119,14 +119,12 @@
linear32_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
{
- ADDR8 dst8, src8;
ADDR32 dst = dstpsd->addr;
ADDR32 src = srcpsd->addr;
int i;
int dlinelen = dstpsd->linelen;
int slinelen = srcpsd->linelen;
- int dlinelen_minus_w4;
- int slinelen_minus_w4;
+
#if ALPHABLEND
unsigned int alpha;
#endif
@@ -149,35 +147,44 @@
src += srcx + srcy * slinelen;
#if ALPHABLEND
- if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
- goto stdblit;
- alpha = op & 0xff;
-
- src8 = (ADDR8)src;
- dst8 = (ADDR8)dst;
- dlinelen_minus_w4 = (dlinelen - w) * 4;
- slinelen_minus_w4 = (slinelen - w) * 4;
- while(--h >= 0) {
- for(i=0; i
- /* FIXME: This doesn't look endian-neutral.
- * I don't think this'll work on PowerPC,
- * but I don't have one to test it.
- */
- register unsigned long s = *src8++;
- register unsigned long d = *dst8;
- *dst8++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- s = *src8++;
- d = *dst8;
- *dst8++ = (unsigned char)(((s - d)*alpha)>>8) + d;
- s = *src8;
- d = *dst8;
- *dst8 = (unsigned char)(((s - d)*alpha)>>8) + d;
- dst8 += 2;
- src8 += 2;
- }
- dst8 += dlinelen_minus_w4;
- src8 += slinelen_minus_w4;
- }
+
+ #define R_VAL(p) ((unsigned char *)(p))[2]
+ #define G_VAL(p) ((unsigned char *)(p))[1]
+ #define B_VAL(p) ((unsigned char *)(p))[0]
+
+ #include
+
+ if((op & MWROP_EXTENSION) < MWROP_BLEND)goto stdblit;
+ alpha = op & 0xff;
+
+ while(--h >= 0) {
+ for(i=0; i
+ unsigned long tmp;
+
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+
+ default:
+ BLEND(R_VAL(src), G_VAL(src), B_VAL(src), alpha, dst);
+ break;
+ }
+
+ src++;
+ dst++;
+ }
+
+ dst += dlinelen - w;
+ src += slinelen - w;
+ }
DRAWOFF;
return;
stdblit:
diff -Nur microwindows-0.91.org/src/drivers/fblin8.c microwindows-0.91/src/drivers/fblin8.c
--- microwindows-0.91.org/src/drivers/fblin8.c 2008-11-17 20:36:13.000000000 +0800
+++ microwindows-0.91/src/drivers/fblin8.c 2008-11-18 22:09:45.000000000 +0800
@@ -19,6 +19,11 @@
#include "device.h"
#include "fb.h"
+/* FIXME: This table lookup does not scale well
+ We now have 4 alpha blending modes, which would result in 256 * 256 * 4 entries
+ which IMHO is not acceptable. This needs to be re thought
+*/
+
#if ALPHABLEND
/*
* Alpha lookup tables for 256 color palette systems
@@ -164,37 +169,86 @@
src = ((ADDR8)srcpsd->addr) + srcx + srcy * slinelen;
#if ALPHABLEND
- if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
+
+#define R_VAL(p) ((unsigned char *)(p))[2]
+#define G_VAL(p) ((unsigned char *)(p))[1]
+#define B_VAL(p) ((unsigned char *)(p))[0]
+
+#include
+
+ if((op & MWROP_EXTENSION) < MWROP_BLEND)
goto stdblit;
srcalpha = op & 0xff;
/* FIXME create lookup table after palette is stabilized...*/
- if(!rgb_to_palindex || !alpha_to_rgb) {
- init_alpha_lookup();
- if(!rgb_to_palindex || !alpha_to_rgb)
- goto stdblit;
- }
+ /* We should only do this for palette mode - truecolor 332
+ can compute it on the fly */
- /* Create 5 bit alpha value index for 256 color indexing*/
-
- /* destination alpha is (1 - source) alpha*/
- dstalpha = ((srcalpha>>3) ^ 31) << 8;
- srcalpha = (srcalpha>>3) << 8;
-
- while(--h >= 0) {
+ if (dstpsd->pixtype == MWPF_PALETTE) {
+ if(!rgb_to_palindex || !alpha_to_rgb) {
+ init_alpha_lookup();
+ if(!rgb_to_palindex || !alpha_to_rgb)
+ goto stdblit;
+ }
+
+ /* Create 5 bit alpha value index for 256 color indexing*/
+
+ /* destination alpha is (1 - source) alpha*/
+ dstalpha = ((srcalpha>>3) ^ 31) << 8;
+ srcalpha = (srcalpha>>3) << 8;
+
+ while(--h >= 0) {
int i;
for(i=0; i
- /* Get source RGB555 value for source alpha value*/
- unsigned short s = alpha_to_rgb[srcalpha + *src++];
+ /* Get source RGB555 value for source alpha value*/
+ unsigned short s = alpha_to_rgb[srcalpha + *src++];
+
+ /* Get destination RGB555 value for dest alpha value*/
+ unsigned short d = alpha_to_rgb[dstalpha + *dst];
+
+ /* Add RGB values together and get closest palette index to it*/
+ *dst++ = rgb_to_palindex[s + d];
+ }
+ dst += dlinelen - w;
+ src += slinelen - w;
+ }
+ }
+ else { /* Truecolor 332 mode */
+ unsigned long tmp;
+
+ while(--h >= 0) {
+ int i;
+ for(i=0; i
+ unsigned long in = (*src & 0xE0) << 16 | (*src & 0x16) << 11 | (*src & 0x03) << 6;
+ unsigned long out = (*dst & 0xE0) << 16 | (*dst & 0x16) << 11 | (*dst & 0x03) << 6;
- /* Get destination RGB555 value for dest alpha value*/
- unsigned short d = alpha_to_rgb[dstalpha + *dst];
+ unsigned long *ptr = &out;
- /* Add RGB values together and get closest palette index to it*/
- *dst++ = rgb_to_palindex[s + d];
+ switch (op & MWROP_EXTENSION) {
+ case MWROP_BLENDADD:
+ BLEND_ADD(R_VAL(&in), G_VAL(&in), B_VAL(&in), srcalpha, ptr);
+ break;
+
+ case MWROP_BLENDSUBTRACT:
+ BLEND_SUB(R_VAL(&in), G_VAL(&in), B_VAL(&in), srcalpha, ptr);
+ break;
+
+ case MWROP_BLENDRESHADE:
+ BLEND_RE(R_VAL(&in), G_VAL(&in), B_VAL(&in), srcalpha, ptr);
+ break;
+
+ default:
+ BLEND(R_VAL(&in), G_VAL(&in), B_VAL(&in), srcalpha, ptr);
+ break;
+ }
+
+ src++;
+ *dst++ = ((R_VAL(ptr) & 0x07) << 5) | ((G_VAL(ptr) & 0x07) << 2) | (B_VAL(ptr) & 0x03);
}
+
dst += dlinelen - w;
src += slinelen - w;
+ }
}
DRAWOFF;
return;
diff -Nur microwindows-0.91.org/src/include/alpha.h microwindows-0.91/src/include/alpha.h
--- microwindows-0.91.org/src/include/alpha.h 1970-01-01 08:00:00.000000000 +0800
+++ microwindows-0.91/src/include/alpha.h 2008-11-18 22:09:45.000000000 +0800
@@ -0,0 +1,296 @@
+/*
+ * Copied and inspired by imlib2/src/blend.h
+ * most routines by Raster (raster@rasterman.com).
+ *
+ * IMBLIB2 Copyright (C) 1999 Carsten Haitzler and various contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies of the Software, its documentation and marketing & publicity
+ * materials, and acknowledgment shall be given in the documentation, materials
+ * and software packages that this Software was used.
+ */
+
+/* I have included Rasters excellent comments at the bottom of this file. These
+ routines and alogrithms are his. Thank you so much Raster (and special props to Chris Ross,
+ who pointed these out to me). The only changes I made are to refect the fact that we don't
+ currently have a alpha channel, so we don't need to worry about merging / saturating the
+ destination alpha channel.
+*/
+
+/* Note: The macros R_VAL, G_VAL and B_VAL need to be defined for the appropriate depth */
+
+#if !defined(R_VAL) || !defined(G_VAL) || !defined(B_VAL)
+#error You have to define R_VAL, G_VAL and B_VAL for your depth
+#endif
+
+/* Saturate values in the range [0, 512) */
+#define SATURATE_UPPER(nc, v) nc = ((v) | (-((v) >> 8)))
+
+/* Saturate values in the range (-256, 256) */
+#define SATURATE_LOWER(nc, v) nc = (v) & (~((v) >> 8))
+
+/* Saturate values in the range (-256, 512) */
+#define SATURATE_BOTH(nc, v) nc = ((v) | (-((v) >> 8))) & (~((v) >> 9))
+
+#define BLEND_COLOR(a, nc, c, cc) \
+tmp = ((c) - (cc)) * (a); \
+nc = (cc) + ((tmp + (tmp >> 8) + 0x80) >> 8);
+
+#define ADD_COLOR_WITH_ALPHA(a, nc, c, cc) \
+tmp = (cc) + (((c) * (a)) >> 8); \
+SATURATE_UPPER(nc, tmp);
+
+#define ADD_COLOR(nc, c, cc) \
+tmp = (cc) + (c); \
+SATURATE_UPPER(nc, tmp);
+
+#define SUB_COLOR_WITH_ALPHA(a, nc, c, cc) \
+tmp = (cc) - (((c) * (a)) >> 8); \
+SATURATE_LOWER((nc), (tmp));
+
+#define SUB_COLOR(nc, c, cc) \
+tmp = (cc) - (c); \
+SATURATE_LOWER(nc, tmp);
+
+#define RESHADE_COLOR_WITH_ALPHA(a, nc, c, cc) \
+tmp = (cc) + ((((c) - 127) * (a)) >> 7); \
+SATURATE_BOTH(nc, tmp);
+
+#define RESHADE_COLOR(nc, c, cc) \
+tmp = (cc) + (((c) - 127) << 1); \
+SATURATE_BOTH(nc, tmp);
+
+#define BLEND(r1, g1, b1, a1, dest) \
+BLEND_COLOR(a1, R_VAL(dest), r1, R_VAL(dest)); \
+BLEND_COLOR(a1, G_VAL(dest), g1, G_VAL(dest)); \
+BLEND_COLOR(a1, B_VAL(dest), b1, B_VAL(dest));
+
+#define BLEND_ADD(r1, g1, b1, a1, dest) \
+ADD_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
+ADD_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
+ADD_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
+
+#define BLEND_SUB(r1, g1, b1, a1, dest) \
+SUB_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
+SUB_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
+SUB_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
+
+#define BLEND_RE(r1, g1, b1, a1, dest) \
+RESHADE_COLOR_WITH_ALPHA(a1, R_VAL(dest), r1, R_VAL(dest)); \
+RESHADE_COLOR_WITH_ALPHA(a1, G_VAL(dest), g1, G_VAL(dest)); \
+RESHADE_COLOR_WITH_ALPHA(a1, B_VAL(dest), b1, B_VAL(dest));
+
+/*
+ * 1) Basic Saturation - 8 bit unsigned
+ *
+ * The add, subtract, and reshade operations generate new color values that may
+ * be out of range for an unsigned 8 bit quantity. Therefore, we will want to
+ * saturate the values into the range [0, 255]. Any value < 0 will become 0,
+ * and any value > 255 will become 255. Or simply:
+ *
+ * saturated = (value < 0) ? 0 : ((value > 255) ? 255 : value)
+ *
+ * Of course the above isn't the most efficient means of saturating. Sometimes
+ * due to the nature of a calculation, we know we only need to saturate from
+ * above (> 255) or just from below (< 0). Or simply:
+ *
+ * saturated = (value < 0) ? 0 : value
+ * saturated = (value > 255) ? 255 : value
+ *
+ * 2) Alternate Forms of Saturation
+ *
+ * The methods of saturation described above use testing/branching operations,
+ * which are not necessarily efficient on all platforms. There are other means
+ * of performing saturation using just simple arithmetic operations
+ * (+, -, >>, <<, ~). A discussion of these saturation techniques follows.
+ *
+ * A) Saturation in the range [0, 512), or "from above".
+ *
+ * Assuming we have an integral value in the range [0, 512), the following
+ * formula evaluates to either 0, or 255:
+ *
+ * (value & 255) - ((value & 256) >> 8)
+ *
+ * This is easy to show. Notice that if the value is in the range [0, 256)
+ * the 9th bit is 0, and we get (0 - 0), which is 0. And if the value is in
+ * the range [256, 512) the 9th bit is 1, and we get (256 - 1), which is 255.
+ *
+ * Now, using the above information and the fact that assigning an integer to
+ * an 8 bit unsigned value will truncate to the lower 8 bits of the integer,
+ * the following properly saturates:
+ *
+ * 8bit_value = value | (value & 256) - ((value & 256) >> 8)
+ *
+ * To prove this to yourself, just think about what the lower 8 bits look like
+ * in the ranges [0, 256) and [256, 512). In particular, notice that the value
+ * in the range [0, 256) are unchanged, and values in the range [256, 512)
+ * always give you 255. Just what we want!
+ *
+ * B) Saturation in the range (-256, 256), or "from below".
+ *
+ * Assuming we have an integral value in the range (-256, 256), the following
+ * formula evaluates to either 0, or -1:
+ *
+ * ~(value >> 8)
+ *
+ * Here's why. If the value is in the range [0, 256), then shifting right by
+ * 8 bits gives us all 0 bits, or 0. And thus inverting the bits gives all
+ * 1 bits, which is -1. If the value is in the range (-256, 0), then the 9th
+ * bit and higher bits are all 1. So, when we shift right by 8 bits (with
+ * signed extension), we get a value with all 1 bits. Which when inverted is
+ * all 0 bits, or 0.
+ *
+ * Now, using the above information the following properly saturates:
+ *
+ * 8bit_value = value & (~(value >> 8))
+ *
+ * To prove this to yourself, noticed that values in the range (-256, 0) will
+ * always be AND'd with 0, and thus map to 0. Further, values in the range
+ * [0, 256) will always be AND'd with a value that is all 1 bits, and thus
+ * be unchanged. Just what we want!
+ *
+ * C) Saturation in the range (-256, 512), or "from above and below".
+ *
+ * The short of it is the following works:
+ *
+ * 8bit_value = (tmp | ((tmp & 256) - ((tmp & 256) >> 8))) & (~(tmp >> 9))
+ *
+ * We leave it to the reader to prove. Looks very similar to the techniques
+ * used above, eh? :)
+ */
+
+/*
+ * 1) Operations
+ *
+ * There are 4 operations supported:
+ *
+ * Copy, Add, Subtract, and Reshade
+ *
+ * For each operation there are 3 different variations that can be made:
+ *
+ * a) Use "blend" or "copy" in the calculations? A "blend" uses the alpha
+ * value of the source pixel to lighten the source pixel values. Where
+ * as "copy" ignores the alpha value and uses the raw source pixel values.
+ * b) Include source alpha in the calculation for new destination alpha?
+ * If source alpha is not used, then destination alpha is preserved.
+ * If source alpha is used, a "copy" sets the new alpha to the source
+ * alpha, and a "blend" adds them together (with saturation).
+ * c) Should the source pixels be passed through a color modifier before the
+ * calculations are performed?
+ *
+ * All together we have 4*2*2*2 = 32 combinations.
+ *
+ * 2) Copy operation
+ *
+ * The "copy" version of this operation copies the source image onto the
+ * destination image.
+ *
+ * The "blend" version of this operation blends the source image color 'c' with
+ * the destination image color 'cc' using 'a' (in the range [0, 1]) according
+ * to the following formula. Also notice that saturation is not needed for
+ * this calculation, the output is in the range [0, 255]:
+ *
+ * nc = c * alpha + (1 - alpha) * cc
+ * = c * alpha - cc * alpha + cc
+ * = (c - cc) * alpha + cc;
+ *
+ * A discussion of how we're calculating this value follows:
+ *
+ * We're using 'a', an integer, in the range [0, 255] for alpha (and for 'c'
+ * and 'cc', BTW). Therefore, we need to slightly modify the equation to take
+ * that into account. To get into the range [0, 255] we need to divide 'a'
+ * by 255:
+ *
+ * nc = ((c - cc) * a) / 255 + cc
+ *
+ * Notice that it is faster to divide by 256 (bit shifting), however without a
+ * fudge factor 'x' to balance things this isn't horribly accurate. So, let's
+ * solve for 'x'. The equality is:
+ *
+ * ((c - cc) * a) / 256 + cc + x = ((c - cc) * a) / 255 + cc
+ *
+ * The 'cc' terms cancel, and multiply both sides by 255*256 to remove the
+ * fractions:
+ *
+ * ((c - cc) * a) * 255 + 255 * 256 * x = ((c - cc) * a) * 256
+ *
+ * Get the 'x' term alone:
+ *
+ * 255 * 256 * x = ((c - cc) * a)
+ *
+ * Divide both sides by 255 * 256 to solve for 'x':
+ *
+ * x = ((c - cc) * a) / (255 * 256)
+ *
+ * And putting 'x' back into the equation we get:
+ *
+ * nc = ((c - cc) * a) / 256 + cc + ((c - cc) * a) / (255 * 256)
+ *
+ * And if we let 'tmp' represent the value '(c - cc) * a', and do a little
+ * regrouping we get:
+ *
+ * nc = tmp / 256 + tmp / (255 * 256) + cc
+ * = (tmp + tmp / 255) / 256 + cc
+ *
+ * We'll be using integer arithmetic, and over the range of values tmp takes
+ * (in [-255*255, 255*255]) the term tmp/(255*256) is pretty much the same as
+ * tmp/(256*256). So we get:
+ *
+ * nc = (tmp + tmp / 256) / 256 + cc
+ *
+ * And because the division of the sum uses integer arithmetic, it always
+ * rounds up/down even if that isn't the "best" choice. If we add .5 to the
+ * sum, we can get standard rounding: Like so:
+ *
+ * nc = (tmp + tmp / 256 + 128) / 256 + cc
+ *
+ * 3) Add operation
+ *
+ * The "copy" version of this operation sums the source image pixel values
+ * with the destination image pixel values, saturating at 255 (from above).
+ *
+ * The "blend" version of this operation sums the source image pixel values,
+ * after taking into account alpha transparency (e.g. a percentage), with the
+ * destination image pixel values, saturating at 255 (from above).
+ *
+ * 4) Subtract operation
+ *
+ * This operation is the same as the Add operation, except the source values
+ * are subtracted from the destination values (instead of added). Further,
+ * the result must be saturated at 0 (from below).
+ *
+ * 5) Reshade operation
+ *
+ * This operation uses the source image color values to lighten/darken color
+ * values in the destination image using the following formula:
+ *
+ * nc = cc + ((c - middle_value) * 2 * alpha)
+ *
+ * Recall our pixel color and alpha values are in the range [0, 255]. So, the
+ * "blend" version of this operation can be calculated as:
+ *
+ * nc = cc + ((c - 127) * 2 * (a / 255))
+ *
+ * And in an integer arithmetic friendly form is:
+ *
+ * nc = cc + (((c - 127) * a) >> 7)
+ *
+ * The "copy" version of this operation treats alpha as 1.0 (or a/255), and in
+ * integer arithmetic friendly form is:
+ *
+ * nc = cc + ((c - 127) << 1)
+ *
+ * Notice the color values created by this operation are in the range
+ * (-256, 512), and thus must be saturated at 0 and 255 (from above and below).
+ */
+
+
+
+
diff -Nur microwindows-0.91.org/src/include/mwtypes.h microwindows-0.91/src/include/mwtypes.h
--- microwindows-0.91.org/src/include/mwtypes.h 2008-11-17 20:36:14.000000000 +0800
+++ microwindows-0.91/src/include/mwtypes.h 2008-11-18 22:28:44.000000000 +0800
@@ -132,7 +132,7 @@
#define MWROP_SRCTRANSCOPY 0x21000000L
/* alpha blend src -> dst with constant alpha, alpha value in low 8 bits*/
-#define MWROP_BLENDCONSTANT 0x22000000L
+/*#define MWROP_BLENDCONSTANT 0x22000000L*/
/* alpha blend fg/bg color -> dst with src as alpha channel*/
#define MWROP_BLENDFGBG 0x23000000L
@@ -143,6 +143,18 @@
/* stretch src -> dst*/
#define MWROP_STRETCH 0x25000000L
+ /* alpha blend src & dst with constant alpha, alpha value in low 8 bits*/
+
+#define MWROP_BLEND 0x26000000L
+#define MWROP_BLENDCONSTANT MWROP_BLEND
+
+/* alpha blend src + dst with constant alpha, alpha value in low 8 bits */
+#define MWROP_BLENDADD 0x27000000L
+/* alpha blend src - dst with constant alpha, alpha value in low 8 bits */
+#define MWROP_BLENDSUBTRACT 0x28000000L
+/* Use src to lighten / darken dst value, alpha value in low 8 bits */
+#define MWROP_BLENDRESHADE 0x29000000L
+
/* Use the MWMODE value in the graphics context
* to choose the appropriate MWROP value.
* (This is only valid in calls to the Nano-X API,
2008年11月16日 星期日
Microwindow 中文顯示 with pcf fonts
相關連結
Unicode Code Converter
http://rishida.net/scripts/uniview/conversion.php
http://space.flash8.net/space/?638324/action_viewspace_itemid_374138.html
字型使用 fireflyR16.pcf
fonts.dir
1
fireflyR16.pcf -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
要顯示firefly字型,需要作UTF-8 to ISO10646-1
也就是 UTF-8 to Unicode (UCS-2)
Microwindow 中相關的檔案
src/config
src/engine/devfont.c
src/engine/font_pcf.c
1.src/config
####################################################################
# PCF font support
# Selecting HAVE_PCFGZ_SUPPORT will allow you to directly read
# .pcf.gz files, but it will add libz to the size of the server
####################################################################
HAVE_PCF_SUPPORT = Y
HAVE_PCFGZ_SUPPORT = N
PCF_FONT_DIR = "/phone/lib/X11/fonts/misc"
不知道為何gziped pcf font在我的系統中讀到的資料是不正確的.
應該跟gzopen, gzread, gzseek, gzclose有關.所以不支援囉.
注意!!!PCF_FONT_DIR要正確設定到PCF字型所在的路徑
2.src/engine/devfont.c
關於轉碼的部份在
int GdConvertEncoding(const void *istr, MWTEXTFLAGS iflags, int cc, void *ostr,
MWTEXTFLAGS oflags)
看起來是有支援UTF-8 to Unicode, 實際上轉出來的碼是不正確的
3.src/engine/font_pcf.c
參考
http://tw.myblog.yahoo.com/stevegigijoe/article?mid=55&prev=56&next=54
4.UTF-8 to UCS-2
/* Set to 1 to turn bad UTF8 bytes into ISO-8859-1. If this is to zero
they are instead turned into the Unicode REPLACEMENT CHARACTER, of
value 0xfffd.
If this is on utf8decode will correctly map most (perhaps all)
human-readable text that is in ISO-8859-1. This may allow you
to completely ignore character sets in your code because virtually
everything is either ISO-8859-1 or UTF-8.
*/
#define ERRORS_TO_ISO8859_1 1
/* Set to 1 to turn bad UTF8 bytes in the 0x80-0x9f range into the
Unicode index for Microsoft's CP1252 character set. You should
also set ERRORS_TO_ISO8859_1. With this a huge amount of more
available text (such as all web pages) are correctly converted
to Unicode.
*/
#define ERRORS_TO_CP1252 1
/* A number of Unicode code points are in fact illegal and should not
be produced by a UTF-8 converter. Turn this on will replace the
bytes in those encodings with errors. If you do this then converting
arbitrary 16-bit data to UTF-8 and then back is not an identity,
which will probably break a lot of software.
*/
#define STRICT_RFC3629 0
#if ERRORS_TO_CP1252
// Codes 0x80..0x9f from the Microsoft CP1252 character set, translated
// to Unicode:
static unsigned short cp1252[32] = {
0x20ac, 0x0081, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021,
0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008d, 0x017d, 0x008f,
0x0090, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014,
0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x009d, 0x017e, 0x0178
};
#endif
/*! Decode a single UTF-8 encoded character starting at \e p. The
resulting Unicode value (in the range 0-0x10ffff) is returned,
and \e len is set the the number of bytes in the UTF-8 encoding
(adding \e len to \e p will point at the next character).
If \a p points at an illegal UTF-8 encoding, including one that
would go past \e end, or where a code is uses more bytes than
necessary, then *(unsigned char*)p is translated as though it is
in the Microsoft CP1252 character set and \e len is set to 1.
Treating errors this way allows this to decode almost any
ISO-8859-1 or CP1252 text that has been mistakenly placed where
UTF-8 is expected, and has proven very useful.
If you want errors to be converted to error characters (as the
standards recommend), adding a test to see if the length is
unexpectedly 1 will work:
\code
if (*p & 0x80) { // what should be a multibyte encoding
code = utf8decode(p,end,&len);
if (len<2) code = 0xFFFD; // Turn errors into REPLACEMENT CHARACTER
} else { // handle the 1-byte utf8 encoding:
code = *p;
len = 1;
}
\endcode
Direct testing for the 1-byte case (as shown above) will also
speed up the scanning of strings where the majority of characters
are ASCII.
*/
unsigned utf8decode(const char* p, const char* end, int* len)
{
unsigned char c = *(unsigned char*)p;
if (c < 0x80) {
*len = 1;
return c;
#if ERRORS_TO_CP1252
} else if (c < 0xa0) {
*len = 1;
return cp1252[c-0x80];
#endif
} else if (c < 0xc2) {
goto FAIL;
}
if (p+1 >= end || (p[1]&0xc0) != 0x80) goto FAIL;
if (c < 0xe0) {
*len = 2;
return
((p[0] & 0x1f) << 6) +
((p[1] & 0x3f));
} else if (c == 0xe0) {
if (((unsigned char*)p)[1] < 0xa0) goto FAIL;
goto UTF8_3;
#if STRICT_RFC3629
} else if (c == 0xed) {
// RFC 3629 says surrogate chars are illegal.
if (((unsigned char*)p)[1] >= 0xa0) goto FAIL;
goto UTF8_3;
} else if (c == 0xef) {
// 0xfffe and 0xffff are also illegal characters
if (((unsigned char*)p)[1]==0xbf &&
((unsigned char*)p)[2]>=0xbe) goto FAIL;
goto UTF8_3;
#endif
} else if (c < 0xf0) {
UTF8_3:
if (p+2 >= end || (p[2]&0xc0) != 0x80) goto FAIL;
*len = 3;
return
((p[0] & 0x0f) << 12) +
((p[1] & 0x3f) << 6) +
((p[2] & 0x3f));
} else if (c == 0xf0) {
if (((unsigned char*)p)[1] < 0x90) goto FAIL;
goto UTF8_4;
} else if (c < 0xf4) {
UTF8_4:
if (p+3 >= end || (p[2]&0xc0) != 0x80 || (p[3]&0xc0) != 0x80) goto FAIL;
*len = 4;
#if STRICT_RFC3629
// RFC 3629 says all codes ending in fffe or ffff are illegal:
if ((p[1]&0xf)==0xf &&
((unsigned char*)p)[2] == 0xbf &&
((unsigned char*)p)[3] >= 0xbe) goto FAIL;
#endif
return
((p[0] & 0x07) << 18) +
((p[1] & 0x3f) << 12) +
((p[2] & 0x3f) << 6) +
((p[3] & 0x3f));
} else if (c == 0xf4) {
if (((unsigned char*)p)[1] > 0x8f) goto FAIL; // after 0x10ffff
goto UTF8_4;
} else {
FAIL:
*len = 1;
#if ERRORS_TO_ISO8859_1
return c;
#else
return 0xfffd; // Unicode REPLACEMENT CHARACTER
#endif
}
}
typedef struct { /* normal 16 bit characters are two bytes */
unsigned char byte1;
unsigned char byte2;
} XChar2b;
////////////////////////////////////////////////////////////////
// Things you can do once the font+size has been selected:
// I see no sign of "FontSets" working. Instead this supposedly will
// draw the correct letters if you happen to pick an iso10646-1 font.
// This is similar to utf8towc() but works with the big-endian-only
// structure X seems to want, and does not bother with surrogate
// pairs. If all characters are 1 byte or errors it returns
// null. Otherwise it converts it to 16-bit and returns the allocated
// buffer and size:
static XChar2b* utf8to2b(const char* text, int n, int* charcount) {
static XChar2b* buffer = 0;
static int bufcount = 0;
const char* p = text;
const char* e = text+n;
int sawutf8 = 0;
int count = 0;
while (p < e) {
if (*(unsigned char*)p < 0x80) p++; // ascii
else if (*(unsigned char*)p < 0xa0) {sawutf8 = 1; p++;} //cp1252
else if (*(unsigned char*)p < 0xC2) p++; // other bad code
else {
int len; utf8decode(p,e,&len);
if (len > 1) sawutf8 = 1;
else if (!len) len = 1;
p += len;
}
count++;
}
if (!sawutf8) return 0;
*charcount = count;
if(bufcount < count) {
bufcount = count;
if(buffer)
free(buffer);
buffer = malloc(sizeof(XChar2b)*count);
} else if(buffer)
memset(buffer, 0, sizeof(XChar2b)*count);
count = 0;
p = text;
while (p < e) {
unsigned char c = *(unsigned char*)p;
if (c < 0xC2) { // ascii letter or bad code
buffer[count].byte1 = 0;
buffer[count].byte2 = c;
p++;
} else {
int len;
unsigned n = utf8decode(p,e,&len);
if (n > 0xffff) n = '?';
p += len;
buffer[count].byte1 = n>>8;
buffer[count].byte2 = n;
}
count++;
}
return buffer;
}
5.實際測試
int count = 0;
unsigned char buffer[512];
strcpy(buffer, "測試在Microwindow中顯示PCF字型");
XChar2b *uc16 = utf8to2b(buffer, strlen(buffer), &count);
GrText(main_wid, gc, 0, 0, uc16, count, GR_TFXCHAR2B|GR_TFBASELINE);
Unicode Code Converter
http://rishida.net/scripts/uniview/conversion.php
http://space.flash8.net/space/?638324/action_viewspace_itemid_374138.html
字型使用 fireflyR16.pcf
fonts.dir
1
fireflyR16.pcf -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
要顯示firefly字型,需要作UTF-8 to ISO10646-1
也就是 UTF-8 to Unicode (UCS-2)
Microwindow 中相關的檔案
src/config
src/engine/devfont.c
src/engine/font_pcf.c
1.src/config
####################################################################
# PCF font support
# Selecting HAVE_PCFGZ_SUPPORT will allow you to directly read
# .pcf.gz files, but it will add libz to the size of the server
####################################################################
HAVE_PCF_SUPPORT = Y
HAVE_PCFGZ_SUPPORT = N
PCF_FONT_DIR = "/phone/lib/X11/fonts/misc"
不知道為何gziped pcf font在我的系統中讀到的資料是不正確的.
應該跟gzopen, gzread, gzseek, gzclose有關.所以不支援囉.
注意!!!PCF_FONT_DIR要正確設定到PCF字型所在的路徑
2.src/engine/devfont.c
關於轉碼的部份在
int GdConvertEncoding(const void *istr, MWTEXTFLAGS iflags, int cc, void *ostr,
MWTEXTFLAGS oflags)
看起來是有支援UTF-8 to Unicode, 實際上轉出來的碼是不正確的
3.src/engine/font_pcf.c
參考
http://tw.myblog.yahoo.com/stevegigijoe/article?mid=55&prev=56&next=54
4.UTF-8 to UCS-2
/* Set to 1 to turn bad UTF8 bytes into ISO-8859-1. If this is to zero
they are instead turned into the Unicode REPLACEMENT CHARACTER, of
value 0xfffd.
If this is on utf8decode will correctly map most (perhaps all)
human-readable text that is in ISO-8859-1. This may allow you
to completely ignore character sets in your code because virtually
everything is either ISO-8859-1 or UTF-8.
*/
#define ERRORS_TO_ISO8859_1 1
/* Set to 1 to turn bad UTF8 bytes in the 0x80-0x9f range into the
Unicode index for Microsoft's CP1252 character set. You should
also set ERRORS_TO_ISO8859_1. With this a huge amount of more
available text (such as all web pages) are correctly converted
to Unicode.
*/
#define ERRORS_TO_CP1252 1
/* A number of Unicode code points are in fact illegal and should not
be produced by a UTF-8 converter. Turn this on will replace the
bytes in those encodings with errors. If you do this then converting
arbitrary 16-bit data to UTF-8 and then back is not an identity,
which will probably break a lot of software.
*/
#define STRICT_RFC3629 0
#if ERRORS_TO_CP1252
// Codes 0x80..0x9f from the Microsoft CP1252 character set, translated
// to Unicode:
static unsigned short cp1252[32] = {
0x20ac, 0x0081, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021,
0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008d, 0x017d, 0x008f,
0x0090, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014,
0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x009d, 0x017e, 0x0178
};
#endif
/*! Decode a single UTF-8 encoded character starting at \e p. The
resulting Unicode value (in the range 0-0x10ffff) is returned,
and \e len is set the the number of bytes in the UTF-8 encoding
(adding \e len to \e p will point at the next character).
If \a p points at an illegal UTF-8 encoding, including one that
would go past \e end, or where a code is uses more bytes than
necessary, then *(unsigned char*)p is translated as though it is
in the Microsoft CP1252 character set and \e len is set to 1.
Treating errors this way allows this to decode almost any
ISO-8859-1 or CP1252 text that has been mistakenly placed where
UTF-8 is expected, and has proven very useful.
If you want errors to be converted to error characters (as the
standards recommend), adding a test to see if the length is
unexpectedly 1 will work:
\code
if (*p & 0x80) { // what should be a multibyte encoding
code = utf8decode(p,end,&len);
if (len<2) code = 0xFFFD; // Turn errors into REPLACEMENT CHARACTER
} else { // handle the 1-byte utf8 encoding:
code = *p;
len = 1;
}
\endcode
Direct testing for the 1-byte case (as shown above) will also
speed up the scanning of strings where the majority of characters
are ASCII.
*/
unsigned utf8decode(const char* p, const char* end, int* len)
{
unsigned char c = *(unsigned char*)p;
if (c < 0x80) {
*len = 1;
return c;
#if ERRORS_TO_CP1252
} else if (c < 0xa0) {
*len = 1;
return cp1252[c-0x80];
#endif
} else if (c < 0xc2) {
goto FAIL;
}
if (p+1 >= end || (p[1]&0xc0) != 0x80) goto FAIL;
if (c < 0xe0) {
*len = 2;
return
((p[0] & 0x1f) << 6) +
((p[1] & 0x3f));
} else if (c == 0xe0) {
if (((unsigned char*)p)[1] < 0xa0) goto FAIL;
goto UTF8_3;
#if STRICT_RFC3629
} else if (c == 0xed) {
// RFC 3629 says surrogate chars are illegal.
if (((unsigned char*)p)[1] >= 0xa0) goto FAIL;
goto UTF8_3;
} else if (c == 0xef) {
// 0xfffe and 0xffff are also illegal characters
if (((unsigned char*)p)[1]==0xbf &&
((unsigned char*)p)[2]>=0xbe) goto FAIL;
goto UTF8_3;
#endif
} else if (c < 0xf0) {
UTF8_3:
if (p+2 >= end || (p[2]&0xc0) != 0x80) goto FAIL;
*len = 3;
return
((p[0] & 0x0f) << 12) +
((p[1] & 0x3f) << 6) +
((p[2] & 0x3f));
} else if (c == 0xf0) {
if (((unsigned char*)p)[1] < 0x90) goto FAIL;
goto UTF8_4;
} else if (c < 0xf4) {
UTF8_4:
if (p+3 >= end || (p[2]&0xc0) != 0x80 || (p[3]&0xc0) != 0x80) goto FAIL;
*len = 4;
#if STRICT_RFC3629
// RFC 3629 says all codes ending in fffe or ffff are illegal:
if ((p[1]&0xf)==0xf &&
((unsigned char*)p)[2] == 0xbf &&
((unsigned char*)p)[3] >= 0xbe) goto FAIL;
#endif
return
((p[0] & 0x07) << 18) +
((p[1] & 0x3f) << 12) +
((p[2] & 0x3f) << 6) +
((p[3] & 0x3f));
} else if (c == 0xf4) {
if (((unsigned char*)p)[1] > 0x8f) goto FAIL; // after 0x10ffff
goto UTF8_4;
} else {
FAIL:
*len = 1;
#if ERRORS_TO_ISO8859_1
return c;
#else
return 0xfffd; // Unicode REPLACEMENT CHARACTER
#endif
}
}
typedef struct { /* normal 16 bit characters are two bytes */
unsigned char byte1;
unsigned char byte2;
} XChar2b;
////////////////////////////////////////////////////////////////
// Things you can do once the font+size has been selected:
// I see no sign of "FontSets" working. Instead this supposedly will
// draw the correct letters if you happen to pick an iso10646-1 font.
// This is similar to utf8towc() but works with the big-endian-only
// structure X seems to want, and does not bother with surrogate
// pairs. If all characters are 1 byte or errors it returns
// null. Otherwise it converts it to 16-bit and returns the allocated
// buffer and size:
static XChar2b* utf8to2b(const char* text, int n, int* charcount) {
static XChar2b* buffer = 0;
static int bufcount = 0;
const char* p = text;
const char* e = text+n;
int sawutf8 = 0;
int count = 0;
while (p < e) {
if (*(unsigned char*)p < 0x80) p++; // ascii
else if (*(unsigned char*)p < 0xa0) {sawutf8 = 1; p++;} //cp1252
else if (*(unsigned char*)p < 0xC2) p++; // other bad code
else {
int len; utf8decode(p,e,&len);
if (len > 1) sawutf8 = 1;
else if (!len) len = 1;
p += len;
}
count++;
}
if (!sawutf8) return 0;
*charcount = count;
if(bufcount < count) {
bufcount = count;
if(buffer)
free(buffer);
buffer = malloc(sizeof(XChar2b)*count);
} else if(buffer)
memset(buffer, 0, sizeof(XChar2b)*count);
count = 0;
p = text;
while (p < e) {
unsigned char c = *(unsigned char*)p;
if (c < 0xC2) { // ascii letter or bad code
buffer[count].byte1 = 0;
buffer[count].byte2 = c;
p++;
} else {
int len;
unsigned n = utf8decode(p,e,&len);
if (n > 0xffff) n = '?';
p += len;
buffer[count].byte1 = n>>8;
buffer[count].byte2 = n;
}
count++;
}
return buffer;
}
5.實際測試
int count = 0;
unsigned char buffer[512];
strcpy(buffer, "測試在Microwindow中顯示PCF字型");
XChar2b *uc16 = utf8to2b(buffer, strlen(buffer), &count);
GrText(main_wid, gc, 0, 0, uc16, count, GR_TFXCHAR2B|GR_TFBASELINE);
2008年9月25日 星期四
k3b - avi to mpg
by selecting a format as one of the options (”vcd”, “svcd”, “dvd”, “dv”, “pal-vcd”, “ntsc-svcd”), all the format options (bitrate, codecs, buffer sizes) are then set automatically.
You can just type:
$ ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
#same example but use high quality, ntsc vcd format
$ ffmpeg -i myfile.avi -hq -target ntsc-vcd /tmp/vcd.mpg
#same example but dvd quality
$ ffmpeg -i myfile.avi -target ntsc-dvd /tmp/dvd.mpg
#same example use same quality as source
$ ffmpeg -1 myfile.avi -sameq -target vcd /tmp/vcd.mpg
#converting a file for VCD format using a and b frames for MPEG 2
$ ffmpeg -i myfile.avi -target ntsc-vcd -bf 2 /home/user/Video/vcd.mpg
#same conversion, but start at 0 seconds and convert only first 45 minutes
#use -ss for start position and -t for duration
$ ffmpeg -i myfile.avi -target ntsc-vcd -bf 2 -ss 00:00:00 -t 00:45:00 /home/user/Video/vcd.mpg
then you can use K3b to burn it to VCD or DVD.
source: http://www.smorgasbord.net/conve ... fmpeg-and-mencoder/
You can just type:
$ ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg
#same example but use high quality, ntsc vcd format
$ ffmpeg -i myfile.avi -hq -target ntsc-vcd /tmp/vcd.mpg
#same example but dvd quality
$ ffmpeg -i myfile.avi -target ntsc-dvd /tmp/dvd.mpg
#same example use same quality as source
$ ffmpeg -1 myfile.avi -sameq -target vcd /tmp/vcd.mpg
#converting a file for VCD format using a and b frames for MPEG 2
$ ffmpeg -i myfile.avi -target ntsc-vcd -bf 2 /home/user/Video/vcd.mpg
#same conversion, but start at 0 seconds and convert only first 45 minutes
#use -ss for start position and -t for duration
$ ffmpeg -i myfile.avi -target ntsc-vcd -bf 2 -ss 00:00:00 -t 00:45:00 /home/user/Video/vcd.mpg
then you can use K3b to burn it to VCD or DVD.
source: http://www.smorgasbord.net/conve ... fmpeg-and-mencoder/
2008年3月21日 星期五
Get IP address / Netmask / Broadcast C code
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <ifaddrs.h>
#include <string.h>
int printLocalIps()
{
struct ifaddrs *ifa = NULL, *ifp = NULL;
if (getifaddrs (&ifp) < 0)
{
perror ("getifaddrs");
return 1;
}
for (ifa = ifp; ifa; ifa = ifa->ifa_next)
{
char ip[NI_MAXHOST];
socklen_t salen;
if (ifa->ifa_addr->sa_family == AF_INET) {
struct sockaddr_in *sin = (struct sockaddr_in *)(ifa->ifa_addr);
salen = sizeof (struct sockaddr_in);
/*printf("%s : %s\n", ifa->ifa_name, inet_ntoa(sin->sin_addr)); */
} else if (ifa->ifa_addr->sa_family == AF_INET6)
/*salen = sizeof (struct sockaddr_in6);*/
continue;
else
continue;
printf("<---------->\n");
printf("%s :\n", ifa->ifa_name);
if (getnameinfo (ifa->ifa_addr, salen,
ip, sizeof (ip), NULL, 0, NI_NUMERICHOST) < 0)
{
perror ("getnameinfo");
continue;
}
printf ("IP : %s\n", ip);
if (getnameinfo (ifa->ifa_netmask, salen,
ip, sizeof (ip), NULL, 0, NI_NUMERICHOST) < 0)
{
perror ("getnameinfo");
continue;
}
printf ("Netmask : %s\n", ip);
if (getnameinfo (ifa->ifa_broadaddr, salen,
ip, sizeof (ip), NULL, 0, NI_NUMERICHOST) < 0)
{
perror ("getnameinfo");
continue;
}
printf ("Broadcast : %s\n", ip);
}
freeifaddrs (ifp);
return 0;
}
int main(int argc, char **argv)
{
printLocalIps();
}
Result :
<---------->
lo :
IP : 127.0.0.1
Netmask : 255.0.0.0
Broadcast : 127.0.0.1
<---------->
eth0 :
IP : 192.168.168.67
Netmask : 255.255.255.0
Broadcast : 192.168.168.255
2008年3月10日 星期一
PHP + thttpd + MySQL
MySQL 5.0.18
CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --host=i386-linux --target=i386-linux --prefix=/opt/mysql-5.0.18 --disable-shared --enable-static --without-debug --enable-assembler --with-pthread --without-docs --without-man --without-bench --without-innodb --program-prefix= --cache-file=/dev/null
Fix clinet/Makefile -->> LDFLAGS = -s -static
make
make install
php-4.3.10
CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --enable-static --build=i386-linux --host=i386-linux --with-thttpd=../thttpd-2.21b --with-mysql=/opt/mysql-5.0.18 --with-config-file-path=/opt/thttpd-2.21b/lib --prefix=/opt/php-4.3.10 --enable-memory-limit --disable-debug --without-gd --enable-sysvshm --cache-file=/dev/null
make
make install
cd thttpd-2.21b
CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --host=i386-linux --target=i386-linux --prefix=/opt/thttpd-2.21b --cache-file=/dev/null
make
make install
CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --host=i386-linux --target=i386-linux --prefix=/opt/mysql-5.0.18 --disable-shared --enable-static --without-debug --enable-assembler --with-pthread --without-docs --without-man --without-bench --without-innodb --program-prefix= --cache-file=/dev/null
Fix clinet/Makefile -->> LDFLAGS = -s -static
make
make install
php-4.3.10
CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --enable-static --build=i386-linux --host=i386-linux --with-thttpd=../thttpd-2.21b --with-mysql=/opt/mysql-5.0.18 --with-config-file-path=/opt/thttpd-2.21b/lib --prefix=/opt/php-4.3.10 --enable-memory-limit --disable-debug --without-gd --enable-sysvshm --cache-file=/dev/null
make
make install
cd thttpd-2.21b
CC=i386-linux-gcc CXX=i386-linux-g++ AR=i386-linux-ar ./configure --host=i386-linux --target=i386-linux --prefix=/opt/thttpd-2.21b --cache-file=/dev/null
make
make install
2008年1月28日 星期一
FLTK-utf8 中文顯示 by gziped pcf fonts
1.Requirement
nano-X support GZIP PCF fonts
字型可用firefly
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR11.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR12.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR13.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR14.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR15.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR16.pcf.gz
在PC上產生fonts.dir在加以修改
[gigijoe@localhost fonts]$ ls
fireflyR13.pcf.gz fireflyR16.pcf.gz
[gigijoe@localhost fonts]$ mkfontdir
[gigijoe@localhost fonts]$ cat fonts.dir
2
fireflyR13.pcf.gz -firefly-firefly new sung-medium-r-normal--13-120-75-75-p-129-iso10646-1
fireflyR16.pcf.gz -firefly-firefly new sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
修改成
[gigijoe@localhost fonts]$ cat fonts.dir
2
fireflyR13.pcf.gz -firefly-sung-medium-r-normal--13-120-75-75-p-129-iso10646-1
fireflyR16.pcf.gz -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
修改 x11/Font_xlfd.cxx
////////////////////////////////////////////////////////////////
// The predefined fonts that fltk has:
static IFont fonts [] = {
{{"helvetica",0}, "-*-helvetica-medium-r-normal--*", fonts+1, fonts+2},
{{"helvetica",1}, "-*-helvetica-bold-r-normal--*", fonts+1, fonts+3},
{{"helvetica",2}, "-*-helvetica-medium-o-normal--*", fonts+3, fonts+2},
{{"helvetica",3}, "-*-helvetica-bold-o-normal--*", fonts+3, fonts+3},
{{"courier", 0}, "-*-courier-medium-r-normal--*", fonts+5, fonts+6},
{{"courier", 1}, "-*-courier-bold-r-normal--*", fonts+5, fonts+7},
{{"courier", 2}, "-*-courier-medium-o-normal--*", fonts+7, fonts+6},
{{"courier", 3}, "-*-courier-bold-o-normal--*", fonts+7, fonts+7},
{{"times", 0}, "-*-times-medium-r-normal--*", fonts+9, fonts+10},
{{"times", 1}, "-*-times-bold-r-normal--*", fonts+9, fonts+11},
{{"times", 2}, "-*-times-medium-i-normal--*", fonts+11,fonts+10},
{{"times", 3}, "-*-times-bold-i-normal--*", fonts+11,fonts+11},
{{"symbol", 0}, "-*-symbol-*", fonts+12,fonts+12},
{{"lucidatypewriter", 0}, "-*-lucidatypewriter-medium-r-normal-sans-*", fonts+14,fonts+14},
{{"lucidatypewriter", 1}, "-*-lucidatypewriter-bold-r-normal-sans-*", fonts+14,fonts+14},
{{"zapf dingbats", 0}, "-*-*zapf dingbats-*", fonts+15,fonts+15},
{{"sung", 0}, "-*-sung-medium-*-*--*", fonts+16,fonts+16},
};
fltk::Font* const fltk::HELVETICA = &(fonts[0].f);
fltk::Font* const fltk::HELVETICA_BOLD = &(fonts[1].f);
fltk::Font* const fltk::HELVETICA_ITALIC = &(fonts[2].f);
fltk::Font* const fltk::HELVETICA_BOLD_ITALIC = &(fonts[3].f);
fltk::Font* const fltk::COURIER = &(fonts[4].f);
fltk::Font* const fltk::COURIER_BOLD = &(fonts[5].f);
fltk::Font* const fltk::COURIER_ITALIC = &(fonts[6].f);
fltk::Font* const fltk::COURIER_BOLD_ITALIC = &(fonts[7].f);
fltk::Font* const fltk::TIMES = &(fonts[8].f);
fltk::Font* const fltk::TIMES_BOLD = &(fonts[9].f);
fltk::Font* const fltk::TIMES_ITALIC = &(fonts[10].f);
fltk::Font* const fltk::TIMES_BOLD_ITALIC = &(fonts[11].f);
fltk::Font* const fltk::SYMBOL_FONT = &(fonts[12].f);
fltk::Font* const fltk::SCREEN_FONT = &(fonts[13].f);
fltk::Font* const fltk::SCREEN_BOLD_FONT = &(fonts[14].f);
fltk::Font* const fltk::ZAPF_DINGBATS = &(fonts[15].f);
fltk::Font* const fltk::SUNG = &(fonts[16].f);
/*! For back-compatabilty with FLTK1, this turns an integer into one
of the built-in fonts. 0 = HELVETICA. */
fltk::Font* fltk::font(int i) {return &(fonts[i%16].f);}
修改 src/Style.cxx
// Do not change the contents of this ever. The themes depend on getting
// a known state initially. Make sure the documentation below matches the
// default values!
static void revert(Style* s) {
s->parent_ = 0; // this is the topmost style always
s->box_ = DOWN_BOX;
s->buttonbox_ = UP_BOX;
s->glyph_ = Widget::default_glyph;
s->labelfont_ = SUNG;
s->textfont_ = SUNG;
s->labeltype_ = NORMAL_LABEL;
s->color_ = WHITE; // GRAY99?
s->textcolor_ = BLACK;
s->selection_color_ = WINDOWS_BLUE;
s->selection_textcolor_= WHITE;
s->buttoncolor_ = GRAY75;
s->labelcolor_ = BLACK;
s->highlight_color_ = NO_COLOR;
s->highlight_textcolor_= NO_COLOR;
s->labelsize_ = 12;
s->textsize_ = 12;
s->leading_ = 2;
s->scrollbar_width_ = 15;
s->scrollbar_align_ = ALIGN_RIGHT|ALIGN_BOTTOM;
}
修改 fltk/Style.h
struct Font;
extern FL_API Font* const HELVETICA;
extern FL_API Font* const HELVETICA_BOLD;
extern FL_API Font* const HELVETICA_ITALIC;
extern FL_API Font* const HELVETICA_BOLD_ITALIC;
extern FL_API Font* const COURIER;
extern FL_API Font* const COURIER_BOLD;
extern FL_API Font* const COURIER_ITALIC;
extern FL_API Font* const COURIER_BOLD_ITALIC;
extern FL_API Font* const TIMES;
extern FL_API Font* const TIMES_BOLD;
extern FL_API Font* const TIMES_ITALIC;
extern FL_API Font* const TIMES_BOLD_ITALIC;
extern FL_API Font* const SYMBOL_FONT;
extern FL_API Font* const SCREEN_FONT;
extern FL_API Font* const SCREEN_BOLD_FONT;
extern FL_API Font* const ZAPF_DINGBATS;
extern FL_API Font* const SUNG;
patch
轉載
http://tw.myblog.yahoo.com/jw!GdTvlQ.YCR8E9rpahh6eqfZX9g--/article?mid=163&prev=164&next=149&l=f&fid=17
--- microwindows-0.91-old/src/engine/font_pcf.c 2003-06-16 11:20:09.000000000 +0800
+++ microwindows-0.91-new/src/engine/font_pcf.c 2008-01-10 14:28:37.000000000 +0800
@@ -245,6 +245,37 @@
return dwswap(n);
}
+/* read a 16-bit integer MSB16 format*/
+static unsigned short
+readMSB16(FILEP file)
+{
+ unsigned short s;
+
+ FREAD(file, &s, sizeof(s));
+#if !MW_CPU_BIG_ENDIAN
+ return ((((s) << 8) & 0xff00) | (((s) >> 8) & 0x00ff));
+#else
+ return s;
+#endif
+}
+
+/* read a 32-bit integer MSB32 format*/
+static unsigned long
+readMSB32(FILEP file)
+{
+ unsigned long n;
+
+ FREAD(file, &n, sizeof(n));
+#if !MW_CPU_BIG_ENDIAN
+ return ((((n) << 24) & 0xff000000L) | \
+ (((n) << 8) & 0x00ff0000L) | \
+ (((n) >> 8) & 0x0000ff00L) | \
+ (((n) >> 24) & 0x000000ffL) );
+#else
+ return n;
+#endif
+}
+
/* Get the offset of the given field */
static int
pcf_get_offset(int item)
@@ -272,21 +303,26 @@
struct prop_entry *p;
unsigned char *string_buffer, *spos;
+ unsigned long (*read32)(FILEP);
if ((offset = pcf_get_offset(PCF_PROPERTIES)) == -1)
return (-1);
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
- num_props = readLSB32(file);
+ if (format & PCF_BIT_MASK)
+ read32 = readMSB32;
+ else
+ read32 = readLSB32;
+ num_props = read32(file);
p = *prop = (struct prop_entry *) malloc(num_props *
sizeof(struct prop_entry));
for (i = 0; i < num_props; i++) {
- p[i].name = readLSB32(file);
+ p[i].name = read32(file);
p[i].is_string = readINT8(file);
- p[i].value = readLSB32(file);
+ p[i].value = read32(file);
}
/* Pad to 32 bit multiples */
@@ -295,7 +331,7 @@
/* Read the entire set of strings into memory */
- ssize = readLSB32(file);
+ ssize = read32(file);
spos = string_buffer = (unsigned char *) ALLOCA(ssize);
FREAD(file, string_buffer, ssize);
@@ -333,6 +369,7 @@
unsigned long *o;
unsigned char *b;
unsigned long bmsize[GLYPHPADOPTIONS];
+ unsigned long (*read32)(FILEP);
if ((offset = pcf_get_offset(PCF_BITMAPS)) == -1)
return -1;
@@ -340,15 +377,18 @@
format = readLSB32(file);
endian = (format & PCF_BIT_MASK)? PCF_LSB_FIRST: PCF_MSB_FIRST;
-
- num_glyphs = readLSB32(file);
+ if (endian == PCF_LSB_FIRST)
+ read32 = readMSB32;
+ else
+ read32 = readLSB32;
+ num_glyphs = read32(file);
o = *offsets = (unsigned long *)malloc(num_glyphs * sizeof(unsigned long));
for (i=0; i < num_glyphs; ++i)
- o[i] = readLSB32(file);
+ o[i] = read32(file);
for (i=0; i < GLYPHPADOPTIONS; ++i)
- bmsize[i] = readLSB32(file);
+ bmsize[i] = read32(file);
pad = format & PCF_GLYPH_PAD_MASK;
*bits_size = bmsize[pad]? bmsize[pad] : 1;
@@ -358,14 +398,9 @@
FREAD(file, b, *bits_size);
/* convert bitmaps*/
- bit_order_invert(b, *bits_size);
-#if MW_CPU_BIG_ENDIAN
- if (endian == PCF_LSB_FIRST)
- two_byte_swap(b, *bits_size);
-#else
if (endian == PCF_MSB_FIRST)
- two_byte_swap(b, *bits_size);
-#endif
+ bit_order_invert(b, *bits_size);
+ two_byte_swap(b, *bits_size);
return num_glyphs;
}
@@ -376,29 +411,39 @@
long i, size, offset;
unsigned long format;
struct metric_entry *m;
+ unsigned long (*read32)(FILEP);
+ unsigned short (*read16)(FILEP);
if ((offset = pcf_get_offset(PCF_METRICS)) == -1)
return -1;
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
+ if (format & PCF_BIT_MASK) {
+ read16 = readMSB16;
+ read32 = readMSB32;
+ }
+ else {
+ read16 = readLSB16;
+ read32 = readLSB32;
+ }
if ((format & PCF_FORMAT_MASK) == PCF_DEFAULT_FORMAT) {
- size = readLSB32(file); /* 32 bits - Number of metrics*/
+ size = read32(file); /* 32 bits - Number of metrics*/
m = *metrics = (struct metric_entry *) malloc(size *
sizeof(struct metric_entry));
for (i=0; i < size; i++) {
- m[i].leftBearing = readLSB16(file);
- m[i].rightBearing = readLSB16(file);
- m[i].width = readLSB16(file);
- m[i].ascent = readLSB16(file);
- m[i].descent = readLSB16(file);
- m[i].attributes = readLSB16(file);
+ m[i].leftBearing = read16(file);
+ m[i].rightBearing = read16(file);
+ m[i].width = read16(file);
+ m[i].ascent = read16(file);
+ m[i].descent = read16(file);
+ m[i].attributes = read16(file);
}
} else {
- size = readLSB16(file); /* 16 bits - Number of metrics*/
+ size = read16(file); /* 16 bits - Number of metrics*/
m = *metrics = (struct metric_entry *) malloc(size *
sizeof(struct metric_entry));
@@ -421,30 +466,35 @@
long offset, n;
unsigned long format;
struct encoding_entry *e;
+ unsigned short (*read16)(FILEP);
if ((offset = pcf_get_offset(PCF_BDF_ENCODINGS)) == -1)
return -1;
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
+ if (format & PCF_BIT_MASK)
+ read16 = readMSB16;
+ else
+ read16 = readLSB16;
e = *encoding = (struct encoding_entry *)
malloc(sizeof(struct encoding_entry));
- e->min_byte2 = readLSB16(file);
- e->max_byte2 = readLSB16(file);
- e->min_byte1 = readLSB16(file);
- e->max_byte1 = readLSB16(file);
- e->defaultchar = readLSB16(file);
+ e->min_byte2 = read16(file);
+ e->max_byte2 = read16(file);
+ e->min_byte1 = read16(file);
+ e->max_byte1 = read16(file);
+ e->defaultchar = read16(file);
e->count = (e->max_byte2 - e->min_byte2 + 1) *
(e->max_byte1 - e->min_byte1 + 1);
e->map = (unsigned short *) malloc(e->count * sizeof(unsigned short));
DPRINTF("def char %d (%x)\n", e->defaultchar, e->defaultchar);
for (n = 0; n < e->count; ++n) {
- e->map[n] = readLSB16(file);
+ e->map[n] = read16(file);
/*DPRINTF("ncode %x (%c) %x\n", n, n, e->map[n]);*/
}
- DPRINTF("size %d byte1 %d,%d byte2 %d,%d\n", e->count,
+ DPRINTF("size %ld byte1 %d,%d byte2 %d,%d\n", e->count,
e->min_byte1, e->max_byte1, e->min_byte2, e->max_byte2);
return e->count;
}
2.Compile procdure as FLTK
3.修改 test/utf8.cxx
//"-*-fixed-*-*-*--*-*-*-*-*-*-gost19768.74-*,"
"-*-fixed-*-iso10646-1"*/
/*"-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1"*/ <<-- Mark這行
"-*-sung-medium-*-*--*-*-*-*-*-*-iso10646-1" <<-- 加入這行,這樣才會認得firefly字型
#if 0
xchar arabic1[] ={/*8238,*/ 1610, 0x20, 1608, 0x20, 1606, 0x20, 1616, 0x20, 1603, 0x20, 1608, 0x20, 1583, 0};
l = fl_unicode2utf(arabic1, 14, abuf);
abuf[l] = 0;
#endif
strcpy(abuf, "中華電信");
4.run utf8
nano-X support GZIP PCF fonts
字型可用firefly
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR11.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR12.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR13.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR14.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR15.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR16.pcf.gz
在PC上產生fonts.dir在加以修改
[gigijoe@localhost fonts]$ ls
fireflyR13.pcf.gz fireflyR16.pcf.gz
[gigijoe@localhost fonts]$ mkfontdir
[gigijoe@localhost fonts]$ cat fonts.dir
2
fireflyR13.pcf.gz -firefly-firefly new sung-medium-r-normal--13-120-75-75-p-129-iso10646-1
fireflyR16.pcf.gz -firefly-firefly new sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
修改成
[gigijoe@localhost fonts]$ cat fonts.dir
2
fireflyR13.pcf.gz -firefly-sung-medium-r-normal--13-120-75-75-p-129-iso10646-1
fireflyR16.pcf.gz -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
修改 x11/Font_xlfd.cxx
////////////////////////////////////////////////////////////////
// The predefined fonts that fltk has:
static IFont fonts [] = {
{{"helvetica",0}, "-*-helvetica-medium-r-normal--*", fonts+1, fonts+2},
{{"helvetica",1}, "-*-helvetica-bold-r-normal--*", fonts+1, fonts+3},
{{"helvetica",2}, "-*-helvetica-medium-o-normal--*", fonts+3, fonts+2},
{{"helvetica",3}, "-*-helvetica-bold-o-normal--*", fonts+3, fonts+3},
{{"courier", 0}, "-*-courier-medium-r-normal--*", fonts+5, fonts+6},
{{"courier", 1}, "-*-courier-bold-r-normal--*", fonts+5, fonts+7},
{{"courier", 2}, "-*-courier-medium-o-normal--*", fonts+7, fonts+6},
{{"courier", 3}, "-*-courier-bold-o-normal--*", fonts+7, fonts+7},
{{"times", 0}, "-*-times-medium-r-normal--*", fonts+9, fonts+10},
{{"times", 1}, "-*-times-bold-r-normal--*", fonts+9, fonts+11},
{{"times", 2}, "-*-times-medium-i-normal--*", fonts+11,fonts+10},
{{"times", 3}, "-*-times-bold-i-normal--*", fonts+11,fonts+11},
{{"symbol", 0}, "-*-symbol-*", fonts+12,fonts+12},
{{"lucidatypewriter", 0}, "-*-lucidatypewriter-medium-r-normal-sans-*", fonts+14,fonts+14},
{{"lucidatypewriter", 1}, "-*-lucidatypewriter-bold-r-normal-sans-*", fonts+14,fonts+14},
{{"zapf dingbats", 0}, "-*-*zapf dingbats-*", fonts+15,fonts+15},
{{"sung", 0}, "-*-sung-medium-*-*--*", fonts+16,fonts+16},
};
fltk::Font* const fltk::HELVETICA = &(fonts[0].f);
fltk::Font* const fltk::HELVETICA_BOLD = &(fonts[1].f);
fltk::Font* const fltk::HELVETICA_ITALIC = &(fonts[2].f);
fltk::Font* const fltk::HELVETICA_BOLD_ITALIC = &(fonts[3].f);
fltk::Font* const fltk::COURIER = &(fonts[4].f);
fltk::Font* const fltk::COURIER_BOLD = &(fonts[5].f);
fltk::Font* const fltk::COURIER_ITALIC = &(fonts[6].f);
fltk::Font* const fltk::COURIER_BOLD_ITALIC = &(fonts[7].f);
fltk::Font* const fltk::TIMES = &(fonts[8].f);
fltk::Font* const fltk::TIMES_BOLD = &(fonts[9].f);
fltk::Font* const fltk::TIMES_ITALIC = &(fonts[10].f);
fltk::Font* const fltk::TIMES_BOLD_ITALIC = &(fonts[11].f);
fltk::Font* const fltk::SYMBOL_FONT = &(fonts[12].f);
fltk::Font* const fltk::SCREEN_FONT = &(fonts[13].f);
fltk::Font* const fltk::SCREEN_BOLD_FONT = &(fonts[14].f);
fltk::Font* const fltk::ZAPF_DINGBATS = &(fonts[15].f);
fltk::Font* const fltk::SUNG = &(fonts[16].f);
/*! For back-compatabilty with FLTK1, this turns an integer into one
of the built-in fonts. 0 = HELVETICA. */
fltk::Font* fltk::font(int i) {return &(fonts[i%16].f);}
修改 src/Style.cxx
// Do not change the contents of this ever. The themes depend on getting
// a known state initially. Make sure the documentation below matches the
// default values!
static void revert(Style* s) {
s->parent_ = 0; // this is the topmost style always
s->box_ = DOWN_BOX;
s->buttonbox_ = UP_BOX;
s->glyph_ = Widget::default_glyph;
s->labelfont_ = SUNG;
s->textfont_ = SUNG;
s->labeltype_ = NORMAL_LABEL;
s->color_ = WHITE; // GRAY99?
s->textcolor_ = BLACK;
s->selection_color_ = WINDOWS_BLUE;
s->selection_textcolor_= WHITE;
s->buttoncolor_ = GRAY75;
s->labelcolor_ = BLACK;
s->highlight_color_ = NO_COLOR;
s->highlight_textcolor_= NO_COLOR;
s->labelsize_ = 12;
s->textsize_ = 12;
s->leading_ = 2;
s->scrollbar_width_ = 15;
s->scrollbar_align_ = ALIGN_RIGHT|ALIGN_BOTTOM;
}
修改 fltk/Style.h
struct Font;
extern FL_API Font* const HELVETICA;
extern FL_API Font* const HELVETICA_BOLD;
extern FL_API Font* const HELVETICA_ITALIC;
extern FL_API Font* const HELVETICA_BOLD_ITALIC;
extern FL_API Font* const COURIER;
extern FL_API Font* const COURIER_BOLD;
extern FL_API Font* const COURIER_ITALIC;
extern FL_API Font* const COURIER_BOLD_ITALIC;
extern FL_API Font* const TIMES;
extern FL_API Font* const TIMES_BOLD;
extern FL_API Font* const TIMES_ITALIC;
extern FL_API Font* const TIMES_BOLD_ITALIC;
extern FL_API Font* const SYMBOL_FONT;
extern FL_API Font* const SCREEN_FONT;
extern FL_API Font* const SCREEN_BOLD_FONT;
extern FL_API Font* const ZAPF_DINGBATS;
extern FL_API Font* const SUNG;
patch
轉載
http://tw.myblog.yahoo.com/jw!GdTvlQ.YCR8E9rpahh6eqfZX9g--/article?mid=163&prev=164&next=149&l=f&fid=17
--- microwindows-0.91-old/src/engine/font_pcf.c 2003-06-16 11:20:09.000000000 +0800
+++ microwindows-0.91-new/src/engine/font_pcf.c 2008-01-10 14:28:37.000000000 +0800
@@ -245,6 +245,37 @@
return dwswap(n);
}
+/* read a 16-bit integer MSB16 format*/
+static unsigned short
+readMSB16(FILEP file)
+{
+ unsigned short s;
+
+ FREAD(file, &s, sizeof(s));
+#if !MW_CPU_BIG_ENDIAN
+ return ((((s) << 8) & 0xff00) | (((s) >> 8) & 0x00ff));
+#else
+ return s;
+#endif
+}
+
+/* read a 32-bit integer MSB32 format*/
+static unsigned long
+readMSB32(FILEP file)
+{
+ unsigned long n;
+
+ FREAD(file, &n, sizeof(n));
+#if !MW_CPU_BIG_ENDIAN
+ return ((((n) << 24) & 0xff000000L) | \
+ (((n) << 8) & 0x00ff0000L) | \
+ (((n) >> 8) & 0x0000ff00L) | \
+ (((n) >> 24) & 0x000000ffL) );
+#else
+ return n;
+#endif
+}
+
/* Get the offset of the given field */
static int
pcf_get_offset(int item)
@@ -272,21 +303,26 @@
struct prop_entry *p;
unsigned char *string_buffer, *spos;
+ unsigned long (*read32)(FILEP);
if ((offset = pcf_get_offset(PCF_PROPERTIES)) == -1)
return (-1);
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
- num_props = readLSB32(file);
+ if (format & PCF_BIT_MASK)
+ read32 = readMSB32;
+ else
+ read32 = readLSB32;
+ num_props = read32(file);
p = *prop = (struct prop_entry *) malloc(num_props *
sizeof(struct prop_entry));
for (i = 0; i < num_props; i++) {
- p[i].name = readLSB32(file);
+ p[i].name = read32(file);
p[i].is_string = readINT8(file);
- p[i].value = readLSB32(file);
+ p[i].value = read32(file);
}
/* Pad to 32 bit multiples */
@@ -295,7 +331,7 @@
/* Read the entire set of strings into memory */
- ssize = readLSB32(file);
+ ssize = read32(file);
spos = string_buffer = (unsigned char *) ALLOCA(ssize);
FREAD(file, string_buffer, ssize);
@@ -333,6 +369,7 @@
unsigned long *o;
unsigned char *b;
unsigned long bmsize[GLYPHPADOPTIONS];
+ unsigned long (*read32)(FILEP);
if ((offset = pcf_get_offset(PCF_BITMAPS)) == -1)
return -1;
@@ -340,15 +377,18 @@
format = readLSB32(file);
endian = (format & PCF_BIT_MASK)? PCF_LSB_FIRST: PCF_MSB_FIRST;
-
- num_glyphs = readLSB32(file);
+ if (endian == PCF_LSB_FIRST)
+ read32 = readMSB32;
+ else
+ read32 = readLSB32;
+ num_glyphs = read32(file);
o = *offsets = (unsigned long *)malloc(num_glyphs * sizeof(unsigned long));
for (i=0; i < num_glyphs; ++i)
- o[i] = readLSB32(file);
+ o[i] = read32(file);
for (i=0; i < GLYPHPADOPTIONS; ++i)
- bmsize[i] = readLSB32(file);
+ bmsize[i] = read32(file);
pad = format & PCF_GLYPH_PAD_MASK;
*bits_size = bmsize[pad]? bmsize[pad] : 1;
@@ -358,14 +398,9 @@
FREAD(file, b, *bits_size);
/* convert bitmaps*/
- bit_order_invert(b, *bits_size);
-#if MW_CPU_BIG_ENDIAN
- if (endian == PCF_LSB_FIRST)
- two_byte_swap(b, *bits_size);
-#else
if (endian == PCF_MSB_FIRST)
- two_byte_swap(b, *bits_size);
-#endif
+ bit_order_invert(b, *bits_size);
+ two_byte_swap(b, *bits_size);
return num_glyphs;
}
@@ -376,29 +411,39 @@
long i, size, offset;
unsigned long format;
struct metric_entry *m;
+ unsigned long (*read32)(FILEP);
+ unsigned short (*read16)(FILEP);
if ((offset = pcf_get_offset(PCF_METRICS)) == -1)
return -1;
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
+ if (format & PCF_BIT_MASK) {
+ read16 = readMSB16;
+ read32 = readMSB32;
+ }
+ else {
+ read16 = readLSB16;
+ read32 = readLSB32;
+ }
if ((format & PCF_FORMAT_MASK) == PCF_DEFAULT_FORMAT) {
- size = readLSB32(file); /* 32 bits - Number of metrics*/
+ size = read32(file); /* 32 bits - Number of metrics*/
m = *metrics = (struct metric_entry *) malloc(size *
sizeof(struct metric_entry));
for (i=0; i < size; i++) {
- m[i].leftBearing = readLSB16(file);
- m[i].rightBearing = readLSB16(file);
- m[i].width = readLSB16(file);
- m[i].ascent = readLSB16(file);
- m[i].descent = readLSB16(file);
- m[i].attributes = readLSB16(file);
+ m[i].leftBearing = read16(file);
+ m[i].rightBearing = read16(file);
+ m[i].width = read16(file);
+ m[i].ascent = read16(file);
+ m[i].descent = read16(file);
+ m[i].attributes = read16(file);
}
} else {
- size = readLSB16(file); /* 16 bits - Number of metrics*/
+ size = read16(file); /* 16 bits - Number of metrics*/
m = *metrics = (struct metric_entry *) malloc(size *
sizeof(struct metric_entry));
@@ -421,30 +466,35 @@
long offset, n;
unsigned long format;
struct encoding_entry *e;
+ unsigned short (*read16)(FILEP);
if ((offset = pcf_get_offset(PCF_BDF_ENCODINGS)) == -1)
return -1;
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
+ if (format & PCF_BIT_MASK)
+ read16 = readMSB16;
+ else
+ read16 = readLSB16;
e = *encoding = (struct encoding_entry *)
malloc(sizeof(struct encoding_entry));
- e->min_byte2 = readLSB16(file);
- e->max_byte2 = readLSB16(file);
- e->min_byte1 = readLSB16(file);
- e->max_byte1 = readLSB16(file);
- e->defaultchar = readLSB16(file);
+ e->min_byte2 = read16(file);
+ e->max_byte2 = read16(file);
+ e->min_byte1 = read16(file);
+ e->max_byte1 = read16(file);
+ e->defaultchar = read16(file);
e->count = (e->max_byte2 - e->min_byte2 + 1) *
(e->max_byte1 - e->min_byte1 + 1);
e->map = (unsigned short *) malloc(e->count * sizeof(unsigned short));
DPRINTF("def char %d (%x)\n", e->defaultchar, e->defaultchar);
for (n = 0; n < e->count; ++n) {
- e->map[n] = readLSB16(file);
+ e->map[n] = read16(file);
/*DPRINTF("ncode %x (%c) %x\n", n, n, e->map[n]);*/
}
- DPRINTF("size %d byte1 %d,%d byte2 %d,%d\n", e->count,
+ DPRINTF("size %ld byte1 %d,%d byte2 %d,%d\n", e->count,
e->min_byte1, e->max_byte1, e->min_byte2, e->max_byte2);
return e->count;
}
2.Compile procdure as FLTK
3.修改 test/utf8.cxx
//"-*-fixed-*-*-*--*-*-*-*-*-*-gost19768.74-*,"
"-*-fixed-*-iso10646-1"*/
/*"-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1"*/ <<-- Mark這行
"-*-sung-medium-*-*--*-*-*-*-*-*-iso10646-1" <<-- 加入這行,這樣才會認得firefly字型
#if 0
xchar arabic1[] ={/*8238,*/ 1610, 0x20, 1608, 0x20, 1606, 0x20, 1616, 0x20, 1603, 0x20, 1608, 0x20, 1583, 0};
l = fl_unicode2utf(arabic1, 14, abuf);
abuf[l] = 0;
#endif
strcpy(abuf, "中華電信");
4.run utf8
2008年1月15日 星期二
Build nxlib-0.45
1.Modify Makefile
MWIN=../microwindows-0.91/src
X11_INCLUDE=$(X11)/include
CC = mipsel-linux-gcc
CFLAGS += -G 0 -Wall $(DEBUG) -I$(MWIN_INCLUDE) -I$(X11_INCLUDE)
xCFLAGS += -G 0 -O2 -fno-strength-reduce
libnx11.a: keysymstr.h $(OBJS)
mipsel-linux-ar r libnx11.a $(OBJS)
Add Selection.o to $OBJS
Modify
# perl ./keymap.pl $(X11_INCLUDE)/X11 > ./keysymstr.h
perl ./keymap.pl . > ./keysymstr.h
2. CFLAGS="-D_XP_PRINT_SERVER_" make
3.http://www.linuxhacker.org/cgi-bin/ezmlm-cgi/5/11115
FLTK with nxlib and nano-X
1.Modify configure.in
# LIBS="$LIBS -lXext -lX11 $X_EXTRA_LIBS"
If static link
LIBS="$LIBS -lnx11 -lnano-X $X_EXTRA_LIBS"
If dynamic link
LIBS="$LIBS -lX11 -lnano-X $X_EXTRA_LIBS"
2.Fix
Compiling Fl_x.cxx...
Fl_x.cxx: In function `int fl_wait(double)':
Fl_x.cxx:238: error: impossible constraint in `asm'
Fl_x.cxx:239: error: impossible constraint in `asm'
Fl_x.cxx:240: error: impossible constraint in `asm'
make[1]: *** [Fl_x.o] Error 1
The problem casue by reference to host header file.
Remove -I/usr/include to solve it.
Because we need X header files
cp -a /usr/include/X11 /usr/local/MIPSEL/mipsel-linux/include/
Add config param --x-include=-Iinclude
3.Configure
CFLAGS="-G 0" CXXFLAGS="-G 0" LDFLAGS="-s -L$PWD/../nxlib-0.45 -L$PWD/../microwindows-0.91/src/lib" ./configure --host=mipsel-linux --target=mipsel-linux --enable-shared --with-x --disable-gl --disable-cygwin --x-includes=include/ --x-libraries=$PWD/../nxlib-0.45 --cache-file=/dev/null
Fix ar in makeinclude
LIBCOMMAND = mipsel-linux-ar cr
Fix strip in makeinclude
STRIP = mipsel-linux-strip
4.make
5.Fix
Linking fluid...
../lib/libfltk.a(Fl_x.o)(.text+0x1420): In function `Fl::paste(Fl_Widget&, int)':
: undefined reference to `XConvertSelection'
../lib/libfltk.a(Fl_x.o)(.text+0x1624): In function `Fl::copy(char const*, int, int)':
: undefined reference to `XSetSelectionOwner'
../lib/libfltk.a(Fl_x.o)(.text+0x22c4): In function `fl_handle(_XEvent const&)':
: undefined reference to `XConvertSelection'
../lib/libfltk.a(fl_dnd.o)(.text+0x29c): In function `Fl::dnd()':
: undefined reference to `XSetSelectionOwner'
collect2: ld returned 1 exit status
Append the following to nxlib-0.45/stub.c
/* required for FLTK 1.1.7*/
int XConvertSelection() { printf("XConvertSelection called\n"); return 0; }
int XSetSelectionOwner() { printf("XSetSelectionOwner called\n"); return 0; }
6.vi test/Makefile
Mark following item
# fast_slow(EXEEXT) \
# keyboard$(EXEEXT) \
# mandelbrot$(EXEEXT) \
# preferences$(EXEEXT) \
# radio$(EXEEXT) \
# resize$(EXEEXT) \
# sudoku$(EXEEXT) \
# tabs$(EXEEXT) \
# valuators$(EXEEXT)
7.Copy shared library to lib/
cp src/*.so.* lib/
8.make again to let demo programs on test/ as dynamic link
9.Library needed
/tmp # /lib/ld-2.2.5.so --list ./utf8
libfltk-utf8.so.1.1 => /phone/lib/libfltk-utf8.so.1.1 (0x2aaa9000)
libm.so.6 => /lib/libm.so.6 (0x2aba3000)
libX11.so.6 => /phone/lib/libX11.so.6 (0x2ac65000)
libnano-X.so => /usr/lib/libnano-X.so (0x2acdf000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x2ad31000)
libc.so.6 => /lib/libc.so.6 (0x2ad82000)
/lib/ld.so.1 => /lib/ld-2.2.5.so (0x55550000)
# LIBS="$LIBS -lXext -lX11 $X_EXTRA_LIBS"
If static link
LIBS="$LIBS -lnx11 -lnano-X $X_EXTRA_LIBS"
If dynamic link
LIBS="$LIBS -lX11 -lnano-X $X_EXTRA_LIBS"
2.Fix
Compiling Fl_x.cxx...
Fl_x.cxx: In function `int fl_wait(double)':
Fl_x.cxx:238: error: impossible constraint in `asm'
Fl_x.cxx:239: error: impossible constraint in `asm'
Fl_x.cxx:240: error: impossible constraint in `asm'
make[1]: *** [Fl_x.o] Error 1
The problem casue by reference to host header file.
Remove -I/usr/include to solve it.
Because we need X header files
cp -a /usr/include/X11 /usr/local/MIPSEL/mipsel-linux/include/
Add config param --x-include=-Iinclude
3.Configure
CFLAGS="-G 0" CXXFLAGS="-G 0" LDFLAGS="-s -L$PWD/../nxlib-0.45 -L$PWD/../microwindows-0.91/src/lib" ./configure --host=mipsel-linux --target=mipsel-linux --enable-shared --with-x --disable-gl --disable-cygwin --x-includes=include/ --x-libraries=$PWD/../nxlib-0.45 --cache-file=/dev/null
Fix ar in makeinclude
LIBCOMMAND = mipsel-linux-ar cr
Fix strip in makeinclude
STRIP = mipsel-linux-strip
4.make
5.Fix
Linking fluid...
../lib/libfltk.a(Fl_x.o)(.text+0x1420): In function `Fl::paste(Fl_Widget&, int)':
: undefined reference to `XConvertSelection'
../lib/libfltk.a(Fl_x.o)(.text+0x1624): In function `Fl::copy(char const*, int, int)':
: undefined reference to `XSetSelectionOwner'
../lib/libfltk.a(Fl_x.o)(.text+0x22c4): In function `fl_handle(_XEvent const&)':
: undefined reference to `XConvertSelection'
../lib/libfltk.a(fl_dnd.o)(.text+0x29c): In function `Fl::dnd()':
: undefined reference to `XSetSelectionOwner'
collect2: ld returned 1 exit status
Append the following to nxlib-0.45/stub.c
/* required for FLTK 1.1.7*/
int XConvertSelection() { printf("XConvertSelection called\n"); return 0; }
int XSetSelectionOwner() { printf("XSetSelectionOwner called\n"); return 0; }
6.vi test/Makefile
Mark following item
# fast_slow(EXEEXT) \
# keyboard$(EXEEXT) \
# mandelbrot$(EXEEXT) \
# preferences$(EXEEXT) \
# radio$(EXEEXT) \
# resize$(EXEEXT) \
# sudoku$(EXEEXT) \
# tabs$(EXEEXT) \
# valuators$(EXEEXT)
7.Copy shared library to lib/
cp src/*.so.* lib/
8.make again to let demo programs on test/ as dynamic link
9.Library needed
/tmp # /lib/ld-2.2.5.so --list ./utf8
libfltk-utf8.so.1.1 => /phone/lib/libfltk-utf8.so.1.1 (0x2aaa9000)
libm.so.6 => /lib/libm.so.6 (0x2aba3000)
libX11.so.6 => /phone/lib/libX11.so.6 (0x2ac65000)
libnano-X.so => /usr/lib/libnano-X.so (0x2acdf000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x2ad31000)
libc.so.6 => /lib/libc.so.6 (0x2ad82000)
/lib/ld.so.1 => /lib/ld-2.2.5.so (0x55550000)
2008年1月6日 星期日
microwindew True Type Fonts support
http://tw.myblog.yahoo.com/jw!GdTvlQ.YCR8E9rpahh6eqfZX9g--/article?mid=128&prev=132&next=126&l=f&fid=17
1.Set ttf font environment, if *.ttf at /tmp
export MWFONTS=/tmp
2.Load ttf font
GR_FONT_ID ttf_font;
ttf_font = GrCreateFont("kaiu", 12, NULL);
GrSetFontAttr(ttf_font, GR_TFANTIALIAS|GR_TFKERNING, 0);
3.Show ttf font
GrSetGCFont(w->gid, ttf_font);
GrText(w->wid, w->gid, 20, 20, "ABCDEFGHIJK", 8, GR_TFASCII | GR_TFTOP);
microwindew 中文顯示 with build-in font
1.Enable chinese big5 support from microwindow config file
####################################################################
# Chinese BIG5 compiled in font support (big5font.c)
####################################################################
HAVE_BIG5_SUPPORT = Y
2.Get big5font.c
ftp://microwindows.censoft.com/pub/microwindows/microwindows-fonts-0.91.tar.gz
3.Put on
microwindow-0.91/src/fonts/chinese/big5font.c
4.make & install
5.Test it
Show 中華電信
XXX 為八進位數值
####################################################################
# Chinese BIG5 compiled in font support (big5font.c)
####################################################################
HAVE_BIG5_SUPPORT = Y
2.Get big5font.c
ftp://microwindows.censoft.com/pub/microwindows/microwindows-fonts-0.91.tar.gz
3.Put on
microwindow-0.91/src/fonts/chinese/big5font.c
4.make & install
5.Test it
Show 中華電信
GrText(w->wid, w->gid, 20, 20, "\244\244\265\330\271\161\253\110", 8, MWTF_DBCS_BIG5);
6. \XXX XXX 為八進位數值
訂閱:
文章 (Atom)