コード例 #1
0
ファイル: pixma_mp750.c プロジェクト: Ichoran/lifespan
static int
request_image_block_ex (pixma_t * s, unsigned *size, uint8_t * info,
			unsigned flag)
{
  mp750_t *mp = (mp750_t *) s->subdriver;
  int error;

  memset (mp->cb.buf, 0, 10);
  pixma_set_be16 (cmd_read_image, mp->cb.buf);
  mp->cb.buf[7] = *size >> 8;
  mp->cb.buf[8] = 4 | flag;
  mp->cb.reslen = pixma_cmd_transaction (s, mp->cb.buf, 10, mp->cb.buf, 6);
  mp->cb.expected_reslen = 0;
  error = pixma_check_result (&mp->cb);
  if (error >= 0)
    {
      if (mp->cb.reslen == 6)
        {
          *info = mp->cb.buf[2];
          *size = pixma_get_be16 (mp->cb.buf + 4);
        }
      else
        {
          error = PIXMA_EPROTO;
        }
    }
  return error;
}
コード例 #2
0
ファイル: pixma_imageclass.c プロジェクト: Ichoran/lifespan
static int
request_image_block (pixma_t * s, unsigned flag, uint8_t * info,
		     unsigned * size, uint8_t * data, unsigned * datalen)
{
  iclass_t *mf = (iclass_t *) s->subdriver;
  int error;
  unsigned expected_len;
  const int hlen = 2 + 6;

  memset (mf->cb.buf, 0, 11);
  pixma_set_be16 (((s->cfg->pid == MF3010_PID ||
                    s->cfg->pid == MF4410_PID ||
                    s->cfg->pid == MF4770_PID ||
                    s->cfg->pid == MF4550_PID) ? cmd_read_image2 : cmd_read_image), mf->cb.buf);
  mf->cb.buf[8] = flag;
  mf->cb.buf[10] = 0x06;
  expected_len = (s->cfg->pid == MF3010_PID ||
                  s->cfg->pid == MF4410_PID ||
                  s->cfg->pid == MF4770_PID ||
                  s->cfg->pid == MF4550_PID ||
                  s->cfg->pid == MF4600_PID ||
                  s->cfg->pid == MF6500_PID ||
                  s->cfg->pid == MF8030_PID) ? 512 : hlen;
  mf->cb.reslen = pixma_cmd_transaction (s, mf->cb.buf, 11, mf->cb.buf, expected_len);
  if (mf->cb.reslen >= hlen)
    {
      *info = mf->cb.buf[2];
      *size = pixma_get_be16 (mf->cb.buf + 6);    /* 16bit size */
      error = 0;

      if (s->cfg->pid == MF3010_PID ||
          s->cfg->pid == MF4410_PID ||
          s->cfg->pid == MF4770_PID ||
          s->cfg->pid == MF4550_PID ||
          s->cfg->pid == MF4600_PID ||
          s->cfg->pid == MF6500_PID ||
          s->cfg->pid == MF8030_PID)
        {                                         /* 32bit size */
          *datalen = mf->cb.reslen - hlen;
          *size = (*datalen + hlen == 512) ? pixma_get_be32 (mf->cb.buf + 4) - *datalen : 0;
          memcpy (data, mf->cb.buf + hlen, *datalen);
        }
    }
  else
    {
       error = PIXMA_EPROTO;
    }
  return error;
}
コード例 #3
0
ファイル: pixma_mp730.c プロジェクト: DspaceSPI/SPIScan
static int
mp730_fill_buffer (pixma_t * s, pixma_imagebuf_t * ib)
{
  int error, n;
  mp730_t *mp = (mp730_t *) s->subdriver;
  unsigned block_size, bytes_received;
  uint8_t header[16];

  do
    {
      do
	{
	  if (s->cancel)
	    return PIXMA_ECANCELED;
	  if (mp->last_block)           /* end of image */
	      return 0;

	  error = read_image_block (s, header, mp->imgbuf + mp->imgbuf_len);
	  if (error < 0)
	    return error;

	  bytes_received = error;
	  block_size = pixma_get_be16 (header + 4);
	  mp->last_block = ((header[2] & 0x28) == 0x28);
	  if (mp->last_block)
	    {    /* end of image */
	      mp->state = state_finished;
	    }
	  if ((header[2] & ~0x38) != 0)
	    {
	      PDBG (pixma_dbg (1, "WARNING: Unexpected result header\n"));
	      PDBG (pixma_hexdump (1, header, 16));
	    }
	  PASSERT (bytes_received == block_size);

	  if (block_size == 0)
	    {
	      /* no image data at this moment. */
	      /*pixma_sleep(100000); *//* FIXME: too short, too long? */
	      handle_interrupt (s, 100);
            }
	}
      while (block_size == 0);

      /* TODO: simplify! */
      mp->imgbuf_len += bytes_received;
      n = mp->imgbuf_len / s->param->line_size;
      /* n = number of full lines (rows) we have in the buffer. */
      if (n != 0)
	{
	  if (s->param->channels != 1    &&
	      s->cfg->pid != MF5730_PID  &&
	      s->cfg->pid != MF5750_PID  &&
	      s->cfg->pid != MF5770_PID  &&
	      s->cfg->pid != MF3110_PID  &&
	      s->cfg->pid != IR1020_PID)
	    {
	      /* color, and not an MF57x0 nor MF3110 */
	      pack_rgb (mp->imgbuf, n, mp->raw_width, mp->lbuf);
	    }
	  else
             /* grayscale/lineart or MF57x0 or MF3110 */
             memcpy (mp->lbuf, mp->imgbuf, n * s->param->line_size);

	  block_size = n * s->param->line_size;
	  mp->imgbuf_len -= block_size;
	  memcpy (mp->imgbuf, mp->imgbuf + block_size, mp->imgbuf_len);
	}
    }
  while (n == 0);

  ib->rptr = mp->lbuf;
  ib->rend = mp->lbuf + block_size;
  return ib->rend - ib->rptr;
}