Ejemplo n.º 1
0
static int		recv_screen	(CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap)
{
	uint32_t size = 0;
	uint8_t cmd, *data;
	int retval;
	int type;
	CalcInfos infos;

	// First of all, we have to identify the Nspire model.
	retval = get_version(handle, &infos);
	if (!retval)
	{
		if (infos.bits_per_pixel == 4)
		{
			// Nspire (CAS) Clickpad or Touchpad.
			type = 0;
		}
		else if (infos.bits_per_pixel == 16)
		{
			// Nspire (CAS) CX.
			type = 1;
		}
		else
		{
			ticalcs_critical(_("Unknown calculator model with %d bpp\n"), infos.bits_per_pixel);
			return ERR_UNSUPPORTED; // THIS RETURNS !
		}

		// Do screenshot
		TRYF(nsp_session_open(handle, SID_SCREEN_RLE));

		TRYF(nsp_cmd_s_screen_rle(handle, 0));
		TRYF(nsp_cmd_r_screen_rle(handle, &cmd, &size, &data));
		sc->width = sc->clipped_width = (data[8] << 8) | data[9];
		sc->height = sc->clipped_height = (data[10] << 8) | data[11];
		//size = GUINT32_FROM_BE(*((uint32_t *)(data)));
		size = (  (((uint32_t)data[0]) << 24)
		        | (((uint32_t)data[1]) << 16)
		        | (((uint32_t)data[2]) <<  8)
		        | (((uint32_t)data[3])      ));
		TRYF(nsp_cmd_r_screen_rle(handle, &cmd, &size, &data));

		TRYF(nsp_session_close(handle));

		*bitmap = rle_uncompress(sc, data, size, type);
		g_free(data);

		if(*bitmap == NULL)
		{
			return ERR_MALLOC;
		}

		retval = 0;
	}

	return retval;
}
Ejemplo n.º 2
0
static int		recv_screen	(CalcHandle* handle, CalcScreenCoord* sc, uint8_t** bitmap)
{
	int ret;
	CalcInfos infos;

	// First of all, we have to identify the Nspire model.
	ret = get_version(handle, &infos);
	if (!ret)
	{
		if (infos.bits_per_pixel == 4)
		{
			// Nspire (CAS) Clickpad or Touchpad.
			sc->pixel_format = CALC_PIXFMT_GRAY_4;
		}
		else if (infos.bits_per_pixel == 16)
		{
			// Nspire (CAS) CX or CM.
			sc->pixel_format = CALC_PIXFMT_RGB_565_LE;
		}
		else
		{
			ticalcs_critical(_("Unknown calculator model with %d bpp\n"), infos.bits_per_pixel);
			return ERR_UNSUPPORTED; // THIS RETURNS !
		}

		// Do screenshot
		ret = nsp_session_open(handle, NSP_SID_SCREEN_RLE);
		if (!ret)
		{
			ret = nsp_cmd_s_screen_rle(handle, 0);
			if (!ret)
			{
				uint32_t size = 0;
				uint8_t cmd, *data;

				ret = nsp_cmd_r_screen_rle(handle, &cmd, &size, &data);
				if (!ret)
				{
					sc->width = sc->clipped_width = (((uint16_t)data[8]) << 8) | data[9];
					sc->height = sc->clipped_height = (((uint16_t)data[10]) << 8) | data[11];
					size = (  (((uint32_t)data[0]) << 24)
					        | (((uint32_t)data[1]) << 16)
					        | (((uint32_t)data[2]) <<  8)
					        | (((uint32_t)data[3])      ));
					g_free(data);

					if (sc->width > 320)
					{
						ticalcs_critical("%s: no calculator model known to this library has screens of width > 320 pixels", __FUNCTION__);
						ret = ERR_INVALID_PACKET;
					}
					else if (sc->height > 240)
					{
						ticalcs_critical("%s: no calculator model known to this library has screens of height > 240 pixels", __FUNCTION__);
						ret = ERR_INVALID_PACKET;
					}
					else if (size > 2 * sc->width * sc->height)
					{
						ticalcs_critical("%s: no calculator model known to this library uses more than 16 bpp", __FUNCTION__);
						ret = ERR_INVALID_PACKET;
					}
					else
					{
						ret = nsp_cmd_r_screen_rle(handle, &cmd, &size, &data);
						if (!ret)
						{
							uint32_t len = sc->width * sc->height * infos.bits_per_pixel / 8;
							uint8_t * dst = ticalcs_alloc_screen(len);
							if (dst != NULL)
							{
								ret = ticalcs_screen_nspire_rle_uncompress(sc->pixel_format, data, size, dst, len);
								if (!ret)
								{
									*bitmap = dst;
								}
								else
								{
									ticalcs_free_screen(dst);
								}
							}
							else
							{
								ret = ERR_MALLOC;
							}
							g_free(data);
						}
					}
				}
			}

			DO_CLOSE_SESSION(handle);
		}
	}

	return ret;
}