Esempio n. 1
0
static int qb_get_varaible_details(qb_storage *storage, qb_variable *qvar, qb_debug_variable_details **p_details) {
	qb_debug_variable_details *details = NULL;
	if(qvar) {
		details = malloc(sizeof(qb_debug_variable_details));
		if(details) {
			uint32_t i, element_count;
			qb_address *address = qvar->address;
			details->bitness = BYTE_COUNT(8, address->type);
			details->flags = 0;
			if(address->type & QB_TYPE_UNSIGNED) {
				details->flags |= QB_VAR_IS_UNSIGNED;
			}
			if(address->type >= QB_TYPE_F32) {
				details->flags |= QB_VAR_IS_FLOAT;
			} else {
				details->flags |= QB_VAR_IS_INTEGER;
			}
			if(address->flags & QB_ADDRESS_STRING) {
				details->flags |= QB_VAR_IS_STRING;
			} else if(address->flags & QB_ADDRESS_BOOLEAN) {
				details->flags |= QB_VAR_IS_BOOL;
			} else if(address->flags & QB_ADDRESS_IMAGE) {
				details->flags |= QB_VAR_IS_IMAGE;
			} else {
				if(qvar->value) {
					gdImagePtr image = qb_get_gd_image(qvar->value);
					if(image && image->trueColor) {
						details->flags |= QB_VAR_IS_IMAGE;
					}
				}
			}
			details->dimension_count = address->dimension_count;
			for(i = 0; i < QB_MAXIMUM_DIMENSION_COUNT; i++) {
				if(i < details->dimension_count) {
					details->dimensions[i] = VALUE_IN(storage, U32, address->dimension_addresses[i]);
				} else {
					details->dimensions[i] = 0;
				}
			}
			if(details->dimension_count > 0) {
				element_count = VALUE_IN(storage, U32, address->array_size_address);
			} else {
				element_count = 1;
			}
			details->byte_count = BYTE_COUNT(element_count, address->type);
			details->data = ARRAY_IN(storage, I08, address);
			details->variable = qvar;
		}
	}
	if(p_details) {
		*p_details = details;
	} else {
		qb_debug_free_variable_details(details);
	}
	return (details != NULL);
}
Esempio n. 2
0
static int32_t qb_transfer_operands_unpack(qb_compiler_context *cxt, qb_op_factory *f, uint32_t flags, qb_operand *operands, uint32_t operand_count, qb_operand *result, qb_operand *dest, uint32_t dest_count) {
	qb_operand *string = &operands[0], *index = &operands[1];
	qb_address *substring_address;
	if(index->type == QB_OPERAND_ADDRESS) {
		uint32_t length = BYTE_COUNT(1, result->address->type);
		qb_address *length_address = qb_obtain_constant_U32(cxt, length);
		substring_address = qb_obtain_array_slice(cxt, string->address, index->address, length_address, QB_ARRAY_BOUND_CHECK_READ);
	} else {
		substring_address = string->address;
	}
	dest[0].address = substring_address;
	dest[0].type = QB_OPERAND_ADDRESS;
	dest[1] = *result;
	return TRUE;
}
Esempio n. 3
0
/*
 * Convert X cursor to Windows cursor
 * FIXME: Perhaps there are more smart code
 */
static HCURSOR
winLoadCursor (ScreenPtr pScreen, CursorPtr pCursor, int screen)
{
  winScreenPriv(pScreen);
  HCURSOR hCursor = NULL;
  unsigned char *pAnd;
  unsigned char *pXor;
  int nCX, nCY;
  int nBytes;
  double dForeY, dBackY;
  BOOL fReverse;
  HBITMAP hAnd, hXor;
  ICONINFO ii;
  unsigned char *pCur;
  int x, y;
  unsigned char bit;
  HDC hDC;
  BITMAPV4HEADER bi;
  BITMAPINFO *pbmi;
  unsigned long *lpBits;

  WIN_DEBUG_MSG("winLoadCursor: Win32: %dx%d X11: %dx%d hotspot: %d,%d\n", 
          pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy,
          pCursor->bits->width, pCursor->bits->height,
          pCursor->bits->xhot, pCursor->bits->yhot
          );

  /* We can use only White and Black, so calc brightness of color 
   * Also check if the cursor is inverted */  
  dForeY = BRIGHTNESS(pCursor->fore);
  dBackY = BRIGHTNESS(pCursor->back);
  fReverse = dForeY < dBackY;
 
  /* Check wether the X11 cursor is bigger than the win32 cursor */
  if (pScreenPriv->cursor.sm_cx < pCursor->bits->width || 
      pScreenPriv->cursor.sm_cy < pCursor->bits->height)
    {
      winErrorFVerb (2, "winLoadCursor - Windows requires %dx%d cursor\n"
	      "\tbut X requires %dx%d\n",
	      pScreenPriv->cursor.sm_cx, pScreenPriv->cursor.sm_cy,
	      pCursor->bits->width, pCursor->bits->height);
    }

  /* Get the number of bytes required to store the whole cursor image 
   * This is roughly (sm_cx * sm_cy) / 8 
   * round up to 8 pixel boundary so we can convert whole bytes */
  nBytes = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * pScreenPriv->cursor.sm_cy;

  /* Get the effective width and height */
  nCX = MIN(pScreenPriv->cursor.sm_cx, pCursor->bits->width);
  nCY = MIN(pScreenPriv->cursor.sm_cy, pCursor->bits->height);

  /* Allocate memory for the bitmaps */
  pAnd = malloc (nBytes);
  memset (pAnd, 0xFF, nBytes);
  pXor = calloc (1, nBytes);

  /* Convert the X11 bitmap to a win32 bitmap 
   * The first is for an empty mask */
  if (pCursor->bits->emptyMask)
    {
      int x, y, xmax = BYTE_COUNT(nCX);
      for (y = 0; y < nCY; ++y)
	for (x = 0; x < xmax; ++x)
	  {
	    int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + x;
	    int nXPix = BitmapBytePad(pCursor->bits->width) * y + x;

	    pAnd[nWinPix] = 0;
	    if (fReverse)
	      pXor[nWinPix] = reverse (~pCursor->bits->source[nXPix]);
	    else
	      pXor[nWinPix] = reverse (pCursor->bits->source[nXPix]);
	  }
    }
  else
    {
      int x, y, xmax = BYTE_COUNT(nCX);
      for (y = 0; y < nCY; ++y)
	for (x = 0; x < xmax; ++x)
	  {
	    int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + x;
	    int nXPix = BitmapBytePad(pCursor->bits->width) * y + x;

	    unsigned char mask = pCursor->bits->mask[nXPix];
	    pAnd[nWinPix] = reverse (~mask);
	    if (fReverse)
	      pXor[nWinPix] = reverse (~pCursor->bits->source[nXPix] & mask);
	    else
	      pXor[nWinPix] = reverse (pCursor->bits->source[nXPix] & mask);
	  }
    }

  /* prepare the pointers */ 
  hCursor = NULL;
  lpBits = NULL;

  /* We have a truecolor alpha-blended cursor and can use it! */
  if (pCursor->bits->argb) 
    {
      WIN_DEBUG_MSG("winLoadCursor: Trying truecolor alphablended cursor\n"); 
      memset (&bi, 0, sizeof (BITMAPV4HEADER));
      bi.bV4Size = sizeof(BITMAPV4HEADER);
      bi.bV4Width = pScreenPriv->cursor.sm_cx;
      bi.bV4Height = -(pScreenPriv->cursor.sm_cy); /* right-side up */
      bi.bV4Planes = 1;
      bi.bV4BitCount = 32;
      bi.bV4V4Compression = BI_BITFIELDS;
      bi.bV4RedMask = 0x00FF0000;
      bi.bV4GreenMask = 0x0000FF00;
      bi.bV4BlueMask = 0x000000FF;
      bi.bV4AlphaMask = 0xFF000000; 
      
      lpBits = (unsigned long *) calloc (pScreenPriv->cursor.sm_cx*pScreenPriv->cursor.sm_cy,
					 sizeof (unsigned long));
      
      if (lpBits)
	{
	  for (y=0; y<nCY; y++)
	    {
	      unsigned long *src, *dst;
	      src = &(pCursor->bits->argb[y * pCursor->bits->width]);
	      dst = &(lpBits[y * pScreenPriv->cursor.sm_cx]);
	      memcpy (dst, src, 4*nCX);
	    }
	}
    } /* End if-truecolor-icon */
  
  if (!lpBits)
    {
      /* Bicolor, use a palettized DIB */
      WIN_DEBUG_MSG("winLoadCursor: Trying two color cursor\n"); 
      pbmi = (BITMAPINFO*)&bi;
      memset (pbmi, 0, sizeof (BITMAPINFOHEADER));
      pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
      pbmi->bmiHeader.biWidth = pScreenPriv->cursor.sm_cx;
      pbmi->bmiHeader.biHeight = -abs(pScreenPriv->cursor.sm_cy); /* right-side up */
      pbmi->bmiHeader.biPlanes = 1;
      pbmi->bmiHeader.biBitCount = 8;
      pbmi->bmiHeader.biCompression = BI_RGB;
      pbmi->bmiHeader.biSizeImage = 0;
      pbmi->bmiHeader.biClrUsed = 3;
      pbmi->bmiHeader.biClrImportant = 3;
      pbmi->bmiColors[0].rgbRed = 0; /* Empty */
      pbmi->bmiColors[0].rgbGreen = 0;
      pbmi->bmiColors[0].rgbBlue = 0;
      pbmi->bmiColors[0].rgbReserved = 0;
      pbmi->bmiColors[1].rgbRed = pCursor->backRed>>8; /* Background */
      pbmi->bmiColors[1].rgbGreen = pCursor->backGreen>>8;
      pbmi->bmiColors[1].rgbBlue = pCursor->backBlue>>8;
      pbmi->bmiColors[1].rgbReserved = 0;
      pbmi->bmiColors[2].rgbRed = pCursor->foreRed>>8; /* Foreground */
      pbmi->bmiColors[2].rgbGreen = pCursor->foreGreen>>8;
      pbmi->bmiColors[2].rgbBlue = pCursor->foreBlue>>8;
      pbmi->bmiColors[2].rgbReserved = 0;
      
      lpBits = (unsigned long *) calloc (pScreenPriv->cursor.sm_cx*pScreenPriv->cursor.sm_cy,
					 sizeof (char));
      
      pCur = (unsigned char *)lpBits;
      if (lpBits)
	{
	  for (y=0; y<pScreenPriv->cursor.sm_cy; y++)
	    {
	      for (x=0; x<pScreenPriv->cursor.sm_cx; x++)
		{
		  if (x>=nCX || y>=nCY) /* Outside of X11 icon bounds */
		    (*pCur++) = 0;
		  else /* Within X11 icon bounds */
		    {
		      int nWinPix = BYTE_COUNT(pScreenPriv->cursor.sm_cx) * y + (x/8);

		      bit = pAnd[nWinPix];
		      bit = bit & (1<<(7-(x&7)));
		      if (!bit) /* Within the cursor mask? */
			{
			  int nXPix = BitmapBytePad(pCursor->bits->width) * y + (x/8);
			  bit = ~reverse(~pCursor->bits->source[nXPix] & pCursor->bits->mask[nXPix]);
			  bit = bit & (1<<(7-(x&7)));
			  if (bit) /* Draw foreground */
			    (*pCur++) = 2;
			  else /* Draw background */
			    (*pCur++) = 1;
			}
		      else /* Outside the cursor mask */
			(*pCur++) = 0;
		    }
		} /* end for (x) */
	    } /* end for (y) */
	} /* end if (lpbits) */
    }
Esempio n. 4
0
File: qb_encoder.c Progetto: 3CTO/qb
static int32_t qb_encode_element_size(qb_encoder_context *cxt, qb_address *address, int8_t **p_ip) {
	*((uint32_t *) *p_ip) = BYTE_COUNT(1, address->type);
	*p_ip += sizeof(uint32_t);
	return TRUE;
}