FreeBASIC  0.91.0
gfx_get.c
Go to the documentation of this file.
1 /* GET statement */
2 
3 #include "fb_gfx.h"
4 
5 
6 /*:::::*/
7 static int gfx_get(void *target, float fx1, float fy1, float fx2, float fy2, unsigned char *dest, int coord_type, FBARRAY *array, int usenewheader )
8 {
10  PUT_HEADER *header;
11  int x1, y1, x2, y2, w, h, pitch;
12 
13  if (!__fb_gfx)
15 
16  fb_hPrepareTarget(context, target);
18 
19  fb_hFixRelative(context, coord_type, &fx1, &fy1, &fx2, &fy2);
20 
21  fb_hTranslateCoord(context, fx1, fy1, &x1, &y1);
22  fb_hTranslateCoord(context, fx2, fy2, &x2, &y2);
23 
24  fb_hFixCoordsOrder(&x1, &y1, &x2, &y2);
25 
26  if ((x1 < context->view_x) || (y1 < context->view_y) ||
27  (x2 >= context->view_x + context->view_w) || (y2 >= context->view_y + context->view_h))
29 
30  w = x2 - x1 + 1;
31  h = y2 - y1 + 1;
32 
33  header = (PUT_HEADER *)dest;
34  if (!usenewheader) {
35  /* use old-style header for compatibility */
36  header->old.bpp = context->target_bpp;
37  header->old.width = w;
38  header->old.height = h;
39  pitch = w * context->target_bpp;
40  dest += 4;
41  }
42  else {
43  /* use new-style header */
44  header->type = PUT_HEADER_NEW;
45  header->width = w;
46  header->height = h;
47  header->bpp = context->target_bpp;
48  pitch = header->pitch = ((w * context->target_bpp) + 0xF) & ~0xF;
49  dest += sizeof(PUT_HEADER);
50  }
51 
52  if( array != NULL ) {
53  if ((array->size > 0) && ((intptr_t)dest + (pitch * h) > (intptr_t)array->data + array->size))
55  }
56 
57  DRIVER_LOCK();
58 
59  for (; y1 <= y2; y1++) {
60  fb_hPixelCpy(dest, context->line[y1] + (x1 * context->target_bpp), w);
61  dest += pitch;
62  }
63 
64  DRIVER_UNLOCK();
65 
66  return fb_ErrorSetNum( FB_RTERROR_OK );
67 }
68 
69 /*:::::*/
70 FBCALL int fb_GfxGet(void *target, float fx1, float fy1, float fx2, float fy2, unsigned char *dest, int coord_type, FBARRAY *array)
71 {
72  return gfx_get( target, fx1, fy1, fx2, fy2, dest, coord_type, array, TRUE );
73 }
74 
75 /*:::::*/
76 FBCALL int fb_GfxGetQB(void *target, float fx1, float fy1, float fx2, float fy2, unsigned char *dest, int coord_type, FBARRAY *array)
77 {
78  return gfx_get( target, fx1, fy1, fx2, fy2, dest, coord_type, array, FALSE );
79 }