diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 17:43:19 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 17:43:19 +0000 |
commit | 0292059f4a16434600564cfa3f0ad2309a508a54 (patch) | |
tree | d95953cd53011917c4df679b96aedca39401b54f /kernel/kls_ttf/ftview | |
download | libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.tar.gz libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.zip |
Added libksquirrel for KDE3
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/libksquirrel@1095624 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kernel/kls_ttf/ftview')
-rw-r--r-- | kernel/kls_ttf/ftview/Makefile.am | 9 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/README | 1 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblany.h | 133 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblblit.cpp | 318 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblblit.h | 82 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblcolor.h | 56 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblender.cpp | 381 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblender.h | 216 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblhbgr.h | 74 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblhrgb.h | 76 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblvbgr.h | 76 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/gblvrgb.h | 76 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/graph.h | 653 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grblit.cpp | 2068 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grblit.h | 25 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grconfig.h | 9 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grevents.h | 117 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grfont.cpp | 373 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grfont.h | 17 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grobjs.cpp | 213 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grobjs.h | 182 | ||||
-rw-r--r-- | kernel/kls_ttf/ftview/grtypes.h | 52 |
22 files changed, 5207 insertions, 0 deletions
diff --git a/kernel/kls_ttf/ftview/Makefile.am b/kernel/kls_ttf/ftview/Makefile.am new file mode 100644 index 0000000..d744d11 --- /dev/null +++ b/kernel/kls_ttf/ftview/Makefile.am @@ -0,0 +1,9 @@ +INCLUDES = -I. @SQ_FT_CFLAGS@ + +noinst_LTLIBRARIES = libftview.la + +libftview_la_SOURCES = gblblit.cpp gblender.cpp grblit.cpp grfont.cpp grobjs.cpp + +EXTRA_DIST = gblblit.h gblender.h gblvbgr.h grblit.cpp grevents.h grobjs.cpp \ +gblany.h gblcolor.h gblhbgr.h gblvrgb.h grblit.h grfont.cpp grobjs.h README \ +gblblit.cpp gblender.cpp gblhrgb.h graph.h grconfig.h grfont.h grtypes.h diff --git a/kernel/kls_ttf/ftview/README b/kernel/kls_ttf/ftview/README new file mode 100644 index 0000000..61dba91 --- /dev/null +++ b/kernel/kls_ttf/ftview/README @@ -0,0 +1 @@ +All code in this directory is taken from ftdemos-2.1.10
\ No newline at end of file diff --git a/kernel/kls_ttf/ftview/gblany.h b/kernel/kls_ttf/ftview/gblany.h new file mode 100644 index 0000000..a0bc750 --- /dev/null +++ b/kernel/kls_ttf/ftview/gblany.h @@ -0,0 +1,133 @@ +/* check that all macros are correctly set + */ +#ifndef GDST_INCR +#error "GDST_INCR not defined" +#endif + +#ifndef GDST_TYPE +#error "GDST_TYPE not defined" +#endif + +#ifndef GDST_READ +#error "GDST_READ not defined" +#endif + +#ifdef GBLENDER_STORE_BYTES +# ifndef GDST_STOREB +# error "GDST_STOREB not defined" +# endif +#else +# ifndef GDST_STOREP +# error "GDST_STOREP not defined" +# endif +#endif /* !STORE_BYTES */ + +#ifndef GDST_STOREC +#error "GDST_STOREC not defined" +#endif + +#ifndef GDST_COPY +#error "GDST_COPY not defined" +#endif + +#ifndef GDST_COPY_VAR +#error "GDST_COPY_VAR not defined" +#endif + +#undef GCONCAT +#undef GCONCATX +#define GCONCAT(x,y) GCONCATX(x,y) +#define GCONCATX(x,y) x ## y + + +#include <stdio.h> + +static void +GCONCAT( _gblender_blit_gray8_, GDST_TYPE )( GBlenderBlit blit, + GBlenderPixel color ) +{ + + GBlender blender = blit->blender; + int r = (color >> 16) & 255; + int g = (color >> 8) & 255; + int b = (color) & 255; + + GDST_COPY_VAR + +#include "gblcolor.h" + +} + + +static void +GCONCAT( _gblender_blit_hrgb_, GDST_TYPE )( GBlenderBlit blit, + GBlenderPixel color ) +{ + GBlender blender = blit->blender; + int r = (color >> 16) & 255; + int g = (color >> 8) & 255; + int b = (color) & 255; + + GDST_COPY_VAR + +#include "gblhrgb.h" +} + + +static void +GCONCAT( _gblender_blit_hbgr_, GDST_TYPE )( GBlenderBlit blit, + GBlenderPixel color ) +{ + GBlender blender = blit->blender; + int r = (color >> 16) & 255; + int g = (color >> 8) & 255; + int b = (color) & 255; + + GDST_COPY_VAR + +#include "gblhbgr.h" +} + + +static void +GCONCAT( _gblender_blit_vrgb_, GDST_TYPE )( GBlenderBlit blit, + GBlenderPixel color ) +{ + GBlender blender = blit->blender; + int r = (color >> 16) & 255; + int g = (color >> 8) & 255; + int b = (color) & 255; + + GDST_COPY_VAR + +#include "gblvrgb.h" +} + +static void +GCONCAT( _gblender_blit_vbgr_, GDST_TYPE )( GBlenderBlit blit, + GBlenderPixel color ) +{ + GBlender blender = blit->blender; + int r = (color >> 16) & 255; + int g = (color >> 8) & 255; + int b = (color) & 255; + + GDST_COPY_VAR + +#include "gblvbgr.h" +} + +/* unset the macros, to prevent accidental re-use + */ + +#undef GCONCATX +#undef GCONCAT +#undef GDST_TYPE +#undef GDST_INCR +#undef GDST_READ +#undef GDST_COPY +#undef GDST_STOREB +#undef GDST_STOREP +#undef GDST_STOREC +#undef GDST_COPY_VAR +/* EOF */ diff --git a/kernel/kls_ttf/ftview/gblblit.cpp b/kernel/kls_ttf/ftview/gblblit.cpp new file mode 100644 index 0000000..afb363d --- /dev/null +++ b/kernel/kls_ttf/ftview/gblblit.cpp @@ -0,0 +1,318 @@ +#include "gblblit.h" + +#include <stdio.h> + +/* blitting gray glyphs + */ + +/* generic macros + */ +#define GRGB_PACK(r,g,b) ( ((GBlenderPixel)(r) << 16) | \ + ((GBlenderPixel)(g) << 8) | \ + (GBlenderPixel)(b) ) + +#define GDST_STORE3(d,r,g,b) (d)[0] = (unsigned char)(r); \ + (d)[1] = (unsigned char)(g); \ + (d)[2] = (unsigned char)(b) + +/* */ + +#define GRGB_TO_RGB565(r,g,b) ((unsigned short)( ((r << 8) & 0xF800) | \ + ((g << 3) & 0x07E0) | \ + ((b >> 3) & 0x001F) ) ) + +#define GRGB565_TO_RGB24(p) ( ( ((p) << 8) & 0xF80000 ) | \ + ( ((p) << 3) & 0x0700F8 ) | \ + ( ((p) << 5) & 0x00FC00 ) | \ + ( ((p) >> 1) & 0x000300 ) | \ + ( ((p) >> 2) & 0x000007 ) ) + +#define GRGB24_TO_RGB565(p) ( (unsigned short)( (((p) >> 8) & 0xF800 ) | \ + (((p) >> 5) & 0x07E0 ) | \ + (((p) >> 3) & 0x001F ) ) ) + +/* */ + +#define GRGB_TO_BGR565(r,g,b) GRGB_TO_RGB565(b,g,r) + +#define GBGR565_TO_RGB24(p) ( ( ((p) << 19) & 0xF80000 ) | \ + ( ((p) << 12) & 0x070000 ) | \ + ( ((p) << 5) & 0x00FC00 ) | \ + ( ((p) >> 1) & 0x000300 ) | \ + ( ((p) >> 8) & 0x0000F8 ) | \ + ( ((p) >> 13) & 0x000007 ) ) + +#define GRGB24_TO_BGR565(p) ( (unsigned short)( (((p) << 8) & 0xF800 ) | \ + (((p) >> 5) & 0x07E0 ) | \ + (((p) >> 19) & 0x001F ) ) ) + +/* */ + +/* Rgb32 blitting routines + */ + +#define GDST_TYPE rgb32 +#define GDST_INCR 4 +#define GDST_READ(d,p) (p) = *(GBlenderPixel*)(d) & 0xFFFFFF +#define GDST_COPY(d) *(GBlenderPixel*)(d) = color +#define GDST_STOREP(d,cells,a) *(GBlenderPixel*)(d) = (cells)[(a)] +#define GDST_STOREB(d,cells,a) \ + { \ + GBlenderCell* _g = (cells) + (a)*3; \ + \ + GDST_STOREC(d,_g[0],_g[1],_g[2]); \ + } +#define GDST_STOREC(d,r,g,b) *(GBlenderPixel*)(d) = GRGB_PACK(r,g,b) +#define GDST_COPY_VAR /* nothing */ + +#include "gblany.h" + +/* Rgb24 blitting routines + */ + +#define GDST_TYPE rgb24 +#define GDST_INCR 3 +#define GDST_READ(d,p) (p) = GRGB_PACK((d)[0],(d)[1],(d)[2]) +#define GDST_COPY(d) GDST_STORE3(d,r,g,b) +#define GDST_STOREC(d,r,g,b) GDST_STORE3(d,r,g,b) + +#define GDST_STOREB(d,cells,a) \ + { \ + GBlenderCell* _g = (cells) + (a)*3; \ + \ + (d)[0] = _g[0]; \ + (d)[1] = _g[1]; \ + (d)[2] = _g[2]; \ + } + +#define GDST_STOREP(d,cells,a) \ + { \ + GBlenderPixel _pix = (cells)[(a)]; \ + \ + GDST_STORE3(d,_pix >> 16,_pix >> 8,_pix); \ + } + +#define GDST_COPY_VAR /* nothing */ + +#include "gblany.h" + +/* Rgb565 blitting routines + */ + +#define GDST_TYPE rgb565 +#define GDST_INCR 2 + +#define GDST_READ(d,p) p = (GBlenderPixel)*(unsigned short*)(d); \ + p = GRGB565_TO_RGB24(p) + +#define GDST_COPY_VAR unsigned short pix = GRGB_TO_RGB565(r,g,b); +#define GDST_COPY(d) *(unsigned short*)(d) = pix + +#define GDST_STOREB(d,cells,a) \ + { \ + GBlenderCell* _g = (cells) + (a)*3; \ + \ + *(unsigned short*)(d) = GRGB_TO_RGB565(_g[0],_g[1],_g[2]); \ + } + +#define GDST_STOREP(d,cells,a) \ + { \ + GBlenderPixel _pix = (cells)[(a)]; \ + \ + *(unsigned short*)(d) = GRGB24_TO_RGB565(_pix); \ + } + +#define GDST_STOREC(d,r,g,b) *(unsigned short*)(d) = GRGB_TO_RGB565(r,g,b) + +#include "gblany.h" + +/* Bgr565 blitting routines + */ +#define GDST_TYPE bgr565 +#define GDST_INCR 2 + +#define GDST_READ(d,p) p = (GBlenderPixel)*(unsigned short*)(d); \ + p = GBGR565_TO_RGB24(p) + +#define GDST_COPY_VAR unsigned short pix = GRGB_TO_BGR565(r,g,b); +#define GDST_COPY(d) *(d) = pix + +#define GDST_STOREB(d,cells,a) \ + { \ + GBlenderCell* _g = (cells) + (a)*3; \ + \ + *(unsigned short*)(d) = GRGB_TO_BGR565(_g[0],_g[1],_g[2]); \ + } + +#define GDST_STOREP(d,cells,a) \ + { \ + GBlenderPixel _pix = (cells)[(a)]; \ + \ + *(unsigned short*)(d) = GRGB24_TO_BGR565(_pix); \ + } + +#define GDST_STOREC(d,r,g,b) *(unsigned short*)(d) = GRGB_TO_BGR565(r,g,b) + +#include "gblany.h" + +/* */ + +static void +_gblender_blit_dummy( GBlenderBlit blit, + GBlenderPixel color ) +{ + (blit)=(blit); + (color)=(color); +} + + +GBLENDER_APIDEF( int ) +gblender_blit_init( GBlenderBlit blit, + GBlender blender, + int dst_x, + int dst_y, + GBlenderSourceFormat src_format, + const unsigned char* src_buffer, + int src_pitch, + int src_width, + int src_height, + GBlenderTargetFormat dst_format, + unsigned char* dst_buffer, + int dst_pitch, + int dst_width, + int dst_height ) +{ + int src_x = 0; + int src_y = 0; + int delta; + GBlenderBlitFunc blit_func = 0; + + switch ( src_format ) + { + case GBLENDER_SOURCE_GRAY8: + switch ( dst_format ) + { + case GBLENDER_TARGET_RGB32: blit_func = _gblender_blit_gray8_rgb32; break; + case GBLENDER_TARGET_RGB24: blit_func = _gblender_blit_gray8_rgb24; break; + case GBLENDER_TARGET_RGB565: blit_func = _gblender_blit_gray8_rgb565; break; + case GBLENDER_TARGET_BGR565: blit_func = _gblender_blit_gray8_bgr565; break; + default: + ; + } + break; + + case GBLENDER_SOURCE_HRGB: + switch ( dst_format ) + { + case GBLENDER_TARGET_RGB32: blit_func = _gblender_blit_hrgb_rgb32; break; + case GBLENDER_TARGET_RGB24: blit_func = _gblender_blit_hrgb_rgb24; break; + case GBLENDER_TARGET_RGB565: blit_func = _gblender_blit_hrgb_rgb565; break; + case GBLENDER_TARGET_BGR565: blit_func = _gblender_blit_hrgb_bgr565; break; + default: + ; + } + break; + + case GBLENDER_SOURCE_HBGR: + switch ( dst_format ) + { + case GBLENDER_TARGET_RGB32: blit_func = _gblender_blit_hbgr_rgb32; break; + case GBLENDER_TARGET_RGB24: blit_func = _gblender_blit_hbgr_rgb24; break; + case GBLENDER_TARGET_RGB565: blit_func = _gblender_blit_hbgr_rgb565; break; + case GBLENDER_TARGET_BGR565: blit_func = _gblender_blit_hbgr_bgr565; break; + default: + ; + } + break; + + case GBLENDER_SOURCE_VRGB: + switch ( dst_format ) + { + case GBLENDER_TARGET_RGB32: blit_func = _gblender_blit_vrgb_rgb32; break; + case GBLENDER_TARGET_RGB24: blit_func = _gblender_blit_vrgb_rgb24; break; + case GBLENDER_TARGET_RGB565: blit_func = _gblender_blit_vrgb_rgb565; break; + case GBLENDER_TARGET_BGR565: blit_func = _gblender_blit_vrgb_bgr565; break; + default: + ; + } + break; + + case GBLENDER_SOURCE_VBGR: + switch ( dst_format ) + { + case GBLENDER_TARGET_RGB32: blit_func = _gblender_blit_vbgr_rgb32; break; + case GBLENDER_TARGET_RGB24: blit_func = _gblender_blit_vbgr_rgb24; break; + case GBLENDER_TARGET_RGB565: blit_func = _gblender_blit_vbgr_rgb565; break; + case GBLENDER_TARGET_BGR565: blit_func = _gblender_blit_vbgr_bgr565; break; + default: + ; + } + break; + + default: + ; + } + + blit->blender = blender; + blit->blit_func = blit_func; + + if ( blit_func == 0 ) + { + /* unsupported blit mode + */ + blit->blit_func = _gblender_blit_dummy; + return -2; + } + + if ( dst_x < 0 ) + { + src_width += dst_x; + src_x -= dst_x; + dst_x = 0; + } + + delta = dst_x + src_width - dst_width; + if ( delta > 0 ) + src_width -= delta; + + if ( dst_y < 0 ) + { + src_height += dst_y; + src_y -= dst_y; + dst_y = 0; + } + + delta = dst_y + src_height - dst_height; + if ( delta > 0 ) + src_height -= delta; + + /* nothing to blit + */ + if ( src_width <= 0 || src_height <= 0 ) + { + blit->blit_func = _gblender_blit_dummy; + return -1; + } + + blit->width = src_width; + blit->height = src_height; + blit->src_format = src_format; + blit->dst_format = dst_format; + + blit->src_x = src_x; + blit->src_y = src_y; + blit->src_line = src_buffer + src_pitch*src_y; + blit->src_pitch = src_pitch; + if ( src_pitch < 0 ) + blit->src_line -= (src_height-1)*src_pitch; + + blit->dst_x = dst_x; + blit->dst_y = dst_y; + blit->dst_line = dst_buffer + dst_pitch*dst_y; + blit->dst_pitch = dst_pitch; + if ( dst_pitch < 0 ) + blit->dst_line -= (dst_height-1)*dst_pitch; + + return 0; +} + diff --git a/kernel/kls_ttf/ftview/gblblit.h b/kernel/kls_ttf/ftview/gblblit.h new file mode 100644 index 0000000..564a21d --- /dev/null +++ b/kernel/kls_ttf/ftview/gblblit.h @@ -0,0 +1,82 @@ +#ifndef __GBLENDER_BLIT_H__ +#define __GBLENDER_BLIT_H__ + +#include "gblender.h" + +/* + * blitting interface + * + */ + +typedef enum +{ + GBLENDER_SOURCE_GRAY8 = 0, + GBLENDER_SOURCE_HRGB, + GBLENDER_SOURCE_HBGR, + GBLENDER_SOURCE_VRGB, + GBLENDER_SOURCE_VBGR, + + GBLENDER_SOURCE_MAX + +} GBlenderSourceFormat; + + +typedef enum +{ + GBLENDER_TARGET_GRAY8 = 0, + GBLENDER_TARGET_RGB32, + GBLENDER_TARGET_RGB24, + GBLENDER_TARGET_RGB565, + GBLENDER_TARGET_BGR565, + + GBLENDER_TARGET_MAX + +} GBlenderTargetFormat; + +typedef struct GBlenderBlitRec_* GBlenderBlit; + +typedef void (*GBlenderBlitFunc)( GBlenderBlit blit, + GBlenderPixel color ); + +typedef struct GBlenderBlitRec_ +{ + int width; + int height; + const unsigned char* src_line; + int src_pitch; + int src_x; + int src_y; + unsigned char* dst_line; + int dst_pitch; + int dst_x; + int dst_y; + GBlenderSourceFormat src_format; + GBlenderTargetFormat dst_format; + + GBlender blender; + GBlenderBlitFunc blit_func; + +} GBlenderBlitRec; + + + +GBLENDER_API( int ) +gblender_blit_init( GBlenderBlit blit, + GBlender blender, + int dst_x, + int dst_y, + GBlenderSourceFormat src_format, + const unsigned char* src_buffer, + int src_pitch, + int src_width, + int src_height, + GBlenderTargetFormat dst_format, + unsigned char* dst_buffer, + int dst_pitch, + int dst_width, + int dst_height ); + +#define gblender_blit_run(b,color) (b)->blit_func( (b), (color) ) + + +#endif /* __GBLENDER_BLIT_H__ */ diff --git a/kernel/kls_ttf/ftview/gblcolor.h b/kernel/kls_ttf/ftview/gblcolor.h new file mode 100644 index 0000000..0aa2b6d --- /dev/null +++ b/kernel/kls_ttf/ftview/gblcolor.h @@ -0,0 +1,56 @@ + + GBLENDER_VARS(blender,color); + + int h = blit->height; + const unsigned char* src_line = blit->src_line; + unsigned char* dst_line = blit->dst_line; + + /* make compiler happy */ + (r)=(r); + (g)=(g); + (b)=(b); + + do + { + const unsigned char* src = src_line + (blit->src_x); + unsigned char* dst = dst_line + blit->dst_x*GDST_INCR; + int w = blit->width; + + do + { + int a = GBLENDER_SHADE_INDEX(src[0]); + + if ( a == 0 ) + { + /* nothing */ + } + else if ( a == GBLENDER_SHADE_COUNT ) + { + GDST_COPY(dst); + } + else + { + GBlenderPixel back; + + GDST_READ(dst,back); + + GBLENDER_LOOKUP( blender, back ); + +#ifdef GBLENDER_STORE_BYTES + GDST_STOREB(dst,_gcells,a); +#else + GDST_STOREP(dst,_gcells,a); +#endif + } + + src += 1; + dst += GDST_INCR; + } + while (--w > 0); + + src_line += blit->src_pitch; + dst_line += blit->dst_pitch; + } + while (--h > 0); + + GBLENDER_CLOSE(blender); diff --git a/kernel/kls_ttf/ftview/gblender.cpp b/kernel/kls_ttf/ftview/gblender.cpp new file mode 100644 index 0000000..a0f204d --- /dev/null +++ b/kernel/kls_ttf/ftview/gblender.cpp @@ -0,0 +1,381 @@ +#include "gblender.h" +#include <stdlib.h> +#include <math.h> + +static void +gblender_set_gamma_table( double gamma_value, + unsigned short* gamma_ramp, + unsigned char* gamma_ramp_inv ) +{ + int gmax = (256 << GBLENDER_GAMMA_SHIFT)-1; + + if ( gamma_value <= 0 ) /* special case for sRGB */ + { + int ii; + + for ( ii = 0; ii < 256; ii++ ) + { + double x = (double)ii / 255.0; + + if ( x <= 0.03926 ) + x = x/12.92; + else + x = pow( (x+0.055)/ 1.055, 2.4 ); + + gamma_ramp[ii] = (unsigned short)(gmax*x); + } + + for ( ii = 0; ii < gmax; ii++ ) + { + double x = (double)ii / gmax; + + if ( x <= 0.00304 ) + x = 12.92*x; + else + x = 1.055*pow(x,1/2.4) - 0.055; + + gamma_ramp_inv[ii] = (unsigned char)(255*x); + } + } + else + { + int ii; + double gamma_inv = 1.0f / gamma_value; + + /* voltage to linear */ + for ( ii = 0; ii < 256; ii++ ) + gamma_ramp[ii] = (unsigned short)( pow( (double)ii/255.0f, gamma_value )*gmax ); + + /* linear to voltage */ + for ( ii = 0; ii < gmax; ii++ ) + gamma_ramp_inv[ii] = (unsigned char)( pow( (double)ii/gmax, gamma_inv ) * 255.0f ); + } +} + + +/* clear the cache + */ +static void +gblender_clear( GBlender blender ) +{ + int nn; + GBlenderKey keys = blender->keys; + + if ( blender->channels ) + { + GBlenderChanKey chan_keys = (GBlenderChanKey) blender->keys; + + for ( nn = 0; nn < GBLENDER_KEY_COUNT; nn++ ) + chan_keys[nn].index = -1; + } + else + { + for ( nn = 0; nn < GBLENDER_KEY_COUNT; nn++ ) + keys[nn].cells = NULL; + } +} + +GBLENDER_APIDEF( void ) +gblender_reset( GBlender blender ) +{ + gblender_clear( blender ); + + blender->cache_r_back = -1; + blender->cache_r_fore = -1; + blender->cache_r_cells = 0; + + blender->cache_r_back = -1; + blender->cache_r_fore = -1; + blender->cache_r_cells = 0; + + blender->cache_back = 0; + blender->cache_fore = 0xFFFFFF; + blender->cache_cells = gblender_lookup( blender, + blender->cache_back, + blender->cache_fore ); + +#ifdef GBLENDER_STATS + blender->stat_hits = 0; + blender->stat_lookups = 0; + blender->stat_keys = 0; + blender->stat_clears = 0; +#endif +} + +GBLENDER_APIDEF( void ) +gblender_init( GBlender blender, + double gamma_value ) +{ + blender->channels = 0; + + gblender_set_gamma_table ( gamma_value, + blender->gamma_ramp, + blender->gamma_ramp_inv ); + + gblender_reset( blender ); +} + +/* recompute the grade levels of a given key + */ +static void +gblender_reset_key( GBlender blender, + GBlenderKey key ) +{ + GBlenderPixel back = key->background; + GBlenderPixel fore = key->foreground; + GBlenderCell* gr = key->cells; + int nn; + int gmax = (256 << GBLENDER_GAMMA_SHIFT)-1; + + const unsigned char* gamma_ramp_inv = blender->gamma_ramp_inv; + const unsigned short* gamma_ramp = blender->gamma_ramp; + + int r1,g1,b1,r2,g2,b2; + + r1 = ( back >> 16 ) & 255; + g1 = ( back >> 8 ) & 255; + b1 = ( back ) & 255; + + r2 = ( fore >> 16 ) & 255; + g2 = ( fore >> 8 ) & 255; + b2 = ( fore ) & 255; + +#ifdef GBLENDER_STORE_BYTES + gr[0] = (unsigned char)r1; + gr[1] = (unsigned char)g1; + gr[2] = (unsigned char)b1; + gr += 3; +#else + gr[0] = back; + gr += 1; +#endif + + r1 = gamma_ramp[r1]; + g1 = gamma_ramp[g1]; + b1 = gamma_ramp[b1]; + + r2 = gamma_ramp[r2]; + g2 = gamma_ramp[g2]; + b2 = gamma_ramp[b2]; + + for ( nn = 1; nn < GBLENDER_SHADE_COUNT; nn++ ) + { + int a = (nn << GBLENDER_SHADE_BITS); + int r = ((r2-r1)*a + 128); + int g = ((g2-g1)*a + 128); + int b = ((g2-g1)*a + 128); + + r = (r + (r >> 8)) >> 8; + g = (g + (g >> 8)) >> 8; + b = (b + (b >> 8)) >> 8; + + r += r1; + g += g1; + b += b1; + +#if 0 + r = ( r | -(r >> 8) ) & 255; + g = ( g | -(g >> 8) ) & 255; + b = ( b | -(b >> 8) ) & 255; +#else + if ( r < 0 ) r = 0; else if ( r > gmax ) r = gmax; + if ( g < 0 ) g = 0; else if ( g > gmax ) g = gmax; + if ( b < 0 ) b = 0; else if ( b > gmax ) b = gmax; +#endif + + r = gamma_ramp_inv[r]; + g = gamma_ramp_inv[g]; + b = gamma_ramp_inv[b]; + +#ifdef GBLENDER_STORE_BYTES + gr[0] = (unsigned char)r; + gr[1] = (unsigned char)g; + gr[2] = (unsigned char)b; + gr += 3; +#else + gr[0] = (( r & 255 ) << 16) | + (( g & 255 ) << 8 ) | + (( b & 255 ) ) ; + gr ++; +#endif + } +} + + /* lookup the grades of a given (background,foreground) couple + */ +GBLENDER_APIDEF( GBlenderCell* ) +gblender_lookup( GBlender blender, + GBlenderPixel background, + GBlenderPixel foreground ) +{ + int idx, idx0; + GBlenderKey key; + +#ifdef GBLENDER_STATS + blender->stat_hits--; + blender->stat_lookups++; +#endif + + if ( blender->channels ) + { + /* set to normal mode */ + blender->channels = 0; + gblender_reset( blender ); + } + + idx0 = ( background + foreground*63 ) % GBLENDER_KEY_COUNT; + idx = idx0; + do + { + key = blender->keys + idx; + + if ( key->cells == NULL ) + goto NewNode; + + if ( key->background == background && + key->foreground == foreground ) + goto Exit; + + idx = (idx+1) % GBLENDER_KEY_COUNT; + } + while ( idx != idx0 ); + + /* the cache is full, clear it completely + */ +#ifdef GBLENDER_STATS + blender->stat_clears++; + gblender_clear( blender ); +#endif + +NewNode: + key->background = background; + key->foreground = foreground; + key->cells = blender->cells + \ + idx0*(GBLENDER_SHADE_COUNT*GBLENDER_CELL_SIZE); + + gblender_reset_key( blender, key ); + +#ifdef GBLENDER_STATS + blender->stat_keys++; +#endif + +Exit: + return key->cells; +} + + +static void +gblender_reset_channel_key( GBlender blender, + GBlenderChanKey key ) +{ + int back = key->backfore & 255; + int fore = (key->backfore >> 8) & 255; + unsigned char* gr = (unsigned char*)blender->cells + key->index; + int nn; + + const unsigned char* gamma_ramp_inv = blender->gamma_ramp_inv; + const unsigned short* gamma_ramp = blender->gamma_ramp; + + int r1,r2; + int gmax = (256 << GBLENDER_GAMMA_SHIFT)-1; + + r1 = back; + r2 = fore; + + gr[0] = r1; + gr++; + + + r1 = gamma_ramp[r1]; + r2 = gamma_ramp[r2]; + + for ( nn = 1; nn < GBLENDER_SHADE_COUNT; nn++ ) + { + int a = (nn << GBLENDER_SHADE_BITS); + int r = ((r2-r1)*a + 128); + + r = (r + (r >> 8)) >> 8; + r += r1; + if ( r < 0 ) r = 0; else if ( r > gmax ) r = gmax; + r = gamma_ramp_inv[r]; + + gr[0] = (unsigned char)r; + gr++; + } +} + + +GBLENDER_APIDEF( unsigned char* ) +gblender_lookup_channel( GBlender blender, + int background, + int foreground ) +{ + int idx, idx0; + unsigned short backfore = (unsigned short)((foreground << 8) | background); + GBlenderChanKey key; + +#ifdef GBLENDER_STATS + blender->stat_hits--; + blender->stat_lookups++; +#endif + + if ( !blender->channels ) + { + /* set to normal mode */ + blender->channels = 1; + gblender_reset( blender ); + } + + idx0 = ( background + foreground*63 ) % (2*GBLENDER_KEY_COUNT); + idx = idx0; + do + { + key = (GBlenderChanKey)blender->keys + idx; + + if ( key->index < 0 ) + goto NewNode; + + if ( key->backfore == backfore ) + goto Exit; + + idx = (idx+1) % (2*GBLENDER_KEY_COUNT); + } + while ( idx != idx0 ); + + /* the cache is full, clear it completely + */ +#ifdef GBLENDER_STATS + blender->stat_clears++; + gblender_clear( blender ); +#endif + +NewNode: + key->backfore = backfore; + key->index = (signed short)( idx0 * GBLENDER_SHADE_COUNT ); + + gblender_reset_channel_key( blender, key ); + +#ifdef GBLENDER_STATS + blender->stat_keys++; +#endif + +Exit: + return (unsigned char*)blender->cells + key->index; +} + + + +#ifdef GBLENDER_STATS +#include <stdio.h> +GBLENDER_APIDEF( void ) +gblender_dump_stats( GBlender blender ) +{ + printf( "hits = %ld, miss1 = %ld, miss2 = %ld, rate1=%.2f%%, rate2=%.2f%%\n", + blender->stat_hits, + blender->stat_lookups, + blender->stat_keys, + (100.0*blender->stat_hits) / (double)(blender->stat_hits + blender->stat_lookups), + (100.0*blender->stat_lookups) / (double)( blender->stat_lookups + blender->stat_keys) + ); +} +#endif diff --git a/kernel/kls_ttf/ftview/gblender.h b/kernel/kls_ttf/ftview/gblender.h new file mode 100644 index 0000000..b519b3c --- /dev/null +++ b/kernel/kls_ttf/ftview/gblender.h @@ -0,0 +1,216 @@ +/**************************************************************************** + * + * Gamma-correct alpha blending of text + * + * (C) 2004 David Turner + * + */ + +#ifndef __GBLENDER_H__ +#define __GBLENDER_H__ + +#ifndef GBLENDER_API +#define GBLENDER_API(x) extern x +#endif + +#ifndef GBLENDER_APIDEF +#define GBLENDER_APIDEF(x) x +#endif + +#define GBLENDER_SHADE_BITS 4 /* must be <= 7 !! */ +#define GBLENDER_SHADE_COUNT ( 1 << GBLENDER_SHADE_BITS ) +#define GBLENDER_SHADE_INDEX(n) ((n + (GBLENDER_SHADE_COUNT/2)) >> GBLENDER_SHADE_BITS) +#define GBLENDER_KEY_COUNT 256 +#define GBLENDER_GAMMA_SHIFT 2 + +#define xGBLENDER_STORE_BYTES /* define this to store (R,G,B) values on 3 \ + * bytes, instead of a single 32-bit integer.\ + * surprisingly, this can speed up \ + * the blender on certain machines. \ + * Go figure what's really happenning though :-) \ + */ + +#define GBLENDER_STATS /* define this to collect statistics in the \ + * blender \ + */ + + typedef unsigned int GBlenderPixel; /* needs 32-bits here !! */ + +#ifdef GBLENDER_STORE_BYTES + typedef unsigned char GBlenderCell; +# define GBLENDER_CELL_SIZE 3 +#else + typedef GBlenderPixel GBlenderCell; +# define GBLENDER_CELL_SIZE 1 +#endif + + + typedef struct + { + GBlenderPixel background; + GBlenderPixel foreground; + GBlenderCell* cells; + + } GBlenderKeyRec, *GBlenderKey; + + + typedef struct + { + unsigned short backfore; /* (fore << 8) | back */ + signed short index; /* offset in (unsigned char*)cells */ + + } GBlenderChanKeyRec, *GBlenderChanKey; + + + typedef struct GBlenderRec_ + { + GBlenderKeyRec keys [ GBLENDER_KEY_COUNT ]; + GBlenderCell cells[ GBLENDER_KEY_COUNT*GBLENDER_SHADE_COUNT*GBLENDER_CELL_SIZE ]; + + /* a small cache for normal modes + */ + GBlenderPixel cache_back; + GBlenderPixel cache_fore; + GBlenderCell* cache_cells; + + /* a small cache for RGB channels modes + */ + int cache_r_back; + int cache_r_fore; + unsigned char* cache_r_cells; + + int cache_g_back; + int cache_g_fore; + unsigned char* cache_g_cells; + + int cache_b_back; + int cache_b_fore; + unsigned char* cache_b_cells; + + /* are we in color or channel mode ? + */ + int channels; + + /* the gamma table + */ + unsigned short gamma_ramp[256]; /* voltage to linear */ + unsigned char gamma_ramp_inv[256 << GBLENDER_GAMMA_SHIFT]; /* linear to voltage */ + +#ifdef GBLENDER_STATS + long stat_hits; /* number of direct hits */ + long stat_lookups; /* number of table lookups */ + long stat_keys; /* number of table key recomputation */ + long stat_clears; /* number of table clears */ +#endif + + } GBlenderRec, *GBlender; + + + /* initialize with a given gamma */ + GBLENDER_API( void ) + gblender_init( GBlender blender, + double gamma ); + + + /* clear blender, and reset stats */ + GBLENDER_API( void ) + gblender_reset( GBlender reset ); + + + /* lookup a cell range for a given (background,foreground) pair + */ + GBLENDER_API( GBlenderCell* ) + gblender_lookup( GBlender blender, + GBlenderPixel background, + GBlenderPixel foreground ); + + GBLENDER_API( unsigned char* ) + gblender_lookup_channel( GBlender blender, + int background, + int foreground ); + +#ifdef GBLENDER_STATS + GBLENDER_API( void ) + gblender_dump_stats( GBlender blender ); +#else +# define gblender_dump_stats(b) do { } while (0); +#endif + + + /* no final `;'! */ +#define GBLENDER_VARS(_gb,_fore) \ + GBlenderPixel _gback = (_gb)->cache_back; \ + GBlenderCell* _gcells = ( (_fore) == (_gb)->cache_fore ? (_gb)->cache_cells : gblender_lookup( (_gb), _gback, _fore ) ); \ + GBlenderPixel _gfore = (_fore) + +#define GBLENDER_CLOSE(_gb) \ + (_gb)->cache_back = _gback; \ + (_gb)->cache_fore = _gfore; \ + (_gb)->cache_cells = _gcells; + + + + /* no final `;'! */ +#define GBLENDER_CHANNEL_VARS(_gb,_rfore,_gfore,_bfore) \ + int _grback = (_gb)->cache_r_back; \ + unsigned char* _grcells = ( (_rfore) == (_gb)->cache_r_fore ? (_gb)->cache_r_cells : gblender_lookup_channel( (_gb), _grback, _rfore )); \ + int _grfore = (_rfore); \ + int _ggback = (_gb)->cache_g_back; \ + unsigned char* _ggcells = ( (_gfore) == (_gb)->cache_g_fore ? (_gb)->cache_g_cells : gblender_lookup_channel( (_gb), _ggback, _gfore )); \ + int _ggfore = (_rfore); \ + int _gbback = (_gb)->cache_b_back; \ + unsigned char* _gbcells = ( (_bfore) == (_gb)->cache_b_fore ? (_gb)->cache_b_cells : gblender_lookup_channel( (_gb), _gbback, _bfore )); \ + int _gbfore = (_bfore) + +#define GBLENDER_CHANNEL_CLOSE(_gb) \ + (_gb)->cache_r_back = _grback; \ + (_gb)->cache_r_fore = _grfore; \ + (_gb)->cache_r_cells = _grcells; \ + (_gb)->cache_g_back = _ggback; \ + (_gb)->cache_g_fore = _ggfore; \ + (_gb)->cache_g_cells = _ggcells; \ + (_gb)->cache_b_back = _gbback; \ + (_gb)->cache_b_fore = _gbfore; \ + (_gb)->cache_b_cells = _gbcells; + + +#ifdef GBLENDER_STATS +#define GBLENDER_STAT_HIT(gb) (gb)->stat_hits++ +#else +#define GBLENDER_STAT_HIT(gb) /* nothing */ +#endif + +#define GBLENDER_LOOKUP(gb,back) \ + GBLENDER_STAT_HIT(gb); \ + if ( _gback != (GBlenderPixel)(back) ) \ + { \ + _gback = (GBlenderPixel)(back); \ + _gcells = gblender_lookup( (gb), _gback, _gfore ); \ + } + +#define GBLENDER_LOOKUP_R(gb,back) \ + GBLENDER_STAT_HIT(gb); \ + if ( _grback != (int)(back) ) \ + { \ + _grback = (GBlenderPixel)(back); \ + _grcells = gblender_lookup_channel( (gb), _grback, _grfore ); \ + } + +#define GBLENDER_LOOKUP_G(gb,back) \ + GBLENDER_STAT_HIT(gb); \ + if ( _ggback != (int)(back) ) \ + { \ + _ggback = (GBlenderPixel)(back); \ + _ggcells = gblender_lookup_channel( (gb), _ggback, _ggfore ); \ + } + +#define GBLENDER_LOOKUP_B(gb,back) \ + GBLENDER_STAT_HIT(gb); \ + if ( _gbback != (int)(back) ) \ + { \ + _gbback = (GBlenderPixel)(back); \ + _gbcells = gblender_lookup_channel( (gb), _gbback, _gbfore ); \ + } + + +#endif /* __GBENCH_CACHE_H__ */ diff --git a/kernel/kls_ttf/ftview/gblhbgr.h b/kernel/kls_ttf/ftview/gblhbgr.h new file mode 100644 index 0000000..a2740ab --- /dev/null +++ b/kernel/kls_ttf/ftview/gblhbgr.h @@ -0,0 +1,74 @@ + GBLENDER_CHANNEL_VARS(blender,r,g,b); + + int h = blit->height; + const unsigned char* src_line = blit->src_line; + unsigned char* dst_line = blit->dst_line; + + do + { + const unsigned char* src = src_line + blit->src_x*3; + unsigned char* dst = dst_line + blit->dst_x*GDST_INCR; + int w = blit->width; + + do + { + int ab = GBLENDER_SHADE_INDEX(src[0]); + int ag = GBLENDER_SHADE_INDEX(src[1]); + int ar = GBLENDER_SHADE_INDEX(src[2]); + int aa = (ar << 16) | (ag << 8) | ab; + + if ( aa == 0 ) + { + /* nothing */ + } + else if ( aa == ((GBLENDER_SHADE_COUNT << 16) | + (GBLENDER_SHADE_COUNT << 8) | + (GBLENDER_SHADE_COUNT) ) ) + { + GDST_COPY(dst); + } + else + { + GBlenderPixel back; + int pix_r, pix_g, pix_b; + + GDST_READ(dst,back); + + { + int back_r = (back >> 16) & 255; + + GBLENDER_LOOKUP_R( blender, back_r ); + + pix_r = _grcells[ar]; + } + + { + int back_g = (back >> 8) & 255; + + GBLENDER_LOOKUP_G( blender, back_g ); + + pix_g = _ggcells[ag]; + } + + { + int back_b = (back) & 255; + + GBLENDER_LOOKUP_B( blender, back_b ); + + pix_b = _gbcells[ab]; + } + + GDST_STOREC(dst,pix_r,pix_g,pix_b); + } + + src += 3; + dst += GDST_INCR; + } + while (--w > 0); + + src_line += blit->src_pitch; + dst_line += blit->dst_pitch; + } + while (--h > 0); + + GBLENDER_CHANNEL_CLOSE(blender); diff --git a/kernel/kls_ttf/ftview/gblhrgb.h b/kernel/kls_ttf/ftview/gblhrgb.h new file mode 100644 index 0000000..930a6c9 --- /dev/null +++ b/kernel/kls_ttf/ftview/gblhrgb.h @@ -0,0 +1,76 @@ + + GBLENDER_CHANNEL_VARS(blender,r,g,b); + + int h = blit->height; + const unsigned char* src_line = blit->src_line; + unsigned char* dst_line = blit->dst_line; + + do + { + const unsigned char* src = src_line + blit->src_x*3; + unsigned char* dst = dst_line + blit->dst_x*GDST_INCR; + int w = blit->width; + + do + { + int ar = GBLENDER_SHADE_INDEX(src[0]); + int ag = GBLENDER_SHADE_INDEX(src[1]); + int ab = GBLENDER_SHADE_INDEX(src[2]); + int aa = (ar << 16) | (ag << 8) | ab; + + if ( aa == 0 ) + { + /* nothing */ + } + else if ( aa == ((GBLENDER_SHADE_COUNT << 16) | + (GBLENDER_SHADE_COUNT << 8) | + (GBLENDER_SHADE_COUNT) ) ) + { + GDST_COPY(dst); + } + else + { + GBlenderPixel back; + int pix_r, pix_g, pix_b; + + GDST_READ(dst,back); + + { + int back_r = (back >> 16) & 255; + + GBLENDER_LOOKUP_R( blender, back_r ); + + pix_r = _grcells[ar]; + } + + { + int back_g = (back >> 8) & 255; + + GBLENDER_LOOKUP_G( blender, back_g ); + + pix_g = _ggcells[ag]; + } + + { + int back_b = (back) & 255; + + GBLENDER_LOOKUP_B( blender, back_b ); + + pix_b = _gbcells[ab]; + } + + GDST_STOREC(dst,pix_r,pix_g,pix_b); + } + + src += 3; + dst += GDST_INCR; + } + while (--w > 0); + + src_line += blit->src_pitch; + dst_line += blit->dst_pitch; + } + while (--h > 0); + + GBLENDER_CHANNEL_CLOSE(blender); + diff --git a/kernel/kls_ttf/ftview/gblvbgr.h b/kernel/kls_ttf/ftview/gblvbgr.h new file mode 100644 index 0000000..48565ff --- /dev/null +++ b/kernel/kls_ttf/ftview/gblvbgr.h @@ -0,0 +1,76 @@ + + GBLENDER_CHANNEL_VARS(blender,r,g,b); + + int h = blit->height; + const unsigned char* src_line = blit->src_line; + int src_pitch = blit->src_pitch; + unsigned char* dst_line = blit->dst_line; + + do + { + const unsigned char* src = src_line + blit->src_x; + unsigned char* dst = dst_line + blit->dst_x*GDST_INCR; + int w = blit->width; + + do + { + int ab = GBLENDER_SHADE_INDEX(src[0]); + int ag = GBLENDER_SHADE_INDEX(src[src_pitch]); + int ar = GBLENDER_SHADE_INDEX(src[src_pitch << 1]); + GBlenderPixel aa = ((GBlenderPixel)ar << 16) | (ag << 8) | ab; + + if ( aa == 0 ) + { + /* nothing */ + } + else if ( aa == ((GBLENDER_SHADE_COUNT << 16) | + (GBLENDER_SHADE_COUNT << 8) | + (GBLENDER_SHADE_COUNT) ) ) + { + GDST_COPY(dst); + } + else + { + GBlenderPixel back; + int pix_r, pix_g, pix_b; + + GDST_READ(dst,back); + + { + int back_r = (back >> 16) & 255; + + GBLENDER_LOOKUP_R( blender, back_r ); + + pix_r = _grcells[ar]; + } + + { + int back_g = (back >> 8) & 255; + + GBLENDER_LOOKUP_G( blender, back_g ); + + pix_g = _ggcells[ag]; + } + + { + int back_b = (back) & 255; + + GBLENDER_LOOKUP_B( blender, back_b ); + + pix_b = _gbcells[ab]; + } + + GDST_STOREC(dst,pix_r,pix_g,pix_b); + } + + src += 1; + dst += GDST_INCR; + } + while (--w > 0); + + src_line += blit->src_pitch*3; + dst_line += blit->dst_pitch; + } + while (--h > 0); + + GBLENDER_CHANNEL_CLOSE(blender); diff --git a/kernel/kls_ttf/ftview/gblvrgb.h b/kernel/kls_ttf/ftview/gblvrgb.h new file mode 100644 index 0000000..d31aaa9 --- /dev/null +++ b/kernel/kls_ttf/ftview/gblvrgb.h @@ -0,0 +1,76 @@ + + GBLENDER_CHANNEL_VARS(blender,r,g,b); + + int h = blit->height; + const unsigned char* src_line = blit->src_line; + int src_pitch = blit->src_pitch; + unsigned char* dst_line = blit->dst_line; + + do + { + const unsigned char* src = src_line + blit->src_x; + unsigned char* dst = dst_line + blit->dst_x*GDST_INCR; + int w = blit->width; + + do + { + int ar = GBLENDER_SHADE_INDEX(src[0]); + int ag = GBLENDER_SHADE_INDEX(src[src_pitch]); + int ab = GBLENDER_SHADE_INDEX(src[src_pitch << 1]); + GBlenderPixel aa = ((GBlenderPixel)ar << 16) | (ag << 8) | ab; + + if ( aa == 0 ) + { + /* nothing */ + } + else if ( aa == ((GBLENDER_SHADE_COUNT << 16) | + (GBLENDER_SHADE_COUNT << 8) | + (GBLENDER_SHADE_COUNT) ) ) + { + GDST_COPY(dst); + } + else + { + GBlenderPixel back; + int pix_r, pix_g, pix_b; + + GDST_READ(dst,back); + + { + int back_r = (back >> 16) & 255; + + GBLENDER_LOOKUP_R( blender, back_r ); + + pix_r = _grcells[ar]; + } + + { + int back_g = (back >> 8) & 255; + + GBLENDER_LOOKUP_G( blender, back_g ); + + pix_g = _ggcells[ag]; + } + + { + int back_b = (back) & 255; + + GBLENDER_LOOKUP_B( blender, back_b ); + + pix_b = _gbcells[ab]; + } + + GDST_STOREC(dst,pix_r,pix_g,pix_b); + } + + src += 1; + dst += GDST_INCR; + } + while (--w > 0); + + src_line += blit->src_pitch*3; + dst_line += blit->dst_pitch; + } + while (--h > 0); + + GBLENDER_CHANNEL_CLOSE(blender); diff --git a/kernel/kls_ttf/ftview/graph.h b/kernel/kls_ttf/ftview/graph.h new file mode 100644 index 0000000..81f1716 --- /dev/null +++ b/kernel/kls_ttf/ftview/graph.h @@ -0,0 +1,653 @@ +/*************************************************************************** + * + * graph.h + * + * Graphics Subsystem interface + * + * Copyright 1999, 2000, 2001, 2002 + * - The FreeType Development Team - www.freetype.org + * + ***************************************************************************/ + +#ifndef GRAPH_H +#define GRAPH_H + +#include "grevents.h" + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /******** ********/ + /******** GENERAL DEFINITIONS AND BLITTING ROUTINES ********/ + /******** ********/ + /******** ********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /* define the global error variable */ + extern int grError; + + /* initialisation */ + extern int grInit( void ); + + /* finalisation */ + extern void grDone( void ); + + + /* pixel mode constants */ + typedef enum grPixelMode + { + gr_pixel_mode_none = 0, + gr_pixel_mode_mono, /* monochrome bitmaps */ + gr_pixel_mode_pal4, /* 4-bit paletted - 16 colors */ + gr_pixel_mode_pal8, /* 8-bit paletted - 256 colors */ + gr_pixel_mode_gray, /* 8-bit gray levels */ + gr_pixel_mode_rgb555, /* 15-bits mode - 32768 colors */ + gr_pixel_mode_rgb565, /* 16-bits mode - 65536 colors */ + gr_pixel_mode_rgb24, /* 24-bits mode - 16 million colors */ + gr_pixel_mode_rgb32, /* 32-bits mode - 16 million colors */ + gr_pixel_mode_lcd, /* horizontal RGB-decimated */ + gr_pixel_mode_lcdv, /* vertical RGB-decimated */ + gr_pixel_mode_lcd2, /* horizontal BGR-decimated */ + gr_pixel_mode_lcdv2, /* vertical BGR-decimated */ + + gr_pixel_mode_max /* don't remove */ + + } grPixelMode; + + + /* forward declaration of the surface class */ + typedef struct grSurface_ grSurface; + + + /********************************************************************* + * + * <Struct> + * grBitmap + * + * <Description> + * a simple bitmap descriptor + * + * <Fields> + * rows :: height in pixels + * width :: width in pixels + * pitch :: + or - the number of bytes per row + * mode :: pixel mode of bitmap buffer + * grays :: number of grays in palette for PAL8 mode. 0 otherwise + * buffer :: pointer to pixel buffer + * + * <Note> + * the 'pitch' is positive for downward flows, and negative otherwise + * Its absolute value is always the number of bytes taken by each + * bitmap row. + * + * All drawing operations will be performed within the first + * "width" pixels of each row (clipping is always performed). + * + ********************************************************************/ + + typedef struct grBitmap_ + { + int rows; + int width; + int pitch; + grPixelMode mode; + int grays; + unsigned char* buffer; + + } grBitmap; + + + + typedef long grPos; + typedef char grBool; + + typedef struct grVector_ + { + grPos x; + grPos y; + + } grVector; + + + typedef union grColor_ + { + long value; + unsigned char chroma[4]; + + } grColor; + + + + /********************************************************************** + * + * <Function> + * grNewBitmap + * + * <Description> + * creates a new bitmap + * + * <Input> + * pixel_mode :: the target surface's pixel_mode + * num_grays :: number of grays levels for PAL8 pixel mode + * width :: width in pixels + * height :: height in pixels + * + * <Output> + * bit :: descriptor of the new bitmap + * + * <Return> + * Error code. 0 means success. + * + * <Note> + * This function really allocates a pixel buffer, zero it, then + * returns a descriptor for it. + * + * Call grDoneBitmap when you're done with it.. + * + **********************************************************************/ + + extern int grNewBitmap( grPixelMode pixel_mode, + int num_grays, + int width, + int height, + grBitmap *bit ); + + + /********************************************************************** + * + * <Function> + * grBlitGlyphToBitmap + * + * <Description> + * writes a given glyph bitmap to a target surface. + * + * <Input> + * target :: handle to target bitmap + * glyph :: handle to source glyph bitmap + * x :: position of left-most pixel of glyph image in target surface + * y :: position of top-most pixel of glyph image in target surface + * color :: color to be used to draw a monochrome glyph + * + * <Return> + * Error code. 0 means success + * + * <Note> + * There are only two supported source pixel modes : monochrome + * and gray. The 8-bit images can have any number of grays between + * 2 and 128, and conversions to the target surface is handled + * _automatically_. + * + * Note however that you should avoid blitting a gray glyph to a gray + * bitmap with fewer levels of grays, as this would much probably + * give unpleasant results.. + * + * This function performs clipping + * + **********************************************************************/ + + extern int + grBlitGlyphToBitmap( grBitmap* target, + grBitmap* glyph, + grPos x, + grPos y, + grColor color ); + + + /********************************************************************** + * + * <Function> + * grFillRectangle + * + * <Description> + * this function is used to fill a given rectangle on a surface + * + * <Input> + * surface :: handle to target surface + * x :: x coordinate of the top-left corner of the rectangle + * y :: y coordinate of the top-left corner of the rectangle + * width :: rectangle width in pixels + * height :: rectangle height in pixels + * color :: fill color + * + **********************************************************************/ + + extern void grFillRectangle( grBitmap* surface, + grPos x, + grPos y, + grPos width, + grPos height, + grColor color ); + + + + /********************************************************************** + * + * <Function> + * grWriteCellChar + * + * <Description> + * The graphics sub-system contains an internal Latin1 8x8 font + * which can be used to display simple strings of text without + * using FreeType. + * + * This function writes a single 8x8 character on the target bitmap. + * + * <Input> + * target :: handle to target surface + * x :: x pixel position of character cell's top left corner + * y :: y pixel position of character cell's top left corner + * charcode :: Latin-1 character code + * color :: color to be used to draw the character + * + **********************************************************************/ + + extern + void grWriteCellChar( grBitmap* target, + int x, + int y, + int charcode, + grColor color ); + + + /********************************************************************** + * + * <Function> + * grWriteCellString + * + * <Description> + * The graphics sub-system contains an internal Latin1 8x8 font + * which can be used to display simple strings of text without + * using FreeType. + * + * This function writes a string with the internal font + * + * <Input> + * target :: handle to target bitmap + * x :: x pixel position of string's top left corner + * y :: y pixel position of string's top left corner + * string :: Latin-1 text string + * color :: color to be used to draw the character + * + **********************************************************************/ + + extern + void grWriteCellString( grBitmap* target, + int x, + int y, + const char* string, + grColor color ); + + /********************************************************************** + * + * <Function> + * grDoneBitmap + * + * <Description> + * destroys a bitmap + * + * <Input> + * bitmap :: handle to bitmap descriptor + * + * <Note> + * This function does NOT release the bitmap descriptor, only + * the pixel buffer. + * + **********************************************************************/ + + extern void grDoneBitmap( grBitmap* bit ); + + + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /******** ********/ + /******** DEVICE-SPECIFIC DEFINITIONS AND ROUTINES ********/ + /******** ********/ + /******** ********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /* forward declaration - the definition of grDevice is not visible */ + /* to clients.. */ + typedef struct grDevice_ grDevice; + + + /********************************************************************** + * + * <Struct> + * grDeviceChain + * + * <Description> + * a simple structure used to implement a linked list of + * graphics device descriptors. The list is called a + * "device chain" + * + * <Fields> + * name :: ASCII name of the device, e.g. "x11", "os2pm", etc.. + * device :: handle to the device descriptor. + * next :: next element in chain + * + * <Note> + * the 'device' field is a blind pointer; it is thus unusable by + * client applications.. + * + **********************************************************************/ + + typedef struct grDeviceChain_ grDeviceChain; + + struct grDeviceChain_ + { + const char* name; + grDevice* device; + grDeviceChain* next; + }; + + + /********************************************************************** + * + * <Function> + * grInitDevices + * + * <Description> + * This function is in charge of initialising all system-specific + * devices. A device is responsible for creating and managing one + * or more "surfaces". A surface is either a window or a screen, + * depending on the system. + * + * <Return> + * a pointer to the first element of a device chain. The chain can + * be parsed to find the available devices on the current system + * + * <Note> + * If a device cannot be initialised correctly, it is not part of + * the device chain returned by this function. For example, if an + * X11 device was compiled in the library, it will be part of + * the returned device chain only if a connection to the display + * could be establisged + * + * If no driver could be initialised, this function returns NULL. + * + **********************************************************************/ + + extern + grDeviceChain* grInitDevices( void ); + + + + /********************************************************************** + * + * <Function> + * grGetDeviceModes + * + * <Description> + * queries the available pixel modes for a device. + * + * <Input> + * device_name :: name of device to be used. 0 for the default + * device. For a list of available devices, see + * grInitDevices. + * + * <Output> + * num_modes :: number of available modes. 0 in case of error, + * which really is an invalid device name. + * + * pixel_modes :: array of available pixel modes for this device + * this table is internal to the device and should + * not be freed by client applications. + * + * <Return> + * error code. 0 means success. invalid device name otherwise + * + * <Note> + * All drivers are _required_ to support at least the following + * pixel formats : + * + * - gr_pixel_mode_mono : i.e. monochrome bitmaps + * - gr_pixel_mode_gray : with any number of gray levels between + * 2 and 256. + * + * the pixel modes do not provide the number of grays in the case + * of "gray" devices. You should try to create a surface with the + * maximal number (256, that is) and see the value returned in + * the bitmap descriptor. + * + **********************************************************************/ + + extern void grGetDeviceModes( const char* device_name, + int *num_modes, + grPixelMode* *pixel_modes ); + + + + /********************************************************************** + * + * <Function> + * grNewSurface + * + * <Description> + * creates a new device-specific surface. A surface is either + * a window or a screen, depending on the device. + * + * <Input> + * device :: name of the device to use. A value of NULL means + * the default device (which depends on the system). + * for a list of available devices, see grInitDevices. + * + * <InOut> + * bitmap :: handle to a bitmap descriptor containing the + * requested pixel mode, number of grays and dimensions + * for the surface. the bitmap's 'pitch' and 'buffer' + * fields are ignored on input. + * + * On output, the bitmap describes the surface's image + * completely. It is possible to write directly in it + * with grBlitGlyphToBitmap, even though the use of + * grBlitGlyphToSurface is recommended. + * + * <Return> + * handle to the corresponding surface object. 0 in case of error + * + * <Note> + * All drivers are _required_ to support at least the following + * pixel formats : + * + * - gr_pixel_mode_mono : i.e. monochrome bitmaps + * - gr_pixel_mode_gray : with any number of gray levels between + * 2 and 256. + * + * This function might change the bitmap descriptor's fields. For + * example, when displaying a full-screen surface, the bitmap's + * dimensions will be set to those of the screen (e.g. 640x480 + * or 800x600); also, the bitmap's 'buffer' field might point to + * the Video Ram depending on the mode requested.. + * + * The surface contains a copy of the returned bitmap descriptor, + * you can thus discard the 'bitmap' parameter after the call. + * + **********************************************************************/ + + extern grSurface* grNewSurface( const char* device, + grBitmap* bitmap ); + + + + /********************************************************************** + * + * <Function> + * grRefreshRectangle + * + * <Description> + * this function is used to indicate that a given surface rectangle + * was modified and thus needs re-painting. It really is useful for + * windowed or gray surfaces. + * + * <Input> + * surface :: handle to target surface + * x :: x coordinate of the top-left corner of the rectangle + * y :: y coordinate of the top-left corner of the rectangle + * width :: rectangle width in pixels + * height :: rectangle height in pixels + * + **********************************************************************/ + + extern void grRefreshRectangle( grSurface* surface, + grPos x, + grPos y, + grPos width, + grPos height ); + + + /********************************************************************** + * + * <Function> + * grRefreshSurface + * + * <Description> + * a variation of grRefreshRectangle which repaints the whole surface + * to the screen. + * + * <Input> + * surface :: handle to target surface + * + **********************************************************************/ + + extern void grRefreshSurface( grSurface* surface ); + + + + /********************************************************************** + * + * <Function> + * grWriteSurfaceChar + * + * <Description> + * This function is equivalent to calling grWriteCellChar on the + * surface's bitmap, then invoking grRefreshRectangle. + * + * The graphics sub-system contains an internal Latin1 8x8 font + * which can be used to display simple strings of text without + * using FreeType. + * + * This function writes a single 8x8 character on the target bitmap. + * + * <Input> + * target :: handle to target surface + * x :: x pixel position of character cell's top left corner + * y :: y pixel position of character cell's top left corner + * charcode :: Latin-1 character code + * color :: color to be used to draw the character + * + **********************************************************************/ + + extern + void grWriteSurfaceChar( grSurface* target, + int x, + int y, + int charcode, + grColor color ); + + + /********************************************************************** + * + * <Function> + * grWriteSurfaceString + * + * <Description> + * This function is equivalent to calling grWriteCellString on the + * surface's bitmap, then invoking grRefreshRectangle. + * + * The graphics sub-system contains an internal Latin1 8x8 font + * which can be used to display simple strings of text without + * using FreeType. + * + * This function writes a string with the internal font + * + * <Input> + * target :: handle to target bitmap + * x :: x pixel position of string's top left corner + * y :: y pixel position of string's top left corner + * string :: Latin-1 text string + * color :: color to be used to draw the character + * + **********************************************************************/ + + extern + void grWriteSurfaceString( grSurface* target, + int x, + int y, + const char* string, + grColor color ); + + + /********************************************************************** + * + * <Function> + * grSetTitle + * + * <Description> + * set the window title of a given windowed surface. + * + * <Input> + * surface :: handle to target surface + * title_string :: the new title + * + **********************************************************************/ + + extern void grSetTitle( grSurface* surface, + const char* title_string ); + + + + + /********************************************************************** + * + * <Function> + * grListenSurface + * + * <Description> + * listen the events for a given surface + * + * <Input> + * surface :: handle to target surface + * event_mask :: the event mask (mode) + * + * <Output> + * event :: the returned event + * + * <Note> + * XXX : For now, only keypresses are supported. + * + **********************************************************************/ + + extern + int grListenSurface( grSurface* surface, + int event_mask, + grEvent *event ); + + /********************************************************************** + * + * <Function> + * grSetGlyphGamma + * + * <Description> + * set the gamma-correction coefficient. This is only used to + * blit glyphs + * + * <Input> + * gamma :: gamma value. <= 0 to select sRGB transfer function + * + **********************************************************************/ + + extern + void grSetGlyphGamma( double gamma_value ); + +/* */ + +#endif /* GRAPH_H */ diff --git a/kernel/kls_ttf/ftview/grblit.cpp b/kernel/kls_ttf/ftview/grblit.cpp new file mode 100644 index 0000000..18046ab --- /dev/null +++ b/kernel/kls_ttf/ftview/grblit.cpp @@ -0,0 +1,2068 @@ +/****************************************************************************/ +/* */ +/* The FreeType project -- a free and portable quality TrueType renderer. */ +/* */ +/* Copyright 1996-1999, 2000, 2001, 2002 by */ +/* D. Turner, R.Wilhelm, and W. Lemberg */ +/* */ +/* grblit.c: Support for blitting of bitmaps with various depth. */ +/* */ +/****************************************************************************/ + +#include "grblit.h" +#include "grobjs.h" + +#include <stdio.h> + +#define GRAY8 + + static + int compute_clips( grBlitter* blit, + int x_offset, + int y_offset ) + { + int xmin, ymin, xmax, ymax, width, height, target_width; + + /* perform clipping and setup variables */ + width = blit->source.width; + height = blit->source.rows; + + switch ( blit->source.mode ) + { + case gr_pixel_mode_mono: + width = (width + 7) & -8; + break; + + case gr_pixel_mode_pal4: + width = (width + 1) & -2; + break; + + case gr_pixel_mode_lcd: + case gr_pixel_mode_lcd2: + width /= 3; + break; + + case gr_pixel_mode_lcdv: + case gr_pixel_mode_lcdv2: + height /= 3; + break; + + default: + ; + } + + xmin = x_offset; + ymin = y_offset; + xmax = xmin + width-1; + ymax = ymin + height-1; + + /* clip if necessary */ + if ( width == 0 || height == 0 || + xmax < 0 || xmin >= blit->target.width || + ymax < 0 || ymin >= blit->target.rows ) + return 1; + + /* set up clipping and cursors */ + blit->yread = 0; + if ( ymin < 0 ) + { + blit->yread -= ymin; + height += ymin; + blit->ywrite = 0; + } + else + blit->ywrite = ymin; + + if ( ymax >= blit->target.rows ) + height -= ymax - blit->target.rows + 1; + + blit->xread = 0; + if ( xmin < 0 ) + { + blit->xread -= xmin; + width += xmin; + blit->xwrite = 0; + } + else + blit->xwrite = xmin; + + target_width = blit->target.width; + + switch ( blit->target.mode ) + { + case gr_pixel_mode_mono: + target_width = (target_width + 7) & -8; + break; + case gr_pixel_mode_pal4: + target_width = (target_width + 1) & -2; + break; + + default: + ; + } + + blit->right_clip = xmax - target_width + 1; + if ( blit->right_clip > 0 ) + width -= blit->right_clip; + else + blit->right_clip = 0; + + blit->width = width; + blit->height = height; + + /* set read and write to the top-left corner of the read */ + /* and write areas before clipping. */ + + blit->read = blit->source.buffer; + blit->write = blit->target.buffer; + + blit->read_line = blit->source.pitch; + blit->write_line = blit->target.pitch; + + if ( blit->read_line < 0 ) + blit->read -= (blit->source.rows-1) * blit->read_line; + + if ( blit->write_line < 0 ) + blit->write -= (blit->target.rows-1) * blit->write_line; + + /* now go to the start line. Note that we do not move the */ + /* x position yet, as this is dependent on the pixel format */ + blit->read += blit->yread * blit->read_line; + blit->write += blit->ywrite * blit->write_line; + + return 0; + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_mono_to_mono */ +/* */ +/**************************************************************************/ + + static + void blit_mono_to_mono( grBlitter* blit, + grColor color ) + { + int shift, left_clip, x, y; + byte* read; + byte* write; + + (void)color; /* unused argument */ + + left_clip = ( blit->xread > 0 ); + shift = ( blit->xwrite - blit->xread ) & 7; + + read = blit->read + (blit->xread >> 3); + write = blit->write + (blit->xwrite >> 3); + + if ( shift == 0 ) + { + y = blit->height; + do + { + byte* _read = read; + byte* _write = write; + + x = blit->width; + + do + { + *_write++ |= *_read++; + x -= 8; + } while ( x > 0 ); + + read += blit->read_line; + write += blit->write_line; + y--; + } while ( y > 0 ); + } + else + { + int first, last, count; + + + first = blit->xwrite >> 3; + last = (blit->xwrite + blit->width-1) >> 3; + + count = last - first; + + if ( blit->right_clip ) + count++; + + y = blit->height; + + do + { + unsigned char* _read = read; + unsigned char* _write = write; + unsigned int old; + int shift2 = (8-shift); + + if ( left_clip ) + old = (*_read++) << shift2; + else + old = 0; + + x = count; + while ( x > 0 ) + { + unsigned char val; + + val = *_read++; + *_write++ |= (unsigned char)( (val >> shift) | old ); + old = val << shift2; + x--; + } + + if ( !blit->right_clip ) + *_write |= (unsigned char)old; + + read += blit->read_line; + write += blit->write_line; + y--; + + } while ( y > 0 ); + } + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_mono_to_pal8 */ +/* */ +/**************************************************************************/ + + static + void blit_mono_to_pal8( grBlitter* blit, + grColor color ) + { + int x, y, shift; + unsigned char* read; + unsigned char* write; + + read = blit->read + (blit->xread >> 3); + write = blit->write + blit->xwrite; + shift = blit->xread & 7; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + unsigned long val = (*_read++ | 0x100) << shift; + + x = blit->width; + do + { + if (val & 0x10000) + val = *_read++ | 0x100; + + if ( val & 0x80 ) + *_write = (unsigned char)color.value; + + val <<= 1; + _write++; + + } while ( --x > 0 ); + + read += blit->read_line; + write += blit->write_line; + y--; + } while ( y > 0 ); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_mono_to_pal4 */ +/* */ +/**************************************************************************/ + + static + void blit_mono_to_pal4( grBlitter* blit, + grColor color ) + { + int x, y, phase,shift; + unsigned char* read; + unsigned char* write; + unsigned int col; + + + col = color.value & 15; + read = blit->read + (blit->xread >> 3); + write = blit->write + (blit->xwrite >> 1); + + /* now begin blit */ + shift = blit->xread & 7; + phase = blit->xwrite & 1; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int _phase = phase; + unsigned long val = (*_read++ | 0x100) << shift; + + x = blit->width; + do + { + if (val & 0x10000) + val = *_read++ | 0x100; + + if ( val & 0x80 ) + { + if ( _phase ) + *_write = (unsigned char)((*_write & 0xF0) | col); + else + *_write = (unsigned char)((*_write & 0x0F) | (col << 4)); + } + + val <<= 1; + + _write += _phase; + _phase ^= 1; + x--; + } while ( x > 0 ); + + read += blit->read_line; + write += blit->write_line; + y--; + } while ( y > 0 ); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_mono_to_rgb16 */ +/* */ +/**************************************************************************/ + + static + void blit_mono_to_rgb16( grBlitter* blit, + grColor color ) + { + int x, y,shift; + unsigned char* read; + unsigned char* write; + + read = blit->read + (blit->xread >> 3); + write = blit->write + blit->xwrite*2; + shift = blit->xread & 7; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + unsigned long val = (*_read++ | 0x100) << shift; + + x = blit->width; + do + { + if (val & 0x10000) + val = *_read++ | 0x100; + + if ( val & 0x80 ) + *(short*)_write = (short)color.value; + + val <<= 1; + _write +=2; + x--; + } while ( x > 0 ); + + read += blit->read_line; + write += blit->write_line; + y--; + } while ( y > 0 ); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_mono_to_rgb24 */ +/* */ +/**************************************************************************/ + + static + void blit_mono_to_rgb24( grBlitter* blit, + grColor color ) + { + int x, y, shift; + unsigned char* read; + unsigned char* write; + + read = blit->read + (blit->xread >> 3); + write = blit->write + blit->xwrite*3; + shift = blit->xread & 7; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + unsigned long val = (*_read++ | 0x100) << shift; + + x = blit->width; + do + { + if (val & 0x10000) + val = *_read++ | 0x100; + + if ( val & 0x80 ) + { + _write[0] = color.chroma[0]; + _write[1] = color.chroma[1]; + _write[2] = color.chroma[2]; + } + + val <<= 1; + _write += 3; + x--; + } while ( x > 0 ); + + read += blit->read_line; + write += blit->write_line; + y--; + } while ( y > 0 ); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_mono_to_rgb32 */ +/* */ +/**************************************************************************/ + + static + void blit_mono_to_rgb32( grBlitter* blit, + grColor color ) + { + int x, y,shift; + unsigned char* read; + unsigned char* write; + + read = blit->read + ( blit->xread >> 3 ); + write = blit->write + blit->xwrite*4; + shift = blit->xread & 7; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + unsigned long val = ( *_read++ | 0x100L ) << shift; + + x = blit->width; + do + { + if ( val & 0x10000 ) + val = *_read++ | 0x100L; + + if ( val & 0x80 ) + { + /* this could be greatly optimized as */ + /* */ + /* *(long*)_write = color.value */ + /* */ + /* but it wouldn't work on 64-bits systems... stupid C types! */ + _write[0] = color.chroma[0]; + _write[1] = color.chroma[1]; + _write[2] = color.chroma[2]; + _write[3] = color.chroma[3]; + } + + val <<= 1; + _write += 4; + x--; + + } while ( x > 0 ); + + read += blit->read_line; + write += blit->write_line; + y--; + + } while ( y > 0 ); + } + + + static + const grBlitterFunc gr_mono_blitters[gr_pixel_mode_max] = + { + 0, + blit_mono_to_mono, + blit_mono_to_pal4, + blit_mono_to_pal8, + blit_mono_to_pal8, + blit_mono_to_rgb16, + blit_mono_to_rgb16, + blit_mono_to_rgb24, + blit_mono_to_rgb32 + }; + + + /*******************************************************************/ + /* */ + /* Saturation tables */ + /* */ + /*******************************************************************/ + + typedef struct grSaturation_ + { + int count; + const byte* table; + + } grSaturation; + + + static + const byte gr_saturation_5[8] = { 0, 1, 2, 3, 4, 4, 4, 4 }; + + + static + const byte gr_saturation_17[32] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }; + + + static + grSaturation gr_saturations[ GR_MAX_SATURATIONS ] = + { + { 5, gr_saturation_5 }, + { 17, gr_saturation_17 } + }; + + static + int gr_num_saturations = 2; + + static + grSaturation* gr_last_saturation = gr_saturations; + + + extern + const byte* grGetSaturation( int num_grays ) + { + /* first of all, scan the current saturations table */ + grSaturation* sat = gr_saturations; + grSaturation* limit = sat + gr_num_saturations; + + if ( num_grays < 2 ) + { + grError = gr_err_bad_argument; + return 0; + } + + for ( ; sat < limit; sat++ ) + { + if ( sat->count == num_grays ) + { + gr_last_saturation = sat; + return sat->table; + } + } + + /* not found, simply create a new entry if there is room */ + if (gr_num_saturations < GR_MAX_SATURATIONS) + { + int i; + const byte* table; + + table = (const byte*)grAlloc( (3*num_grays-1)*sizeof(byte) ); + if (!table) return 0; + + sat->count = num_grays; + sat->table = table; + + for ( i = 0; i < num_grays; i++, table++ ) + *(unsigned char*)table = (unsigned char)i; + + for ( i = 2*num_grays-1; i > 0; i--, table++ ) + *(unsigned char*)table = (unsigned char)(num_grays-1); + + gr_num_saturations++; + gr_last_saturation = sat; + return sat->table; + } + grError = gr_err_saturation_overflow; + return 0; + } + + + + /*******************************************************************/ + /* */ + /* conversion tables */ + /* */ + /*******************************************************************/ + + typedef struct grConversion_ + { + int target_grays; + int source_grays; + const byte* table; + + } grConversion; + + + + static + const byte gr_gray5_to_gray17[5] = { 0, 4, 8, 12, 16 }; + + + static + const byte gr_gray5_to_gray128[5] = { 0, 32, 64, 96, 127 }; + + + static + const unsigned char gr_gray17_to_gray128[17] = + { + 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 127 + }; + + static + grConversion gr_conversions[ GR_MAX_CONVERSIONS ] = + { + { 17, 5, gr_gray5_to_gray17 }, + { 128, 5, gr_gray5_to_gray128 }, + { 128, 17, gr_gray17_to_gray128 } + }; + + static + int gr_num_conversions = 3; + + static + grConversion* gr_last_conversion = gr_conversions; + + + extern + const byte* grGetConversion( int target_grays, + int source_grays ) + { + grConversion* conv = gr_conversions; + grConversion* limit = conv + gr_num_conversions; + + if ( target_grays < 2 || source_grays < 2 ) + { + grError = gr_err_bad_argument; + return 0; + } + + /* otherwise, scan table */ + for ( ; conv < limit; conv++ ) + { + if ( conv->target_grays == target_grays && + conv->source_grays == source_grays ) + { + gr_last_conversion = conv; + return conv->table; + } + } + + /* not found, add a new conversion to the table */ + if (gr_num_conversions < GR_MAX_CONVERSIONS) + { + const byte* table; + int n; + + table = (const byte*)grAlloc( source_grays*sizeof(byte) ); + if (!table) + return 0; + + conv->target_grays = target_grays; + conv->source_grays = source_grays; + conv->table = table; + + for ( n = 0; n < source_grays; n++ ) + ((unsigned char*)table)[n] = (unsigned char)(n*(target_grays-1) / + (source_grays-1)); + + gr_num_conversions++; + gr_last_conversion = conv; + return table; + } + grError = gr_err_conversion_overflow; + return 0; + } + + + + +/**************************************************************************/ +/* */ +/* <Function> blit_gray_to_gray */ +/* */ +/**************************************************************************/ + + static + void blit_gray_to_gray( grBlitter* blit, + const byte* saturation, + const byte* conversion ) + { + int y; + unsigned char* read; + unsigned char* write; + unsigned char max1; + unsigned char max2; + + max1 = (unsigned char)(blit->source.grays-1); + max2 = (unsigned char)(blit->target.grays-1); + + read = blit->read + blit->xread; + write = blit->write + blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { +#ifdef GR_CONFIG_GRAY_SKIP_WHITE + unsigned char val = *_read; + + if (val) + { + if (val == max) + *_write = max2; + else + *_write = saturation[ (int)*_write + conversion[ *_read ] ]; + } +#else + *_write = saturation[ (int)*_write + conversion[ *_read ] ]; +#endif + _write++; + _read++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_gray_to_gray_simple */ +/* */ +/**************************************************************************/ + + static + void blit_gray_to_gray_simple( grBlitter* blit, + const byte* saturation ) + { + int y; + unsigned char* read; + unsigned char* write; + unsigned char max; + + max = (unsigned char)(blit->source.grays-1); + + read = blit->read + blit->xread; + write = blit->write + blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { +#ifdef GR_CONFIG_GRAY_SKIP_WHITE + unsigned char val = *_read; + + if (val) + { + if (val == max) + *_write = val; + else + *_write = saturation[ (int)*_write + *_read ]; + } +#else + *_write = saturation[ (int)*_write + *_read ]; +#endif + _write++; + _read++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + + +#define compose_pixel_full( a, b, n0, n1, n2, max ) \ + { \ + int d, half = max >> 1; \ + \ + \ + d = (int)b.chroma[0] - a.chroma[0]; \ + a.chroma[0] += (unsigned char)((n0*d + half)/max); \ + \ + d = (int)b.chroma[1] - a.chroma[1]; \ + a.chroma[1] += (unsigned char)((n1*d + half)/max); \ + \ + d = (int)b.chroma[2] - a.chroma[2]; \ + a.chroma[2] += (unsigned char)((n2*d + half)/max); \ + } + +#define compose_pixel( a, b, n, max ) \ + compose_pixel_full( a, b, n, n, n, max ) + + +#define extract555( pixel, color ) \ + color.chroma[0] = (unsigned char)((pixel >> 10) & 0x1F); \ + color.chroma[1] = (unsigned char)((pixel >> 5) & 0x1F); \ + color.chroma[2] = (unsigned char)((pixel ) & 0x1F); + + +#define extract565( pixel, color ) \ + color.chroma[0] = (unsigned char)((pixel >> 11) & 0x1F); \ + color.chroma[1] = (unsigned char)((pixel >> 5) & 0x3F); \ + color.chroma[2] = (unsigned char)((pixel ) & 0x1F); + + +#define inject555( color ) \ + ( ( (unsigned short)color.chroma[0] << 10 ) | \ + ( (unsigned short)color.chroma[1] << 5 ) | \ + color.chroma[2] ) + + +#define inject565( color ) \ + ( ( (unsigned short)color.chroma[0] << 11 ) | \ + ( (unsigned short)color.chroma[1] << 5 ) | \ + color.chroma[2] ) + + +/**************************************************************************/ +/* */ +/* <Function> blit_gray_to_555 */ +/* */ +/**************************************************************************/ + +#ifdef GRAY8 + static + void blit_gray8_to_555( grBlitter* blit, + grColor color ) + { + int y; + int sr = (color.chroma[0] << 8) & 0x7C00; + int sg = (color.chroma[1] << 2) & 0x03E0; + int sb = (color.chroma[2] ) & 0x001F; + unsigned char* read; + unsigned char* write; + long color2; + + read = blit->read + blit->xread; + write = blit->write + 2*blit->xwrite; + + color2 = color.value; + extract565( color2, color ); + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val; + + val = *_read; + if (val) + { + unsigned short* pixel = (unsigned short*)_write; + + if (val >= 254 ) + { + pixel[0] = (short)color2; + } + else if ( val >= 2 ) + { + /* compose gray value */ + int pix = (int)*pixel; + int dr = pix & 0x7C00; + int dg = pix & 0x03E0; + int db = pix & 0x001F; + + dr = pix & 0x7C00; + dr += ((sr-dr)*val) >> 8; + dr &= 0xF800; + + dg = pix & 0x03E0; + dg += ((sg-dg)*val) >> 8; + dg &= 0x7E0; + + db = pix & 0x001F; + db += ((sb-db)*val) >> 8; + db += 0x001F; + + *pixel = (short)( dr | dg | db ); + } + } + _write +=2; + _read ++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + + } +#endif /* GRAY8 */ + + static + void blit_gray_to_555( grBlitter* blit, + grColor color, + int max ) + { + int y; + unsigned char* read; + unsigned char* write; + long color2; + + read = blit->read + blit->xread; + write = blit->write + 2*blit->xwrite; + + /* convert color to R:G:B triplet */ + color2 = color.value; + extract555( color2, color ); + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val; + + val = *_read; + if (val) + { + unsigned short* pixel = (unsigned short*)_write; + + if (val == max) + { + pixel[0] = (short)color2; + } + else + { + /* compose gray value */ + unsigned short pix16 = *pixel; + grColor pix; + + extract555( pix16, pix ); + + compose_pixel( pix, color, val, max ); + *pixel = (unsigned short)(inject555(pix)); + } + } + _write += 2; + _read ++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_gray_to_565 */ +/* */ +/**************************************************************************/ + +#ifdef GRAY8 + static + void blit_gray8_to_565( grBlitter* blit, + grColor color ) + { + int y; + int sr = (color.chroma[0] << 8) & 0xF800; + int sg = (color.chroma[1] << 2) & 0x07E0; + int sb = (color.chroma[2] ) & 0x001F; + unsigned char* read; + unsigned char* write; + long color2; + + read = blit->read + blit->xread; + write = blit->write + 2*blit->xwrite; + + color2 = color.value; + extract565( color2, color ); + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val; + + val = *_read; + if (val) + { + unsigned short* pixel = (unsigned short*)_write; + + if (val >= 254 ) + { + pixel[0] = (short)color2; + } + else if ( val >= 2 ) + { + /* compose gray value */ + int pix = (int)*pixel; + int dr = pix & 0xF800; + int dg = pix & 0x07E0; + int db = pix & 0x001F; + + dr = pix & 0xF800; + dr += ((sr-dr)*val) >> 8; + dr &= 0xF800; + + dg = pix & 0x07E0; + dg += ((sg-dg)*val) >> 8; + dg &= 0x7E0; + + db = pix & 0x001F; + db += ((sb-db)*val) >> 8; + db += 0x001F; + + *pixel = (short)( dr | dg | db ); + } + } + _write +=2; + _read ++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } +#endif + + static + void blit_gray_to_565( grBlitter* blit, + grColor color, + int max ) + { + int y; + unsigned char* read; + unsigned char* write; + long color2; + + read = blit->read + blit->xread; + write = blit->write + 2*blit->xwrite; + + color2 = color.value; + extract565( color2, color ); + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val; + + val = *_read; + if (val) + { + unsigned short* pixel = (unsigned short*)_write; + + if (val == max) + { + pixel[0] = (short)color2; + } + else + { + /* compose gray value */ + unsigned short pix16 = *pixel; + grColor pix; + + extract565( pix16, pix ); + + compose_pixel( pix, color, val, max ); + *pixel = (short)inject565( pix ); + } + } + _write +=2; + _read ++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_gray_to_24 */ +/* */ +/**************************************************************************/ + +#ifdef GRAY8 + static void + blit_gray8_to_24( grBlitter* blit, + grColor color ) + { + int y; + int sr = color.chroma[0]; + int sg = color.chroma[1]; + int sb = color.chroma[2]; + unsigned char* read; + unsigned char* write; + + read = blit->read + blit->xread; + write = blit->write + 3*blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val; + + val = *_read; + if (val) + { + if (val >= 254) + { + _write[0] = (unsigned char)sr; + _write[1] = (unsigned char)sg; + _write[2] = (unsigned char)sb; + } + else if ( val >= 2 ) + { + int dr = _write[0]; + int dg = _write[1]; + int db = _write[2]; + + dr += ((sr-dr)*val) >> 8; + dg += ((sg-dg)*val) >> 8; + db += ((sb-db)*val) >> 8; + + _write[0] = (unsigned char)dr; + _write[1] = (unsigned char)dg, + _write[2] = (unsigned char)db; + } + } + _write += 3; + _read ++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } +#endif /* GRAY8 */ + + + static + void blit_gray_to_24( grBlitter* blit, + grColor color, + int max ) + { + int y; + unsigned char* read; + unsigned char* write; + + read = blit->read + blit->xread; + write = blit->write + 3*blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val; + + val = *_read; + if (val) + { + if (val == max) + { + _write[0] = color.chroma[0]; + _write[1] = color.chroma[1]; + _write[2] = color.chroma[2]; + } + else + { + /* compose gray value */ + grColor pix; + + pix.chroma[0] = _write[0]; + pix.chroma[1] = _write[1]; + pix.chroma[2] = _write[2]; + + compose_pixel( pix, color, val, max ); + + _write[0] = pix.chroma[0]; + _write[1] = pix.chroma[1]; + _write[2] = pix.chroma[2]; + } + } + _write += 3; + _read ++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_gray_to_32 */ +/* */ +/**************************************************************************/ + + static + void blit_gray_to_32( grBlitter* blit, + grColor color, + int max ) + { + int y; + unsigned char* read; + unsigned char* write; + + read = blit->read + blit->xread; + write = blit->write + 4*blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val; + + val = *_read; + if (val) + { + if (val == max) + { + _write[0] = color.chroma[0]; + _write[1] = color.chroma[1]; + _write[2] = color.chroma[2]; + _write[3] = color.chroma[3]; + } + else + { + /* compose gray value */ + grColor pix; + + pix.chroma[0] = _write[0]; + pix.chroma[1] = _write[1]; + pix.chroma[2] = _write[2]; + + compose_pixel( pix, color, val, max ); + + _write[0] = pix.chroma[0]; + _write[1] = pix.chroma[1]; + _write[2] = pix.chroma[2]; + } + } + _write += 4; + _read ++; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + + static + void blit_gray8_to_32( grBlitter* blit, + grColor color ) + { + blit_gray_to_32( blit, color, 255 ); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_lcd_to_24 */ +/* */ +/**************************************************************************/ + +#ifdef GRAY8 + static void + blit_lcd8_to_24( grBlitter* blit, + grColor color ) + { + int y; + int sr = color.chroma[0]; + int sg = color.chroma[1]; + int sb = color.chroma[2]; + unsigned char* read; + unsigned char* write; + + read = blit->read + 3*blit->xread; + write = blit->write + 3*blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + int val0, val1, val2; + + val0 = _read[0]; + val1 = _read[1]; + val2 = _read[2]; + + if ( val0 | val1 | val2 ) + { + if ( val0 == val1 && + val0 == val2 && + val0 == 255 ) + { + _write[0] = (unsigned char)sr; + _write[1] = (unsigned char)sg; + _write[2] = (unsigned char)sb; + } + else + { + /* compose gray value */ + int dr, dg, db; + + dr = _write[0]; + dr += (sr-dr)*val0 >> 8; + + dg = _write[1]; + dg += (sg-dg)*val1 >> 8; + + db = _write[1]; + db += (sb-db)*val2 >> 8; + + _write[0] = dr; + _write[1] = dg; + _write[2] = db; + } + } + _write += 3; + _read += 3; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } +#endif /* GRAY8 */ + + static void + blit_lcd_to_24( grBlitter* blit, + grColor color, + int max ) + { + int y; + unsigned char* read; + unsigned char* write; + + read = blit->read + 3*blit->xread; + write = blit->write + 3*blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + int val0, val1, val2; + + val0 = _read[0]; + val1 = _read[1]; + val2 = _read[2]; + + if ( val0 | val1 | val2 ) + { + if ( val0 == val1 && + val0 == val2 && + val0 == max ) + { + _write[0] = color.chroma[0]; + _write[1] = color.chroma[1]; + _write[2] = color.chroma[2]; + } + else + { + /* compose gray value */ + grColor pix; + + pix.chroma[0] = _write[0]; + pix.chroma[1] = _write[1]; + pix.chroma[2] = _write[2]; + + compose_pixel_full( pix, color, val0, val1, val2, max ); + + _write[0] = pix.chroma[0]; + _write[1] = pix.chroma[1]; + _write[2] = pix.chroma[2]; + } + } + _write += 3; + _read += 3; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + +#ifdef GRAY8 + static void + blit_lcd28_to_24( grBlitter* blit, + grColor color ) + { + int y; + int sr = color.chroma[0]; + int sg = color.chroma[1]; + int sb = color.chroma[2]; + unsigned char* read; + unsigned char* write; + + read = blit->read + 3*blit->xread; + write = blit->write + 3*blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + int val0, val1, val2; + + val0 = _read[2]; + val1 = _read[1]; + val2 = _read[0]; + + if ( val0 | val1 | val2 ) + { + if ( val0 == val1 && + val0 == val2 && + val0 == 255 ) + { + _write[0] = (unsigned char)sr; + _write[1] = (unsigned char)sg; + _write[2] = (unsigned char)sb; + } + else + { + /* compose gray value */ + int dr, dg, db; + + dr = _write[0]; + dr += (sr-dr)*val0 >> 8; + + dg = _write[1]; + dg += (sg-dg)*val1 >> 8; + + db = _write[1]; + db += (sb-db)*val2 >> 8; + + _write[0] = dr; + _write[1] = dg; + _write[2] = db; + } + } + _write += 3; + _read += 3; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } +#endif /* GRAY8 */ + + static void + blit_lcd2_to_24( grBlitter* blit, + grColor color, + int max ) + { + int y; + unsigned char* read; + unsigned char* write; + + read = blit->read + 3*blit->xread; + write = blit->write + 3*blit->xwrite; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + int val0, val1, val2; + + val0 = _read[2]; + val1 = _read[1]; + val2 = _read[0]; + + if ( val0 | val1 | val2 ) + { + if ( val0 == val1 && + val0 == val2 && + val0 == max ) + { + _write[0] = color.chroma[0]; + _write[1] = color.chroma[1]; + _write[2] = color.chroma[2]; + } + else + { + /* compose gray value */ + grColor pix; + + pix.chroma[0] = _write[0]; + pix.chroma[1] = _write[1]; + pix.chroma[2] = _write[2]; + + compose_pixel_full( pix, color, val0, val1, val2, max ); + + _write[0] = pix.chroma[0]; + _write[1] = pix.chroma[1]; + _write[2] = pix.chroma[2]; + } + } + _write += 3; + _read += 3; + x--; + } + + read += blit->read_line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + +/**************************************************************************/ +/* */ +/* <Function> blit_lcdv_to_24 */ +/* */ +/**************************************************************************/ + + static void + blit_lcdv_to_24( grBlitter* blit, + grColor color, + int max ) + { + int y; + unsigned char* read; + unsigned char* write; + long line; + + read = blit->read + blit->xread; + write = blit->write + 3*blit->xwrite; + line = blit->read_line; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val0, val1, val2; + + val0 = _read[0*line]; + val1 = _read[1*line]; + val2 = _read[2*line]; + + if ( val0 | val1 | val2 ) + { + if ( val0 == val1 && + val0 == val2 && + val0 == max ) + { + _write[0] = color.chroma[0]; + _write[1] = color.chroma[1]; + _write[2] = color.chroma[2]; + } + else + { + /* compose gray value */ + grColor pix; + + pix.chroma[0] = _write[0]; + pix.chroma[1] = _write[1]; + pix.chroma[2] = _write[2]; + + compose_pixel_full( pix, color, val0, val1, val2, max ); + + _write[0] = pix.chroma[0]; + _write[1] = pix.chroma[1]; + _write[2] = pix.chroma[2]; + } + } + _write += 3; + _read += 1; + x--; + } + + read += 3*line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + + static void + blit_lcdv2_to_24( grBlitter* blit, + grColor color, + int max ) + { + int y; + unsigned char* read; + unsigned char* write; + long line; + + read = blit->read + blit->xread; + write = blit->write + 3*blit->xwrite; + line = blit->read_line; + + y = blit->height; + do + { + unsigned char* _read = read; + unsigned char* _write = write; + int x = blit->width; + + while (x > 0) + { + unsigned char val0, val1, val2; + + val0 = _read[2*line]; + val1 = _read[1*line]; + val2 = _read[0*line]; + + if ( val0 | val1 | val2 ) + { + if ( val0 == val1 && + val0 == val2 && + val0 == max ) + { + _write[0] = color.chroma[0]; + _write[1] = color.chroma[1]; + _write[2] = color.chroma[2]; + } + else + { + /* compose gray value */ + grColor pix; + + pix.chroma[0] = _write[0]; + pix.chroma[1] = _write[1]; + pix.chroma[2] = _write[2]; + + compose_pixel_full( pix, color, val0, val1, val2, max ); + + _write[0] = pix.chroma[0]; + _write[1] = pix.chroma[1]; + _write[2] = pix.chroma[2]; + } + } + _write += 3; + _read += 1; + x--; + } + + read += 3*line; + write += blit->write_line; + y--; + } + while (y > 0); + } + + + /********************************************************************** + * + * <Function> + * grBlitGlyphBitmap + * + * <Description> + * writes a given glyph bitmap to a target surface. + * + * <Input> + * surface :: handle to target surface + * x :: position of left-most pixel of glyph image in surface + * y :: position of top-most pixel of glyph image in surface + * bitmap :: source glyph image + * + * <Return> + * Error code. 0 means success + * + **********************************************************************/ + + typedef void (*grColorGlyphBlitter)( grBlitter* blit, + grColor color, + int max_gray ); + + static + const grColorGlyphBlitter gr_color_blitters[gr_pixel_mode_max] = + { + 0, + 0, + 0, + 0, + 0, + blit_gray_to_555, + blit_gray_to_565, + blit_gray_to_24, + blit_gray_to_32 + }; + +#ifdef GRAY8 + typedef void (*grGray8GlyphBlitter)( grBlitter* blit, + grColor color ); + + static + const grGray8GlyphBlitter gr_gray8_blitters[gr_pixel_mode_max] = + { + 0, + 0, + 0, + 0, + 0, + blit_gray8_to_555, + blit_gray8_to_565, + blit_gray8_to_24, + blit_gray8_to_32 + }; +#endif + + +#include "gblblit.h" + + static double gr_glyph_gamma = 1.0; + + void grSetGlyphGamma( double gamma ) + { + gr_glyph_gamma = gamma; + } + + + int + grBlitGlyphToBitmap( grBitmap* target, + grBitmap* glyph, + grPos x, + grPos y, + grColor color ) + { + grBlitter blit; + grPixelMode mode; + + + /* check arguments */ + if ( !target || !glyph ) + { + grError = gr_err_bad_argument; + return -1; + } + + /* short cut to alpha blender for certain glyph types + */ + { + GBlenderSourceFormat src_format; + GBlenderTargetFormat dst_format; + int width, height; + GBlenderBlitRec gblit[1]; + GBlenderPixel gcolor; + static GBlenderRec gblender[1]; + static double gblender_gamma = -100.0; + + if ( glyph->grays != 256 ) + goto DefaultBlit; + + switch ( glyph->mode ) + { + case gr_pixel_mode_gray: src_format = GBLENDER_SOURCE_GRAY8; break; + case gr_pixel_mode_lcd: src_format = GBLENDER_SOURCE_HRGB; break; + case gr_pixel_mode_lcdv: src_format = GBLENDER_SOURCE_VRGB; break; + case gr_pixel_mode_lcd2: src_format = GBLENDER_SOURCE_HBGR; break; + case gr_pixel_mode_lcdv2: src_format = GBLENDER_SOURCE_VBGR; break; + + default: + goto DefaultBlit; + } + + width = glyph->width; + height = glyph->rows; + + if ( glyph->mode == gr_pixel_mode_lcd || + glyph->mode == gr_pixel_mode_lcd2 ) + width /= 3; + + if ( glyph->mode == gr_pixel_mode_lcdv || + glyph->mode == gr_pixel_mode_lcdv2 ) + height /= 3; + + switch ( target->mode ) + { + case gr_pixel_mode_rgb32: dst_format = GBLENDER_TARGET_RGB32; break; + case gr_pixel_mode_rgb24: dst_format = GBLENDER_TARGET_RGB24; break; + case gr_pixel_mode_rgb565: dst_format = GBLENDER_TARGET_RGB565; break; + default: + goto DefaultBlit; + } + + /* initialize blender when needed, i.e. when gamma changes + */ + if ( gblender_gamma != gr_glyph_gamma ) + { + gblender_gamma = gr_glyph_gamma; + gblender_init( gblender, gblender_gamma ); + } + + if ( gblender_blit_init( gblit, gblender, + x, y, + src_format, + glyph->buffer, + glyph->pitch, + width, + height, + dst_format, + target->buffer, + target->pitch, + target->width, + target->rows ) < 0 ) + { + /* nothing to do */ + return 0; + } + + gcolor = ((GBlenderPixel)color.chroma[0] << 16) | + ((GBlenderPixel)color.chroma[1] << 8 ) | + ((GBlenderPixel)color.chroma[2] ) ; + + gblender_blit_run( gblit, gcolor ); + return 1; + } + + DefaultBlit: + + /* set up blitter and compute clipping. Return immediately if needed */ + blit.source = *glyph; + blit.target = *target; + mode = target->mode; + + if ( compute_clips( &blit, x, y ) ) + return 0; + + switch ( glyph->mode ) + { + case gr_pixel_mode_mono: /* handle monochrome bitmap blitting */ + if ( mode <= gr_pixel_mode_none || mode >= gr_pixel_mode_max ) + { + grError = gr_err_bad_source_depth; + return -1; + } + + gr_mono_blitters[mode]( &blit, color ); + break; + + case gr_pixel_mode_gray: + if ( glyph->grays > 1 ) + { + int target_grays = target->grays; + int source_grays = glyph->grays; + const byte* saturation; + + + if ( mode == gr_pixel_mode_gray && target_grays > 1 ) + { + /* rendering into a gray target - use special composition */ + /* routines.. */ + if ( gr_last_saturation->count == target_grays ) + saturation = gr_last_saturation->table; + else + { + saturation = grGetSaturation( target_grays ); + if ( !saturation ) + return -3; + } + + if ( target_grays == source_grays ) + blit_gray_to_gray_simple( &blit, saturation ); + else + { + const byte* conversion; + + + if ( gr_last_conversion->target_grays == target_grays && + gr_last_conversion->source_grays == source_grays ) + conversion = gr_last_conversion->table; + else + { + conversion = grGetConversion( target_grays, source_grays ); + if ( !conversion ) + return -3; + } + + blit_gray_to_gray( &blit, saturation, conversion ); + } + } + else + { + /* rendering into a color target */ + if ( mode <= gr_pixel_mode_gray || + mode >= gr_pixel_mode_max ) + { + grError = gr_err_bad_target_depth; + return -1; + } + +#ifdef GRAY8 + if ( source_grays == 256 ) + gr_gray8_blitters[mode]( &blit, color ); + else +#endif /* GRAY8 */ + gr_color_blitters[mode]( &blit, color, source_grays - 1 ); + } + } + break; + + case gr_pixel_mode_lcd: + if ( mode == gr_pixel_mode_rgb24 ) + { +#ifdef GRAY8 + if ( glyph->grays == 256 ) + blit_lcd8_to_24( &blit, color ); + else +#endif + if ( glyph->grays > 1 ) + blit_lcd_to_24( &blit, color, glyph->grays-1 ); + } + break; + + + case gr_pixel_mode_lcdv: + if ( glyph->grays > 1 && mode == gr_pixel_mode_rgb24 ) + { + blit_lcdv_to_24( &blit, color, glyph->grays-1 ); + break; + } + + case gr_pixel_mode_lcd2: + if ( mode == gr_pixel_mode_rgb24 ) + { +#ifdef GRAY8 + if ( glyph->grays == 256 ) + blit_lcd28_to_24( &blit, color ); + else +#endif + if ( glyph->grays > 1 ) + blit_lcd2_to_24( &blit, color, glyph->grays-1 ); + } + break; + + case gr_pixel_mode_lcdv2: + if ( mode == gr_pixel_mode_rgb24 ) + { + if ( glyph->grays > 1 ) + blit_lcdv2_to_24( &blit, color, glyph->grays-1 ); + } + break; + + default: + /* we don't support the blitting of bitmaps of the following */ + /* types : pal4, pal8, rgb555, rgb565, rgb24, rgb32 */ + /* */ + grError = gr_err_bad_source_depth; + return -2; + } + + return 0; + } + + +/* End */ diff --git a/kernel/kls_ttf/ftview/grblit.h b/kernel/kls_ttf/ftview/grblit.h new file mode 100644 index 0000000..4d0b6e5 --- /dev/null +++ b/kernel/kls_ttf/ftview/grblit.h @@ -0,0 +1,25 @@ +/****************************************************************************/ +/* */ +/* The FreeType project -- a free and portable quality TrueType renderer. */ +/* */ +/* Copyright 1996-1999 by */ +/* D. Turner, R.Wilhelm, and W. Lemberg */ +/* */ +/* blitter.h: Support for blitting of bitmaps with various depth. */ +/* */ +/****************************************************************************/ + +#ifndef GRBLIT_H +#define GRBLIT_H + +#include "grobjs.h" + + int grBlitMono( grBitmap* target, + grBitmap* source, + int x_offset, + int y_offset, + grColor color ); + + +#endif /* GRBLIT_H */ +/* End */ diff --git a/kernel/kls_ttf/ftview/grconfig.h b/kernel/kls_ttf/ftview/grconfig.h new file mode 100644 index 0000000..02d8f4d --- /dev/null +++ b/kernel/kls_ttf/ftview/grconfig.h @@ -0,0 +1,9 @@ +#ifndef GRCONFIG_H +#define GRCONFIG_H + +#define GR_MAX_SATURATIONS 8 +#define GR_MAX_CONVERSIONS 16 + +#define GR_MAX_DEVICES 8 + +#endif /* GRCONFIG_H */ diff --git a/kernel/kls_ttf/ftview/grevents.h b/kernel/kls_ttf/ftview/grevents.h new file mode 100644 index 0000000..36dd52d --- /dev/null +++ b/kernel/kls_ttf/ftview/grevents.h @@ -0,0 +1,117 @@ +#ifndef GREVENTS_H +#define GREVENTS_H + + +#define gr_event_none 0 +#define gr_event_wait 1 +#define gr_event_poll 2 +#define gr_event_flush 3 + +#define gr_mouse_down 0x04 +#define gr_mouse_move 0x08 +#define gr_mouse_up 0x10 +#define gr_mouse_drag 0x20 + +#define gr_key_down 0x40 +#define gr_key_up 0x80 + + +#define gr_event_mouse 0x3C +#define gr_event_key 0xC0 + +#define gr_event_type (gr_event_mouse | gr_event_key) + + + typedef enum grKey_ + { + grKeyNone = 0, + + grKeyF1, + grKeyF2, + grKeyF3, + grKeyF4, + grKeyF5, + grKeyF6, + grKeyF7, + grKeyF8, + grKeyF9, + grKeyF10, + grKeyF11, + grKeyF12, + + grKeyLeft, + grKeyRight, + grKeyUp, + grKeyDown, + + grKeyIns, + grKeyDel, + grKeyHome, + grKeyEnd, + grKeyPageUp, + grKeyPageDown, + + grKeyEsc, + grKeyTab, + grKeyBackSpace, + grKeyReturn, + + grKeyMax, + grKeyForceShort = 0x7FFF /* this forces the grKey to be stored */ + /* on at least one short ! */ + + } grKey; + +#define grKEY(c) ((grKey)(c)) + +#define grKeyAlt ((grKey)0x8000) +#define grKeyCtrl ((grKey)0x4000) +#define grKeyShift ((grKey)0x2000) + +#define grKeyModifiers ((grKey)0xE000) + +#define grKey0 grKEY('0') +#define grKey1 grKEY('1') +#define grKey2 grKEY('2') +#define grKey3 grKEY('3') +#define grKey4 grKEY('4') +#define grKey5 grKEY('5') +#define grKey6 grKEY('6') +#define grKey7 grKEY('7') +#define grKey8 grKEY('8') +#define grKey9 grKEY('9') + + +#define grKeyPlus grKEY('+') +#define grKeyLess grKEY('-') +#define grKeyEqual grKEY('=') +#define grKeyMult grKEY('*') +#define grKeyDollar grKEY('$') +#define grKeySmaller grKEY('<') +#define grKeyGreater grKEY('>') +#define grKeyQuestion grKEY('?') +#define grKeyComma grKEY(',') +#define grKeyDot grKEY('.') +#define grKeySemiColumn grKEY(';') +#define grKeyColumn grKEY(':') +#define grKeyDiv grKEY('/') +#define grKeyExclam grKEY('!') +#define grKeyPercent grKEY('%') +#define grKeyLeftParen grKEY('(') +#define grKeyRightParen grKEY('(') +#define grKeyAt grKEY('@') +#define grKeyUnder grKEY('_') + + + typedef struct grEvent_ + { + int type; + grKey key; + int x, y; + + } grEvent; + + + +#endif /* GREVENTS_H */ + diff --git a/kernel/kls_ttf/ftview/grfont.cpp b/kernel/kls_ttf/ftview/grfont.cpp new file mode 100644 index 0000000..b6dfa3b --- /dev/null +++ b/kernel/kls_ttf/ftview/grfont.cpp @@ -0,0 +1,373 @@ + +#include "grfont.h" +#include <string.h> + + /* font characters */ + + const unsigned char font_8x8[2048] = + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E, + 0x7E, 0xFF, 0xDB, 0xFF, 0xC3, 0xE7, 0xFF, 0x7E, + 0x6C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38, 0x10, 0x00, + 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x10, 0x00, + 0x38, 0x7C, 0x38, 0xFE, 0xFE, 0x92, 0x10, 0x7C, + 0x00, 0x10, 0x38, 0x7C, 0xFE, 0x7C, 0x38, 0x7C, + 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x18, 0x00, 0x00, + 0xFF, 0xFF, 0xE7, 0xC3, 0xC3, 0xE7, 0xFF, 0xFF, + 0x00, 0x3C, 0x66, 0x42, 0x42, 0x66, 0x3C, 0x00, + 0xFF, 0xC3, 0x99, 0xBD, 0xBD, 0x99, 0xC3, 0xFF, + 0x0F, 0x07, 0x0F, 0x7D, 0xCC, 0xCC, 0xCC, 0x78, + 0x3C, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x7E, 0x18, + 0x3F, 0x33, 0x3F, 0x30, 0x30, 0x70, 0xF0, 0xE0, + 0x7F, 0x63, 0x7F, 0x63, 0x63, 0x67, 0xE6, 0xC0, + 0x99, 0x5A, 0x3C, 0xE7, 0xE7, 0x3C, 0x5A, 0x99, + 0x80, 0xE0, 0xF8, 0xFE, 0xF8, 0xE0, 0x80, 0x00, + 0x02, 0x0E, 0x3E, 0xFE, 0x3E, 0x0E, 0x02, 0x00, + 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x7E, 0x3C, 0x18, + 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x00, + 0x7F, 0xDB, 0xDB, 0x7B, 0x1B, 0x1B, 0x1B, 0x00, + 0x3E, 0x63, 0x38, 0x6C, 0x6C, 0x38, 0x86, 0xFC, + 0x00, 0x00, 0x00, 0x00, 0x7E, 0x7E, 0x7E, 0x00, + 0x18, 0x3C, 0x7E, 0x18, 0x7E, 0x3C, 0x18, 0xFF, + 0x18, 0x3C, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x00, + 0x18, 0x18, 0x18, 0x18, 0x7E, 0x3C, 0x18, 0x00, + 0x00, 0x18, 0x0C, 0xFE, 0x0C, 0x18, 0x00, 0x00, + 0x00, 0x30, 0x60, 0xFE, 0x60, 0x30, 0x00, 0x00, + 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xFE, 0x00, 0x00, + 0x00, 0x24, 0x66, 0xFF, 0x66, 0x24, 0x00, 0x00, + 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00, + 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0x00, + 0x18, 0x7E, 0xC0, 0x7C, 0x06, 0xFC, 0x18, 0x00, + 0x00, 0xC6, 0xCC, 0x18, 0x30, 0x66, 0xC6, 0x00, + 0x38, 0x6C, 0x38, 0x76, 0xDC, 0xCC, 0x76, 0x00, + 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x30, 0x60, 0x60, 0x60, 0x30, 0x18, 0x00, + 0x60, 0x30, 0x18, 0x18, 0x18, 0x30, 0x60, 0x00, + 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00, + 0x00, 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, + 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, + 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x00, + 0x7C, 0xCE, 0xDE, 0xF6, 0xE6, 0xC6, 0x7C, 0x00, + 0x30, 0x70, 0x30, 0x30, 0x30, 0x30, 0xFC, 0x00, + 0x78, 0xCC, 0x0C, 0x38, 0x60, 0xCC, 0xFC, 0x00, + 0x78, 0xCC, 0x0C, 0x38, 0x0C, 0xCC, 0x78, 0x00, + 0x1C, 0x3C, 0x6C, 0xCC, 0xFE, 0x0C, 0x1E, 0x00, + 0xFC, 0xC0, 0xF8, 0x0C, 0x0C, 0xCC, 0x78, 0x00, + 0x38, 0x60, 0xC0, 0xF8, 0xCC, 0xCC, 0x78, 0x00, + 0xFC, 0xCC, 0x0C, 0x18, 0x30, 0x30, 0x30, 0x00, + 0x78, 0xCC, 0xCC, 0x78, 0xCC, 0xCC, 0x78, 0x00, + 0x78, 0xCC, 0xCC, 0x7C, 0x0C, 0x18, 0x70, 0x00, + 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x00, + 0x00, 0x18, 0x18, 0x00, 0x00, 0x18, 0x18, 0x30, + 0x18, 0x30, 0x60, 0xC0, 0x60, 0x30, 0x18, 0x00, + 0x00, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, 0x00, + 0x60, 0x30, 0x18, 0x0C, 0x18, 0x30, 0x60, 0x00, + 0x3C, 0x66, 0x0C, 0x18, 0x18, 0x00, 0x18, 0x00, + 0x7C, 0xC6, 0xDE, 0xDE, 0xDC, 0xC0, 0x7C, 0x00, + 0x30, 0x78, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0x00, + 0xFC, 0x66, 0x66, 0x7C, 0x66, 0x66, 0xFC, 0x00, + 0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00, + 0xF8, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0xF8, 0x00, + 0xFE, 0x62, 0x68, 0x78, 0x68, 0x62, 0xFE, 0x00, + 0xFE, 0x62, 0x68, 0x78, 0x68, 0x60, 0xF0, 0x00, + 0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3A, 0x00, + 0xCC, 0xCC, 0xCC, 0xFC, 0xCC, 0xCC, 0xCC, 0x00, + 0x78, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, + 0x1E, 0x0C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, 0x00, + 0xE6, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0xE6, 0x00, + 0xF0, 0x60, 0x60, 0x60, 0x62, 0x66, 0xFE, 0x00, + 0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, + 0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, + 0x38, 0x6C, 0xC6, 0xC6, 0xC6, 0x6C, 0x38, 0x00, + 0xFC, 0x66, 0x66, 0x7C, 0x60, 0x60, 0xF0, 0x00, + 0x7C, 0xC6, 0xC6, 0xC6, 0xD6, 0x7C, 0x0E, 0x00, + 0xFC, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0xE6, 0x00, + 0x7C, 0xC6, 0xE0, 0x78, 0x0E, 0xC6, 0x7C, 0x00, + 0xFC, 0xB4, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, + 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xFC, 0x00, + 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, + 0xC6, 0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, + 0xC6, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0xC6, 0x00, + 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x30, 0x78, 0x00, + 0xFE, 0xC6, 0x8C, 0x18, 0x32, 0x66, 0xFE, 0x00, + 0x78, 0x60, 0x60, 0x60, 0x60, 0x60, 0x78, 0x00, + 0xC0, 0x60, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, + 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x78, 0x00, + 0x10, 0x38, 0x6C, 0xC6, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, + 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, + 0xE0, 0x60, 0x60, 0x7C, 0x66, 0x66, 0xDC, 0x00, + 0x00, 0x00, 0x78, 0xCC, 0xC0, 0xCC, 0x78, 0x00, + 0x1C, 0x0C, 0x0C, 0x7C, 0xCC, 0xCC, 0x76, 0x00, + 0x00, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, + 0x38, 0x6C, 0x64, 0xF0, 0x60, 0x60, 0xF0, 0x00, + 0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, + 0xE0, 0x60, 0x6C, 0x76, 0x66, 0x66, 0xE6, 0x00, + 0x30, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, + 0x0C, 0x00, 0x1C, 0x0C, 0x0C, 0xCC, 0xCC, 0x78, + 0xE0, 0x60, 0x66, 0x6C, 0x78, 0x6C, 0xE6, 0x00, + 0x70, 0x30, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, + 0x00, 0x00, 0xCC, 0xFE, 0xFE, 0xD6, 0xD6, 0x00, + 0x00, 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, + 0x00, 0x00, 0x78, 0xCC, 0xCC, 0xCC, 0x78, 0x00, + 0x00, 0x00, 0xDC, 0x66, 0x66, 0x7C, 0x60, 0xF0, + 0x00, 0x00, 0x76, 0xCC, 0xCC, 0x7C, 0x0C, 0x1E, + 0x00, 0x00, 0xDC, 0x76, 0x62, 0x60, 0xF0, 0x00, + 0x00, 0x00, 0x7C, 0xC0, 0x70, 0x1C, 0xF8, 0x00, + 0x10, 0x30, 0xFC, 0x30, 0x30, 0x34, 0x18, 0x00, + 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x76, 0x00, + 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x78, 0x30, 0x00, + 0x00, 0x00, 0xC6, 0xC6, 0xD6, 0xFE, 0x6C, 0x00, + 0x00, 0x00, 0xC6, 0x6C, 0x38, 0x6C, 0xC6, 0x00, + 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, + 0x00, 0x00, 0xFC, 0x98, 0x30, 0x64, 0xFC, 0x00, + 0x1C, 0x30, 0x30, 0xE0, 0x30, 0x30, 0x1C, 0x00, + 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00, + 0xE0, 0x30, 0x30, 0x1C, 0x30, 0x30, 0xE0, 0x00, + 0x76, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x38, 0x6C, 0xC6, 0xC6, 0xFE, 0x00, + 0x7C, 0xC6, 0xC0, 0xC6, 0x7C, 0x0C, 0x06, 0x7C, + 0x00, 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, + 0x1C, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, + 0x7E, 0x81, 0x3C, 0x06, 0x3E, 0x66, 0x3B, 0x00, + 0xCC, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, + 0xE0, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, + 0x30, 0x30, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, + 0x00, 0x00, 0x7C, 0xC6, 0xC0, 0x78, 0x0C, 0x38, + 0x7E, 0x81, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0x00, + 0xCC, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, + 0xE0, 0x00, 0x78, 0xCC, 0xFC, 0xC0, 0x78, 0x00, + 0xCC, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, + 0x7C, 0x82, 0x38, 0x18, 0x18, 0x18, 0x3C, 0x00, + 0xE0, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, + 0xC6, 0x10, 0x7C, 0xC6, 0xFE, 0xC6, 0xC6, 0x00, + 0x30, 0x30, 0x00, 0x78, 0xCC, 0xFC, 0xCC, 0x00, + 0x1C, 0x00, 0xFC, 0x60, 0x78, 0x60, 0xFC, 0x00, + 0x00, 0x00, 0x7F, 0x0C, 0x7F, 0xCC, 0x7F, 0x00, + 0x3E, 0x6C, 0xCC, 0xFE, 0xCC, 0xCC, 0xCE, 0x00, + 0x78, 0x84, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, + 0x00, 0xCC, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, + 0x00, 0xE0, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, + 0x78, 0x84, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, + 0x00, 0xE0, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, + 0x00, 0xCC, 0x00, 0xCC, 0xCC, 0x7C, 0x0C, 0xF8, + 0xC3, 0x18, 0x3C, 0x66, 0x66, 0x3C, 0x18, 0x00, + 0xCC, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x78, 0x00, + 0x18, 0x18, 0x7E, 0xC0, 0xC0, 0x7E, 0x18, 0x18, + 0x38, 0x6C, 0x64, 0xF0, 0x60, 0xE6, 0xFC, 0x00, + 0xCC, 0xCC, 0x78, 0x30, 0xFC, 0x30, 0xFC, 0x30, + 0xF8, 0xCC, 0xCC, 0xFA, 0xC6, 0xCF, 0xC6, 0xC3, + 0x0E, 0x1B, 0x18, 0x3C, 0x18, 0x18, 0xD8, 0x70, + 0x1C, 0x00, 0x78, 0x0C, 0x7C, 0xCC, 0x76, 0x00, + 0x38, 0x00, 0x70, 0x30, 0x30, 0x30, 0x78, 0x00, + 0x00, 0x1C, 0x00, 0x78, 0xCC, 0xCC, 0x78, 0x00, + 0x00, 0x1C, 0x00, 0xCC, 0xCC, 0xCC, 0x76, 0x00, + 0x00, 0xF8, 0x00, 0xB8, 0xCC, 0xCC, 0xCC, 0x00, + 0xFC, 0x00, 0xCC, 0xEC, 0xFC, 0xDC, 0xCC, 0x00, + 0x3C, 0x6C, 0x6C, 0x3E, 0x00, 0x7E, 0x00, 0x00, + 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x7C, 0x00, 0x00, + 0x18, 0x00, 0x18, 0x18, 0x30, 0x66, 0x3C, 0x00, + 0x00, 0x00, 0x00, 0xFC, 0xC0, 0xC0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xFC, 0x0C, 0x0C, 0x00, 0x00, + 0xC6, 0xCC, 0xD8, 0x36, 0x6B, 0xC2, 0x84, 0x0F, + 0xC3, 0xC6, 0xCC, 0xDB, 0x37, 0x6D, 0xCF, 0x03, + 0x18, 0x00, 0x18, 0x18, 0x3C, 0x3C, 0x18, 0x00, + 0x00, 0x33, 0x66, 0xCC, 0x66, 0x33, 0x00, 0x00, + 0x00, 0xCC, 0x66, 0x33, 0x66, 0xCC, 0x00, 0x00, + 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, + 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, + 0xDB, 0xF6, 0xDB, 0x6F, 0xDB, 0x7E, 0xD7, 0xED, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0xF8, 0x18, 0x18, 0x18, + 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, + 0x36, 0x36, 0x36, 0x36, 0xF6, 0x36, 0x36, 0x36, + 0x00, 0x00, 0x00, 0x00, 0xFE, 0x36, 0x36, 0x36, + 0x00, 0x00, 0xF8, 0x18, 0xF8, 0x18, 0x18, 0x18, + 0x36, 0x36, 0xF6, 0x06, 0xF6, 0x36, 0x36, 0x36, + 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, + 0x00, 0x00, 0xFE, 0x06, 0xF6, 0x36, 0x36, 0x36, + 0x36, 0x36, 0xF6, 0x06, 0xFE, 0x00, 0x00, 0x00, + 0x36, 0x36, 0x36, 0x36, 0xFE, 0x00, 0x00, 0x00, + 0x18, 0x18, 0xF8, 0x18, 0xF8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xF8, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x1F, 0x00, 0x00, 0x00, + 0x18, 0x18, 0x18, 0x18, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x1F, 0x18, 0x18, 0x18, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, + 0x18, 0x18, 0x18, 0x18, 0xFF, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, + 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, + 0x36, 0x36, 0x37, 0x30, 0x3F, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3F, 0x30, 0x37, 0x36, 0x36, 0x36, + 0x36, 0x36, 0xF7, 0x00, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xF7, 0x36, 0x36, 0x36, + 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, + 0x36, 0x36, 0xF7, 0x00, 0xF7, 0x36, 0x36, 0x36, + 0x18, 0x18, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, + 0x36, 0x36, 0x36, 0x36, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x18, 0x18, 0x18, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0x36, 0x36, 0x36, + 0x36, 0x36, 0x36, 0x36, 0x3F, 0x00, 0x00, 0x00, + 0x18, 0x18, 0x1F, 0x18, 0x1F, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x1F, 0x18, 0x1F, 0x18, 0x18, 0x18, + 0x00, 0x00, 0x00, 0x00, 0x3F, 0x36, 0x36, 0x36, + 0x36, 0x36, 0x36, 0x36, 0xFF, 0x36, 0x36, 0x36, + 0x18, 0x18, 0xFF, 0x18, 0xFF, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0xF8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1F, 0x18, 0x18, 0x18, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, + 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, + 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x76, 0xDC, 0xC8, 0xDC, 0x76, 0x00, + 0x00, 0x78, 0xCC, 0xF8, 0xCC, 0xF8, 0xC0, 0xC0, + 0x00, 0xFC, 0xCC, 0xC0, 0xC0, 0xC0, 0xC0, 0x00, + 0x00, 0x00, 0xFE, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, + 0xFC, 0xCC, 0x60, 0x30, 0x60, 0xCC, 0xFC, 0x00, + 0x00, 0x00, 0x7E, 0xD8, 0xD8, 0xD8, 0x70, 0x00, + 0x00, 0x66, 0x66, 0x66, 0x66, 0x7C, 0x60, 0xC0, + 0x00, 0x76, 0xDC, 0x18, 0x18, 0x18, 0x18, 0x00, + 0xFC, 0x30, 0x78, 0xCC, 0xCC, 0x78, 0x30, 0xFC, + 0x38, 0x6C, 0xC6, 0xFE, 0xC6, 0x6C, 0x38, 0x00, + 0x38, 0x6C, 0xC6, 0xC6, 0x6C, 0x6C, 0xEE, 0x00, + 0x1C, 0x30, 0x18, 0x7C, 0xCC, 0xCC, 0x78, 0x00, + 0x00, 0x00, 0x7E, 0xDB, 0xDB, 0x7E, 0x00, 0x00, + 0x06, 0x0C, 0x7E, 0xDB, 0xDB, 0x7E, 0x60, 0xC0, + 0x38, 0x60, 0xC0, 0xF8, 0xC0, 0x60, 0x38, 0x00, + 0x78, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, + 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x7E, 0x00, 0x00, + 0x18, 0x18, 0x7E, 0x18, 0x18, 0x00, 0x7E, 0x00, + 0x60, 0x30, 0x18, 0x30, 0x60, 0x00, 0xFC, 0x00, + 0x18, 0x30, 0x60, 0x30, 0x18, 0x00, 0xFC, 0x00, + 0x0E, 0x1B, 0x1B, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0xD8, 0xD8, 0x70, + 0x18, 0x18, 0x00, 0x7E, 0x00, 0x18, 0x18, 0x00, + 0x00, 0x76, 0xDC, 0x00, 0x76, 0xDC, 0x00, 0x00, + 0x38, 0x6C, 0x6C, 0x38, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x0F, 0x0C, 0x0C, 0x0C, 0xEC, 0x6C, 0x3C, 0x1C, + 0x58, 0x6C, 0x6C, 0x6C, 0x6C, 0x00, 0x00, 0x00, + 0x70, 0x98, 0x30, 0x60, 0xF8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + + static + grBitmap gr_charcell = + { + 8, /* rows */ + 8, /* width */ + 1, /* pitch */ + gr_pixel_mode_mono, /* mode */ + 0, /* grays */ + 0 /* buffer */ + }; + + void grWriteCellChar( grBitmap* target, + int x, + int y, + int charcode, + grColor color ) + { + if (charcode < 0 || charcode > 255) + return; + + gr_charcell.buffer = (unsigned char*)font_8x8 + 8 * charcode; + grBlitGlyphToBitmap( target, &gr_charcell, x, y, color ); + } + + + void grWriteCellString( grBitmap* target, + int x, + int y, + const char* string, + grColor color ) + { + while (*string) + { + gr_charcell.buffer = (unsigned char *)font_8x8 + + 8 * (int)(unsigned char)*string++; + grBlitGlyphToBitmap( target, &gr_charcell, x, y, color ); + x += 8; + } + } + + static int gr_cursor_x = 0; + static int gr_cursor_y = 0; + static grBitmap* gr_text_bitmap = 0; + static int gr_margin_right = 0; + static int gr_margin_top = 0; + + + extern void grGotobitmap( grBitmap* bitmap ) + { + gr_text_bitmap = bitmap; + } + + + extern void grSetMargin( int right, int top ) + { + gr_margin_top = top << 3; + gr_margin_right = right << 3; + } + + + extern void grSetPixelMargin( int right, int top ) + { + gr_margin_top = top; + gr_margin_right = right; + } + + + extern void grGotoxy ( int x, int y ) + { + gr_cursor_x = x; + gr_cursor_y = y; + } + + + extern void grWrite ( const char* string ) + { + if (string) + { + grColor color; + + color.value = 127; + grWriteCellString( gr_text_bitmap, + gr_margin_right + (gr_cursor_x << 3), + gr_margin_top + (gr_cursor_y << 3), + string, + color ); + + gr_cursor_x += strlen(string); + } + } + + + extern void grLn( void ) + { + gr_cursor_y ++; + gr_cursor_x = 0; + } + + + extern void grWriteln( const char* string ) + { + grWrite( string ); + grLn(); + } + + diff --git a/kernel/kls_ttf/ftview/grfont.h b/kernel/kls_ttf/ftview/grfont.h new file mode 100644 index 0000000..47f226a --- /dev/null +++ b/kernel/kls_ttf/ftview/grfont.h @@ -0,0 +1,17 @@ +#ifndef GRFONT_H +#define GRFONT_H + +#include "graph.h" + + extern const unsigned char font_8x8[]; + + extern void grGotobitmap( grBitmap* bitmap ); + extern void grSetMargin( int right, int top ); + extern void grSetPixelMargin( int right, int top ); + extern void grGotoxy ( int x, int y ); + + extern void grWrite ( const char* string ); + extern void grWriteln( const char* string ); + extern void grLn( void ); + +#endif /* GRFONT_H */ diff --git a/kernel/kls_ttf/ftview/grobjs.cpp b/kernel/kls_ttf/ftview/grobjs.cpp new file mode 100644 index 0000000..283c315 --- /dev/null +++ b/kernel/kls_ttf/ftview/grobjs.cpp @@ -0,0 +1,213 @@ +#include "grobjs.h" +#include <stdlib.h> +#include <string.h> + + int grError = 0; + + + /******************************************************************** + * + * <Function> + * grRealloc + * + * <Description> + * Simple memory re-allocation. + * + * <Input> + * block :: original memory block address + * size :: new requested block size in bytes + * + * <Return> + * the memory block address. 0 in case of error + * + ********************************************************************/ + + unsigned char* grAlloc( long size ) + { + unsigned char* p; + + p = (unsigned char*)malloc(size); + if (!p && size > 0) + { + grError = gr_err_memory; + } + + if (p) + memset( p, 0, size ); + + return p; + } + + + /******************************************************************** + * + * <Function> + * grRealloc + * + * <Description> + * Simple memory re-allocation. + * + * <Input> + * block :: original memory block address + * size :: new requested block size in bytes + * + * <Return> + * the memory block address. 0 in case of error + * + ********************************************************************/ + + unsigned char* grRealloc( const unsigned char* block, long size ) + { + unsigned char* p; + + p = (unsigned char *)realloc( (void*)block, size ); + if (!p && size > 0) + { + grError = gr_err_memory; + } + return p; + } + + + /******************************************************************** + * + * <Function> + * grFree + * + * <Description> + * Simple memory release + * + * <Input> + * block :: target block + * + ********************************************************************/ + + void grFree( const void* block ) + { + if (block) + free( (void *)block ); + } + + + + static + int check_mode( grPixelMode pixel_mode, + int num_grays ) + { + if ( pixel_mode <= gr_pixel_mode_none || + pixel_mode >= gr_pixel_mode_max ) + goto Fail; + + if ( pixel_mode != gr_pixel_mode_gray || + ( num_grays >= 2 && num_grays <= 256 ) ) + return 0; + + Fail: + grError = gr_err_bad_argument; + return grError; + } + + + /********************************************************************** + * + * <Function> + * grNewBitmap + * + * <Description> + * creates a new bitmap + * + * <Input> + * pixel_mode :: the target surface's pixel_mode + * num_grays :: number of grays levels for PAL8 pixel mode + * width :: width in pixels + * height :: height in pixels + * + * <Output> + * bit :: descriptor of the new bitmap + * + * <Return> + * Error code. 0 means success. + * + **********************************************************************/ + + extern int grNewBitmap( grPixelMode pixel_mode, + int num_grays, + int width, + int height, + grBitmap *bit ) + { + int pitch; + + /* check mode */ + if (check_mode(pixel_mode,num_grays)) + goto Fail; + + /* check dimensions */ + if (width < 0 || height < 0) + { + grError = gr_err_bad_argument; + goto Fail; + } + + bit->width = width; + bit->rows = height; + bit->mode = pixel_mode; + bit->grays = num_grays; + + pitch = width; + + switch (pixel_mode) + { + case gr_pixel_mode_mono : pitch = (width+7) >> 3; break; + case gr_pixel_mode_pal4 : pitch = (width+3) >> 2; break; + + case gr_pixel_mode_pal8 : + case gr_pixel_mode_gray : pitch = width; break; + + case gr_pixel_mode_rgb555: + case gr_pixel_mode_rgb565: pitch = width*2; break; + + case gr_pixel_mode_rgb24 : pitch = width*3; break; + + case gr_pixel_mode_rgb32 : pitch = width*4; break; + + default: + grError = gr_err_bad_target_depth; + return 0; + } + + bit->pitch = pitch; + bit->buffer = grAlloc( (long)bit->pitch * bit->rows ); + if (!bit->buffer) goto Fail; + + return 0; + + Fail: + return grError; + } + + /********************************************************************** + * + * <Function> + * grDoneBitmap + * + * <Description> + * destroys a bitmap + * + * <Input> + * bitmap :: handle to bitmap descriptor + * + * <Note> + * This function does NOT release the bitmap descriptor, only + * the pixel buffer. + * + **********************************************************************/ + + extern void grDoneBitmap( grBitmap* bit ) + { + grFree( bit->buffer ); + bit->buffer = 0; + } + + + diff --git a/kernel/kls_ttf/ftview/grobjs.h b/kernel/kls_ttf/ftview/grobjs.h new file mode 100644 index 0000000..038ec54 --- /dev/null +++ b/kernel/kls_ttf/ftview/grobjs.h @@ -0,0 +1,182 @@ +/*************************************************************************** + * + * grobjs.h + * + * basic object classes defintions + * + * Copyright 1999 - The FreeType Development Team - www.freetype.org + * + * + * + * + ***************************************************************************/ + +#ifndef GROBJS_H +#define GROBJS_H + +#include "graph.h" +#include "grconfig.h" +#include "grtypes.h" + + + typedef struct grBiColor_ + { + grColor foreground; + grColor background; + + int num_levels; + int max_levels; + grColor* levels; + + } grBiColor; + + + + /********************************************************************** + * + * Technical note : explaining how the blitter works. + * + * The blitter is used to "draw" a given source bitmap into + * a given target bitmap. + * + * The function called 'compute_clips' is used to compute clipping + * constraints. These lead us to compute two areas : + * + * - the read area : is the rectangle, within the source bitmap, + * which will be effectively "drawn" in the + * target bitmap. + * + * - the write area : is the rectangle, within the target bitmap, + * which will effectively "receive" the pixels + * from the read area + * + * Note that both areas have the same dimensions, but are + * located in distinct surfaces. + * + * These areas are computed by 'compute_clips' which is called + * by each blitting function. + * + * Note that we use the Y-downwards convention within the blitter + * + **********************************************************************/ + + typedef struct grBlitter_ + { + int width; /* width in pixels of the areas */ + int height; /* height in pixels of the areas */ + + int xread; /* x position of start point in read area */ + int yread; /* y position of start point in read area */ + + int xwrite; /* x position of start point in write area */ + int ywrite; /* y position of start point in write area */ + + int right_clip; /* amount of right clip */ + + unsigned char* read; /* top left corner of read area in source map */ + unsigned char* write; /* top left corner of write area in target map */ + + int read_line; /* byte increment to go down one row in read area */ + int write_line; /* byte increment to go down one row in write area */ + + grBitmap source; /* source bitmap descriptor */ + grBitmap target; /* target bitmap descriptor */ + + } grBlitter; + + + + typedef void (*grBlitterFunc)( grBlitter* blitter, + grColor color ); + + typedef void (*grSetTitleFunc)( grSurface* surface, + const char* title_string ); + + typedef void (*grRefreshRectFunc)( grSurface* surface, + int x, + int y, + int width, + int height ); + + typedef void (*grDoneSurfaceFunc)( grSurface* surface ); + + typedef int (*grListenEventFunc)( grSurface* surface, + int event_mode, + grEvent *event ); + + + + struct grSurface_ + { + grDevice* device; + grBitmap bitmap; + grBool refresh; + grBool owner; + + const byte* saturation; /* used for gray surfaces only */ + grBlitterFunc blit_mono; /* 0 by default, set by grBlit.. */ + + grRefreshRectFunc refresh_rect; + grSetTitleFunc set_title; + grListenEventFunc listen_event; + grDoneSurfaceFunc done; + }; + + + + /******************************************************************** + * + * <Function> + * grAlloc + * + * <Description> + * Simple memory allocation. The returned block is always zero-ed + * + * <Input> + * size :: size in bytes of the requested block + * + * <Return> + * the memory block address. 0 in case of error + * + ********************************************************************/ + + extern unsigned char* grAlloc( long size ); + + + /******************************************************************** + * + * <Function> + * grRealloc + * + * <Description> + * Simple memory re-allocation. + * + * <Input> + * block :: original memory block address + * size :: new requested block size in bytes + * + * <Return> + * the memory block address. 0 in case of error + * + ********************************************************************/ + + extern unsigned char* grRealloc( const unsigned char* block, long size ); + + + /******************************************************************** + * + * <Function> + * grFree + * + * <Description> + * Simple memory release + * + * <Input> + * block :: target block + * + ********************************************************************/ + + extern void grFree( const void* block ); + + +#endif /* GROBJS_H */ diff --git a/kernel/kls_ttf/ftview/grtypes.h b/kernel/kls_ttf/ftview/grtypes.h new file mode 100644 index 0000000..7c39e2a --- /dev/null +++ b/kernel/kls_ttf/ftview/grtypes.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * + * grtypes.h + * + * basic type defintions + * + * Copyright 1999 - The FreeType Development Team - www.freetype.org + * + * + * + * + ***************************************************************************/ + +#ifndef GRTYPES_H +#define GRTYPES_H + + typedef unsigned char byte; + +#if 0 + typedef signed char uchar; + + typedef unsigned long ulong; + typedef unsigned short ushort; + typedef unsigned int uint; +#endif + + typedef struct grDimension_ + { + int x; + int y; + + } grDimension; + +#define gr_err_ok 0 +#define gr_err_memory -1 +#define gr_err_bad_argument -2 +#define gr_err_bad_target_depth -3 +#define gr_err_bad_source_depth -4 +#define gr_err_saturation_overflow -5 +#define gr_err_conversion_overflow -6 +#define gr_err_invalid_device -7 + + +#ifdef GR_MAKE_OPTION_SINGLE_OBJECT +#define GR_LOCAL_DECL static +#define GR_LOCAL_FUNC static +#else +#define GR_LOCAL_DECL extern +#define GR_LOCAL_FUNC /* void */ +#endif + +#endif /* GRTYPES_H */ |