Alex,
On Mon, Feb 06, 2006 at 08:38:18AM +0930, Alex Angas wrote:
> Can someone please help me out with the correct way to the
> determine the alpha mask for the mouse pointer?
If you have a look at the pointer's index data, all colours except for
GFX_COLOR_INDEX_TRANSPARENT are opaque. So you can calculate the alpha mask
by going through the index data.
Since this is evidently a bugfixing task and thus meets the qualifications
of the code freeze, I've taken the liberty of moving the xlib implementation
of this process (now documented in gfx_driver.h as
gfx_create_mono_cursor_mask()) into a more accessible place, i.e. you should
be able to use the prototype directly now.
This can give you the opacity/alpha mask directly as a bitmask (scaled, if
neccessary), which is most likely what you want. Let me know if it is not.
-- Christoph
Index: src/include/gfx_driver.h
===================================================================
--- src/include/gfx_driver.h (revision 1509)
+++ src/include/gfx_driver.h (working copy)
@@ -414,7 +414,7 @@
** with 0 <= nr' < nr so that gfx_get_driver_name(nr') == NULL.
*/
-/*** Utility functions for set_parameter implementations */
+/*** Utility functions for set_parameter implementations ***/
int
string_truep(char *value);
@@ -433,5 +433,22 @@
*/
+/*** Utility functions for driver implementations ***/
+/* Cf. also gfx_support.c for line drawing facilities */
+byte *
+gfx_create_mono_cursor_mask(gfx_pixmap_t *pointer, int xfact, int yfact, int
mode);
+/* Computes the bitmap(s) underlying a mouse pointer
+** Parameters: (gfx_pixmap_t *) pointer: Pixmap of the pointer whose index
data will
+** serve as source for the bitmaps
+** (int x int) xfact, yfact: horizontal and vertical scaling
factors
+** (int) mode: If 0, compute the opaqueness map (1 means opaque, 0
means transparent)
+** Otherwise, compute the "is-zero" map, useful for
monochrome pointers which
+** only use transparency, 0, and 1.
+** Returns : A freshly allocated bitmap matching the above specification. If
+** (pointer->xl * xfact) mod 8 > 0, then empty (zero) bits will
be added for
+** padding at the end of each bitmap line.
+*/
+
+
#endif /* !_SCI_GFX_DRIVER_H_ */
Index: src/gfx/gfx_support.c
===================================================================
--- src/gfx/gfx_support.c (revision 1509)
+++ src/gfx/gfx_support.c (working copy)
@@ -394,3 +394,47 @@
+
+byte *
+gfx_create_mono_cursor_mask(gfx_pixmap_t *pointer, int xfact, int yfact, int
mode)
+{
+ int linewidth = (pointer->xl + 7) >> 3;
+ int lines = pointer->yl;
+ int xc, yc;
+ byte *data = sci_calloc(linewidth, lines);
+ byte *linebase = data, *pos;
+ byte *src = pointer->index_data;
+
+
+ for (yc = 0; yc < pointer->index_yl; yc++) {
+ int scalectr;
+ int bitc = 0;
+ pos = linebase;
+
+
+ for (xc = 0; xc < pointer->index_xl; xc++) {
+ int draw = mode?
+ (*src == 0) : (*src <
GFX_COLOR_INDEX_TRANSPARENT);
+
+ for (scalectr = 0; scalectr < xfact; scalectr++) {
+ if (draw)
+ *pos |= (1 << bitc);
+
+ bitc++;
+ if (bitc == 8) {
+ bitc = 0;
+ pos++;
+ }
+ }
+
+ src++;
+ }
+ for (scalectr = 1; scalectr < yfact; scalectr++)
+ memcpy(linebase + linewidth * scalectr, linebase,
linewidth);
+
+ linebase += linewidth * yfact;
+ }
+
+ return data;
+}
+
Index: src/gfx/drivers/xlib_driver.c
===================================================================
--- src/gfx/drivers/xlib_driver.c (revision 1509)
+++ src/gfx/drivers/xlib_driver.c (working copy)
@@ -1020,50 +1020,6 @@
/*** Mouse pointer operations ***/
-byte *
-xlib_create_cursor_data(gfx_driver_t *drv, gfx_pixmap_t *pointer, int mode)
-{
- int linewidth = (pointer->xl + 7) >> 3;
- int lines = pointer->yl;
- int xc, yc;
- int xfact = drv->mode->xfact;
- byte *data = sci_calloc(linewidth, lines);
- byte *linebase = data, *pos;
- byte *src = pointer->index_data;
-
-
- for (yc = 0; yc < pointer->index_yl; yc++) {
- int scalectr;
- int bitc = 0;
- pos = linebase;
-
-
- for (xc = 0; xc < pointer->index_xl; xc++) {
- int draw = mode?
- (*src == 0) : (*src < 255);
-
- for (scalectr = 0; scalectr < xfact; scalectr++) {
- if (draw)
- *pos |= (1 << bitc);
-
- bitc++;
- if (bitc == 8) {
- bitc = 0;
- pos++;
- }
- }
-
- src++;
- }
- for (scalectr = 1; scalectr < drv->mode->yfact; scalectr++)
- memcpy(linebase + linewidth * scalectr, linebase,
linewidth);
-
- linebase += linewidth * drv->mode->yfact;
- }
-
- return data;
-}
-
static int
xlib_set_pointer(struct _gfx_driver *drv, gfx_pixmap_t *pointer)
{
@@ -1094,8 +1050,8 @@
cols[i].blue |= (cols[i].blue << 8);
}
- S->pointer_data[0] = visual_data = xlib_create_cursor_data(drv,
pointer, 1);
- S->pointer_data[1] = mask_data = xlib_create_cursor_data(drv,
pointer, 0);
+ visual_data = gfx_create_mono_cursor_mask(pointer,
drv->mode->xfact, drv->mode->yfact, 1);
+ mask_data = gfx_create_mono_cursor_mask(pointer,
drv->mode->xfact, drv->mode->yfact, 0);
S->pointer_data[0] = NULL;
S->pointer_data[1] = NULL;
visual = XCreateBitmapFromData(S->display, S->window, (char *)
visual_data, real_xl, pointer->yl);
Index: ChangeLog
===================================================================
--- ChangeLog (revision 1521)
+++ ChangeLog (working copy)
@@ -1,5 +1,9 @@
2006-02-05 Christoph Reichenbach <[EMAIL PROTECTED]>
+ * src/gfx/gfx_support.c (gfx_create_mono_cursor_mask): Relocated
+ cursor bitmask computation to a place where it is more easily
+ re-usable
+
* src/sound/pcmout_alsa.c: ALSA pcmout now has a 'device'
parameter (default is still "hw:0,0")
_______________________________________________
FreeSCI-develop mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/freesci-develop