FreeBASIC  0.91.0
gfx_point.c
Go to the documentation of this file.
1 /* pixel retrieving */
2 
3 #include "fb_gfx.h"
4 
5 
6 /*:::::*/
7 FBCALL int fb_GfxPoint(void *target, float fx, float fy)
8 {
10  int x, y;
11  unsigned int color;
12 
13  if (!__fb_gfx)
14  return -1;
15 
16  if( fy == -8388607.0 )
17  return fb_GfxCursor(fx);
18 
19  fb_hPrepareTarget(context, target);
21 
22  fb_hTranslateCoord(context, fx, fy, &x, &y);
23 
24  if ((x < context->view_x) || (y < context->view_y) ||
25  (x >= context->view_x + context->view_w) || (y >= context->view_y + context->view_h))
26  return -1;
27 
28  DRIVER_LOCK();
29  color = context->get_pixel(context, x, y);
30  DRIVER_UNLOCK();
31 
32  if (__fb_gfx->depth == 16)
33  /* approximate: for each component we also report high bits in lower bits of new value */
34  color = (((color & 0x001F) << 3) | ((color >> 2) & 0x7) |
35  ((color & 0x07E0) << 5) | ((color >> 1) & 0x300) |
36  ((color & 0xF800) << 8) | ((color << 3) & 0x70000));
37 
38  return (int)color;
39 }