示例#1
0
void
uidisplay_area( int x, int y, int w, int h )
{
  float scale = (float)wiidisplay_current_size / image_scale;
  int scaled_x, scaled_y, i, yy;
  libspectrum_dword *palette;

  /* Extend the dirty region by 1 pixel for scalers
     that "smear" the screen, e.g. 2xSAI */
  if( scaler_flags & SCALER_FLAGS_EXPAND )
    scaler_expander( &x, &y, &w, &h, image_width, image_height );

  scaled_x = scale * x; scaled_y = scale * y;

  palette = settings_current.bw_tv ? bw_colours : wiidisplay_colours;

  /* Create the RGB image */
  for( yy = y; yy < y + h; yy++ ) {

    libspectrum_dword *rgb; libspectrum_word *display;

    rgb = (libspectrum_dword*)( rgb_image + ( yy + 2 ) * rgb_pitch );
    rgb += x + 1;

    display = &display_image[yy][x];

    for( i = 0; i < w; i++, rgb++, display++ ) *rgb = palette[ *display ];
  }

  /* Create scaled image */
  scaler_proc32( &rgb_image[ ( y + 2 ) * rgb_pitch + 4 * ( x + 1 ) ],
                 rgb_pitch,
                 &scaled_image[ scaled_y * scaled_pitch + 4 * scaled_x ],
                 scaled_pitch, w, h );

  w *= scale; h *= scale;

  /* Blit to the real screen */
  int disp_x,disp_y;
  long ofs;
  u16 fb_pitch = rmode->fbWidth / 2;
  /* ystart is an offset to center spectrum screen on wii screen */
  int ystart = ( rmode->xfbHeight - 2 * DISPLAY_SCREEN_HEIGHT ) / 4;
  u32 *dest, *next_line;

  if( scaled_x%2 ) {
    scaled_x -= 1;
    w += 1;
  }

/* FIXME: optimize this procedure and implement double buffering */
  next_line = xfb + scaled_x / 2 + ( scaled_y + ystart ) * fb_pitch;

  for( disp_y = scaled_y; disp_y < scaled_y + h; disp_y++ ) {

    dest = next_line;

    for( disp_x = scaled_x; disp_x < scaled_x + w; disp_x++ ) {
      ofs = ( 4 * disp_x ) + ( scaled_pitch * disp_y );

      rgb_t rgb1, rgb2;

      rgb1.b = scaled_image[ ofs + 2 ]; /* blue */
      rgb1.g = scaled_image[ ofs + 1 ]; /* green */
      rgb1.r = scaled_image[ ofs + 0 ]; /* red */

      rgb2.b = scaled_image[ ofs + 2 + 4 ]; /* blue */
      rgb2.g = scaled_image[ ofs + 1 + 4 ]; /* green */
      rgb2.r = scaled_image[ ofs + 0 + 4 ]; /* red */

      *dest = convert_rgb( rgb1, rgb2 );
      
      dest += disp_x%2;
    }
    next_line += fb_pitch;
  }
}
示例#2
0
void CX264Encoder::encode()
{
	//MessageBox(NULL, TEXT("1"), TEXT("remote preview"), MB_OK);
	if (x264_picture_alloc(&pic, param.i_csp, param.i_width, param.i_height) < 0){
		return;
	}
	//MessageBox(NULL, TEXT("2"), TEXT("remote preview"), MB_OK);
	while (!b_stop){
		uv_mutex_lock(&queue_mutex);
		if (sample_queue.size() == 0){
			//uv_mutex_unlock(&queue_mutex);
			int ret = uv_cond_timedwait(&queue_not_empty, &queue_mutex, (uint64_t)(5000 * 1e6));
			if (ret == UV_ETIMEDOUT){
				uv_mutex_unlock(&queue_mutex);
				MessageBox(NULL, TEXT("BUFFER EMPTY!"), TEXT("remote preview"), MB_OK);
				return;
			}
		}

		
		cc_src_sample_t buf = sample_queue.front();
		pic.i_pts = i_frame++;
		int64_t ticks_per_frame = buf.end - buf.start;
		TCHAR m[248];
		swprintf(m, TEXT("len: %d; width: %d; height: %d"), buf.len, param.i_width, param.i_height);
		//MessageBox(NULL, m, TEXT("remote preview"), MB_OK);
		if (param.i_csp == X264_CSP_RGB){
			convert_rgb(pic.img.plane[0], buf.buf[0], param.i_width, param.i_height);
			//memcpy(pic.img.plane[0], buf.buf[0], buf.line[0]*param.i_height);
		}
		else {
			//for (int i = 0; i < buf.iplan; i++){
			//	memcpy(pic.img.plane[i], buf.buf[i], buf.line[i]);
			//}
			memcpy(pic.img.plane[0], buf.buf[0], buf.line[0] * param.i_height);

			memcpy(pic.img.plane[1], buf.buf[1], buf.line[1] * param.i_height / 2);

			memcpy(pic.img.plane[2], buf.buf[2], buf.line[2] * param.i_height / 2);
		}
		//MessageBox(NULL, TEXT("3"), TEXT("remote preview"), MB_OK);
		i_frame_size = x264_encoder_encode(h, &nal, &i_nal, &pic, &pic_out);
		//MessageBox(NULL, TEXT("4"), TEXT("remote preview"), MB_OK);
		if (i_frame_size < 0)
			break;
		else if (i_frame_size)
		{
			//TODO:encode success
			if (fn_cb){
				int i;
				for (i = 0; i < i_nal; i++){
					cc_src_sample_t out_smple;
					out_smple.sync = !!pic_out.b_keyframe;
					out_smple.start = pic_out.i_pts;
					out_smple.end = pic_out.i_pts + ticks_per_frame;
					out_smple.buf[0] = (uint8_t*)malloc(nal[i].i_payload);
					out_smple.len = nal[i].i_payload;
					out_smple.iplan = 1;
					memcpy(out_smple.buf[0], nal[i].p_payload, nal[i].i_payload);
					//MessageBox(NULL, TEXT("5"), TEXT("remote preview"), MB_OK);
					fn_cb(out_smple, p_user_data);
					if (!fd){
						fd = fopen("src.264", "wb");
						if (fd)
							;// MessageBox(NULL, TEXT("create file!"), TEXT("x264 encoder"), MB_OK);
						else
							MessageBox(NULL, TEXT("create file false!"), TEXT("x264 encoder"), MB_OK);
					}
					if (fd){
						fwrite(out_smple.buf[0], 1, out_smple.len, fd);
					}
					free(out_smple.buf[0]);
				}
			}
		}
		//MessageBox(NULL, TEXT("6"), TEXT("remote preview"), MB_OK);
		sample_queue.pop_front();
		for (int i = 0; i < buf.iplan; i++){
			free(buf.buf[i]);
		}
		uv_mutex_unlock(&queue_mutex);
	}

	while (encode_delay()){
		i_frame_size = x264_encoder_encode(h, &nal, &i_nal, NULL, &pic_out);
		if (i_frame_size < 0)
			break;
		else if (i_frame_size)
		{
			//TODO:encode success
		}
	}
}
示例#3
0
/**
 * Draws a table, or a table cell, and recursively render the contents
 * of the table cells. 
 *
 * @param partp A pointer to the layout part representing the line.
 * @param geometry The current geometry of the display, describing what
 * @param geometry part and where to render the line.
 *
 * @return non-zero value if an error occurred.
 */
int ofbis_draw_table(struct layout_part* partp, 
		     struct layout_rectangle geometry,
		     struct layout_rectangle scroll)
{

  struct ofbis_information *info = 
    (struct ofbis_information *)ofbis_ui->ui_specific;
  FB *fb;
  uint32_t colour1, colour2;
  struct layout_rectangle rect, cut;
  struct layout_part *rowp, *cellp;
  int border = 0;

  fb = info->ofbis_fb;

  ofbis_cut_rectangle(partp->geometry, geometry, scroll, &rect);

  cut = rect;

  rect.x_position += partp->geometry.x_position - scroll.x_position +
    + info->x_position;
  rect.y_position += partp->geometry.y_position - scroll.y_position +
    + info->y_position;

  /* If the table has a background colour worth mentioning, we fill the area
   * with that colour here. Also select colour for the border.
   */
  if(partp->type == LAYOUT_PART_TABLE) {
    colour1 = convert_rgb(0xffffff);
    colour2 = convert_rgb(0x000000);
    border = partp->data.table.border;
  } else {
    colour1 = convert_rgb(0x000000);
    colour2 = convert_rgb(0xffffff);
    if(!(partp->data.table_cell.background_colour & 0x80000000))
      ofbis_fill_area(rect, partp->data.table_cell.background_colour);

    if(partp->parent && partp->parent->parent &&
       partp->parent->parent->type == LAYOUT_PART_TABLE)
      border = partp->parent->parent->data.table.border;
  }

  if(border > 0) {
    
    if(cut.y_position == 0) {
      FBhline(fb, 
	      rect.x_position,
	      rect.x_position + rect.width - 2,
	      rect.y_position,
	      colour1);
    }

    if(cut.x_position == 0) {    
      FBline(fb, 
	     rect.x_position,
	     rect.y_position,
	     rect.x_position,
	     rect.y_position + rect.height - 1,
	     colour1);
    }

    if(partp->geometry.height - cut.height == cut.y_position) {
      FBhline(fb, 
	      rect.x_position + 1,
	      rect.x_position + rect.width - 2,
	      rect.y_position + rect.height - 1,
	      colour2);
    }

    if(partp->geometry.width - cut.width == cut.x_position) {
      FBline(fb, 
	     rect.x_position + rect.width - 2,
	     rect.y_position + 1,
	     rect.x_position + rect.width - 2,
	     rect.y_position + rect.height - 1,
	     colour2);
    }
  }

  if(partp->type == LAYOUT_PART_TABLE) {
    rowp = partp->child;
    while(rowp) {
      if(rowp->type != LAYOUT_PART_TABLE_ROW) {
	rowp = rowp->next;
	continue;
      }

      cellp = rowp->child;
      while(cellp) {
	if(cellp->type != LAYOUT_PART_TABLE_CELL) {
	  cellp = cellp->next;
	  continue;
	}

	if(!(cellp->geometry.x_position - scroll.x_position > 
	     geometry.x_position + geometry.width ||
	     cellp->geometry.y_position - scroll.y_position > 
	     geometry.y_position + geometry.height ||
	     cellp->geometry.x_position - scroll.x_position + 
	     cellp->geometry.width < geometry.x_position ||
	     cellp->geometry.y_position - scroll.y_position + 
	     cellp->geometry.height < geometry.y_position)) {
	  struct layout_rectangle cell_geometry;

	  /* Draw the frame around the cell. */
	  ofbis_draw_table(cellp, geometry, scroll);

	  cell_geometry.x_position = cellp->geometry.x_position - 
	    scroll.x_position;
	  cell_geometry.y_position = cellp->geometry.y_position - 
	    scroll.y_position;
	  cell_geometry.width = 
	    min(cellp->geometry.width, 
		geometry.width + geometry.x_position - 
		(cellp->geometry.x_position - scroll.x_position));
	  cell_geometry.height = 
	    min(cellp->geometry.height, 
		geometry.height + geometry.y_position - 
		(cellp->geometry.y_position - scroll.y_position));
	  if(cell_geometry.x_position < 0) {
	    cell_geometry.width -= -cell_geometry.x_position;
	    cell_geometry.x_position = 0;
	  }
	  if(cell_geometry.y_position < 0) {
	    cell_geometry.height -= -cell_geometry.y_position;
	    cell_geometry.y_position = 0;
	  }

	  /* Render the parts placed inside the table cell. */
	  if(cellp->child != NULL) {
	    ofbis_render(cellp, cell_geometry, scroll);
	  }
	}

	cellp = cellp->next;
      }

      rowp = rowp->next;
    }
  }
  return 0;
}