Beispiel #1
0
/*
 * fade function
 */
static void fade(int r1, int g1, int b1,
		 int r2, int g2, int b2,
		 uint32_t *yuy2_colors, int steps) {
  int i, r, g, b, y, u, v;

  for (i = 0; i < steps; i++) {
    r = r1 + (r2 - r1) * i / steps;
    g = g1 + (g2 - g1) * i / steps;
    b = b1 + (b2 - b1) * i / steps;

    y = COMPUTE_Y(r, g, b);
    u = COMPUTE_U(r, g, b);
    v = COMPUTE_V(r, g, b);

    *(yuy2_colors + i) = be2me_32((y << 24) |
				  (u << 16) |
				  (y << 8) |
				  v);

  }
}
Beispiel #2
0
static void rgb_decode_data (video_decoder_t *this_gen,
  buf_element_t *buf) {

  rgb_decoder_t *this = (rgb_decoder_t *) this_gen;
  xine_bmiheader *bih;
  palette_entry_t *palette;
  int i;
  int pixel_ptr, row_ptr;
  int palette_index;
  int buf_ptr;
  unsigned int packed_pixel;
  unsigned char r, g, b;
  int pixels_left;
  unsigned char pixel_byte = 0;

  vo_frame_t *img; /* video out frame */

  /* a video decoder does not care about this flag (?) */
  if (buf->decoder_flags & BUF_FLAG_PREVIEW)
    return;

  if ((buf->decoder_flags & BUF_FLAG_SPECIAL) &&
    (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) {
    palette = (palette_entry_t *)buf->decoder_info_ptr[2];
    for (i = 0; i < buf->decoder_info[2]; i++) {
      this->yuv_palette[i * 4 + 0] =
        COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b);
      this->yuv_palette[i * 4 + 1] =
        COMPUTE_U(palette[i].r, palette[i].g, palette[i].b);
      this->yuv_palette[i * 4 + 2] =
        COMPUTE_V(palette[i].r, palette[i].g, palette[i].b);
    }
  }

  if (buf->decoder_flags & BUF_FLAG_FRAMERATE) {
    this->video_step = buf->decoder_info[0];
    _x_stream_info_set(this->stream, XINE_STREAM_INFO_FRAME_DURATION, this->video_step);
  }

  if (buf->decoder_flags & BUF_FLAG_STDHEADER) { /* need to initialize */
    (this->stream->video_out->open) (this->stream->video_out, this->stream);

    bih = (xine_bmiheader *) buf->content;
    this->width = (bih->biWidth + 3) & ~0x03;
    this->height = (bih->biHeight + 3) & ~0x03;
    if (this->height < 0) {
      this->upside_down = 1;
      this->height = -this->height;
    } else {
      this->upside_down = 0;
    }
    this->ratio = (double)this->width/(double)this->height;

    this->bit_depth = bih->biBitCount;
    if (this->bit_depth > 32)
      this->bit_depth &= 0x1F;
    /* round this number up in case of 15 */
    lprintf("width = %d, height = %d, bit_depth = %d\n", this->width, this->height, this->bit_depth);

    this->bytes_per_pixel = (this->bit_depth + 1) / 8;

    free (this->buf);

    /* minimal buffer size */
    this->bufsize = this->width * this->height * this->bytes_per_pixel;
    this->buf = calloc(1, this->bufsize);
    this->size = 0;

    init_yuv_planes(&this->yuv_planes, this->width, this->height);

    (this->stream->video_out->open) (this->stream->video_out, this->stream);
    this->decoder_ok = 1;

    /* load the stream/meta info */
    _x_meta_info_set_utf8(this->stream, XINE_META_INFO_VIDEOCODEC, "Raw RGB");

    return;
  } else if (this->decoder_ok) {

    if (this->size + buf->size > this->bufsize) {
      this->bufsize = this->size + 2 * buf->size;
      this->buf = realloc (this->buf, this->bufsize);
    }
    xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size);

    this->size += buf->size;

    if (buf->decoder_flags & BUF_FLAG_FRAME_END) {

      img = this->stream->video_out->get_frame (this->stream->video_out,
                                        this->width, this->height,
                                        this->ratio, XINE_IMGFMT_YUY2,
                                        VO_BOTH_FIELDS);

      img->duration  = this->video_step;
      img->pts       = buf->pts;
      img->bad_frame = 0;


      /* iterate through each row */
      buf_ptr = 0;

      if (this->upside_down) {
        for (row_ptr = this->yuv_planes.row_width * (this->yuv_planes.row_count - 1);
          row_ptr >= 0; row_ptr -= this->yuv_planes.row_width) {
          for (pixel_ptr = 0; pixel_ptr < this->width; pixel_ptr++) {

            if (this->bytes_per_pixel == 1) {

              palette_index = this->buf[buf_ptr++];

              this->yuv_planes.y[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 0];
              this->yuv_planes.u[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 1];
              this->yuv_planes.v[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 2];

            } else if (this->bytes_per_pixel == 2) {

              /* ABGR1555 format, little-endian order */
              packed_pixel = _X_LE_16(&this->buf[buf_ptr]);
              buf_ptr += 2;
              UNPACK_BGR15(packed_pixel, r, g, b);

              this->yuv_planes.y[row_ptr + pixel_ptr] =
                COMPUTE_Y(r, g, b);
              this->yuv_planes.u[row_ptr + pixel_ptr] =
                COMPUTE_U(r, g, b);
              this->yuv_planes.v[row_ptr + pixel_ptr] =
                COMPUTE_V(r, g, b);

            } else {

              /* BGR24 or BGRA32 */
              b = this->buf[buf_ptr++];
              g = this->buf[buf_ptr++];
              r = this->buf[buf_ptr++];

              /* the next line takes care of 'A' in the 32-bit case */
              buf_ptr += this->bytes_per_pixel - 3;

              this->yuv_planes.y[row_ptr + pixel_ptr] =
                COMPUTE_Y(r, g, b);
              this->yuv_planes.u[row_ptr + pixel_ptr] =
                COMPUTE_U(r, g, b);
              this->yuv_planes.v[row_ptr + pixel_ptr] =
                COMPUTE_V(r, g, b);

            }
          }
        }
      } else {

        for (row_ptr = 0; row_ptr < this->yuv_planes.row_width * this->yuv_planes.row_count; row_ptr += this->yuv_planes.row_width) {
          pixels_left = 0;
          for (pixel_ptr = 0; pixel_ptr < this->width; pixel_ptr++) {

            if (this->bit_depth == 1) {

              if (pixels_left == 0) {
                pixels_left = 8;
                pixel_byte = *this->buf++;
              }

              if (pixel_byte & 0x80) {
                this->yuv_planes.y[row_ptr + pixel_ptr] =
                  this->yuv_palette[1 * 4 + 0];
                this->yuv_planes.u[row_ptr + pixel_ptr] =
                  this->yuv_palette[1 * 4 + 1];
                this->yuv_planes.v[row_ptr + pixel_ptr] =
                  this->yuv_palette[1 * 4 + 2];
              } else {
                this->yuv_planes.y[row_ptr + pixel_ptr] =
                  this->yuv_palette[0 * 4 + 0];
                this->yuv_planes.u[row_ptr + pixel_ptr] =
                  this->yuv_palette[0 * 4 + 1];
                this->yuv_planes.v[row_ptr + pixel_ptr] =
                  this->yuv_palette[0 * 4 + 2];
              }
              pixels_left--;
              pixel_byte <<= 1;

            } else if (this->bit_depth == 2) {

              if (pixels_left == 0) {
                pixels_left = 4;
                pixel_byte = *this->buf++;
              }

              palette_index = (pixel_byte & 0xC0) >> 6;
              this->yuv_planes.y[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 0];
              this->yuv_planes.u[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 1];
              this->yuv_planes.v[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 2];

              pixels_left--;
              pixel_byte <<= 2;

            } else if (this->bit_depth == 4) {

              if (pixels_left == 0) {
                pixels_left = 2;
                pixel_byte = *this->buf++;
              }

              palette_index = (pixel_byte & 0xF0) >> 4;
              this->yuv_planes.y[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 0];
              this->yuv_planes.u[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 1];
              this->yuv_planes.v[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 2];

              pixels_left--;
              pixel_byte <<= 4;

            } else if (this->bytes_per_pixel == 1) {

              palette_index = this->buf[buf_ptr++];

              this->yuv_planes.y[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 0];
              this->yuv_planes.u[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 1];
              this->yuv_planes.v[row_ptr + pixel_ptr] =
                this->yuv_palette[palette_index * 4 + 2];

            } else if (this->bytes_per_pixel == 2) {

              /* ARGB1555 format, big-endian order */
              packed_pixel = _X_BE_16(&this->buf[buf_ptr]);
              buf_ptr += 2;
              UNPACK_RGB15(packed_pixel, r, g, b);

              this->yuv_planes.y[row_ptr + pixel_ptr] =
                COMPUTE_Y(r, g, b);
              this->yuv_planes.u[row_ptr + pixel_ptr] =
                COMPUTE_U(r, g, b);
              this->yuv_planes.v[row_ptr + pixel_ptr] =
                COMPUTE_V(r, g, b);

            } else {

              /* RGB24 or ARGB32; the next line takes care of 'A' in the
               * 32-bit case */
              buf_ptr += this->bytes_per_pixel - 3;

              r = this->buf[buf_ptr++];
              g = this->buf[buf_ptr++];
              b = this->buf[buf_ptr++];

              this->yuv_planes.y[row_ptr + pixel_ptr] =
                COMPUTE_Y(r, g, b);
              this->yuv_planes.u[row_ptr + pixel_ptr] =
                COMPUTE_U(r, g, b);
              this->yuv_planes.v[row_ptr + pixel_ptr] =
                COMPUTE_V(r, g, b);

            }
          }
        }
      }
void TimeFace::DrawHand(Bitmap *destination, int cx, int cy, HandType hand, Fixed degrees)
{
	PRECOMPUTE_ANGLE(degrees);
	bool drawBall = false;
	bool generateArrow = false;
	int lineCount = 0;
	struct {
		int x1, y1, x2, y2;
	} line[4];
	int max = destination->Width();
	line[0].x1 = line[0].x2 = 0;
	switch (hand)
	{
		case htHour:
			line[0].y1 = 0;
			line[0].y2 = max / 4;
			lineCount = 1;
			generateArrow = true;
			break;
		case htMinute:
			line[0].y1 = 0;
			line[0].y2 = (max / 2) - 10;
			lineCount = 1;
			generateArrow = true;
			break;
		case htSecond:
			line[0].y1 = -7;
			line[0].y2 = max / 2;
			lineCount = 1;
			drawBall = true;
			break;
		case htTick:
			line[0].y2 = max / 2;
			line[0].y1 = line[0].y2 - 5;
			lineCount = 1;
			break;
	}
	if (generateArrow)
	{
		line[1].y1 = line[1].y2 = line[0].y2;
		line[1].x1 = -3;
		line[1].x2 = 3;
		line[2].x1 = line[1].x1; line[2].y1 = line[1].y1;
		line[3].x1 = line[1].x2; line[3].y1 = line[1].y2;
		line[2].x2 = line[3].x2 = 0;
		line[2].y2 = line[3].y2 = line[1].y1 + 3;
		lineCount = 4;
	}
	Fixed fcx = cx; Fixed fcy = cy;
	for (int i = 0; i < lineCount; i++)
	{
		Fixed x1 = COMPUTE_X(line[i].x1, line[i].y1) + fcx;
		Fixed y1 = COMPUTE_Y(line[i].x1, line[i].y1) + fcy;
		Fixed x2 = COMPUTE_X(line[i].x2, line[i].y2) + fcx;
		Fixed y2 = COMPUTE_Y(line[i].x2, line[i].y2) + fcy;
		destination->Line(x1, y1, x2, y2, true);
	}
	if (drawBall)
	{
		Fixed x = COMPUTE_X(line[0].x1, line[0].y1) + fcx;
		Fixed y = COMPUTE_Y(line[0].x1, line[0].y1) + fcy;
		destination->Circle(x, y, 3, true);
	}
}