📄 r2d_vertical_lcd_i.c
字号:
new_value=dop((pixel_cache >> y) & R2D_PIXEL_MASK,pixel_value) & R2D_PIXEL_MASK;
pixel_cache &= ~(R2D_PIXEL_MASK << y) ;
// Write new value
pixel_cache |= (new_value << y);
*p=pixel_cache;
}
break;
case R2D_LCD_KIND: // LCD format with any size
{
INT16 height,width;
height=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->height;
width=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->width;
#if (R2D_REFRESH == R2D_VERTICAL)
// Get position of the memory word containing the pixel
p+=((x*R2D_ALIGNED_MWLENGTH(height)+(y>>R2D_PIXELS_PER_MEMORY_WORD)));
#else
p+=((x*R2D_ALIGNED_MWLENGTH(width)+(y>>R2D_PIXELS_PER_MEMORY_WORD)));
#endif
if ((y<0) || (x<0) || ((p<((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words)
|| (p>((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_frame_buffer_end)))
{
#if (R2D_DEBUG == R2D_ON)
IND_rvf_send_trace("R2D : Framebuffer overflow",26, NULL_PARAM,
RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
#endif
goto r2d_fail_pixel;
}
// Get the pixel position into the memory word
y=y & R2D_WORD_POSITION_MASK;
y=y << R2D_PIXEL_POS_TO_BIT_POS;
pixel_cache=*p;
new_value=dop((pixel_cache >> y) & R2D_PIXEL_MASK,pixel_value) & R2D_PIXEL_MASK;
pixel_cache &= ~(R2D_PIXEL_MASK << y) ;
// Write new value
pixel_cache |= (new_value << y);
*p=pixel_cache;
}
break;
case R2D_FULL_KIND:
{
INT16 height,width;
height=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->height;
width=((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->width;
//printf("%08X\n",p);
// Get position of the memory word containing the pixel
#if (R2D_REFRESH == R2D_VERTICAL)
p+=(x*height+y);
#else
p+=(x*width+y);
#endif
//printf(" --> %08X for x=%d and y=%d\n",p,x,y);
if ((y<0) || (x<0) || ((p<((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_memory_words)
|| (p>((T_R2D_FRAMEBUFFER*)(gc->p_frame_buffer))->p_frame_buffer_end)))
{
#if (R2D_DEBUG == R2D_ON)
IND_rvf_send_trace("R2D : Framebuffer overflow",26, NULL_PARAM,
RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
#endif
goto r2d_fail_pixel;
}
// Get the pixel position into the memory word
y=0;
pixel_cache=*p;
new_value=dop(pixel_cache,pixel_value);
pixel_cache = new_value;
*p=pixel_cache;
}
break;
}
r2d_fail_pixel:tmp=0; // Just because one needs code after a label
}
#if (R2D_ASM == R2D_OFF)
// For blitting, two scanning direction are required because of possible
// overlaps between src and dst
// Shift new pixel from srcstream to dststream using variable srccache
// as a pixel cache.dstcounter allows to keep track of number
// of pixels written
// (scanning direction is down)
#define r2d_shift_pixel_down(dststream,srccache,srccounter,srcstream) {dststream =R2D_PIXEL_DOWN_OUT(dststream); \
dststream|=((srccache & R2D_PIXEL_MASK) \
<< ((1<<R2D_MEMORY_WORD) - R2D_PIXEL_DEPTH)) ; \
srccache=R2D_PIXEL_DOWN_OUT(srccache); \
srccounter--; \
if (srccounter==0) \
{ \
srccounter=(1<<R2D_PIXELS_PER_MEMORY_WORD); \
srccache=*++srcstream; \
} }
// Scanning direction is up
#define r2d_shift_pixel_up(dststream,srccache,srccounter,srcstream) {dststream =R2D_PIXEL_UP_OUT(dststream); \
dststream |=(srccache >> ((1<<R2D_MEMORY_WORD) - R2D_PIXEL_DEPTH)) & R2D_PIXEL_MASK; \
srccache=R2D_PIXEL_UP_OUT(srccache); \
srccounter--; \
if (srccounter==0) \
{ \
srccounter=(1<<R2D_PIXELS_PER_MEMORY_WORD); \
srccache=*--srcstream; \
} }
#endif
// Check overlap of src and dst rectangle and return the
// horizontal and vertical scanning direction required to do the
// blit rect
// A positive value means standard direction (increasing x and increasing y)
// When that routine is called, both rectangles are expressed in framebuffer
// coordinates and come from the same framebuffer.
// The routine is never called if dstGc and srcGc are not using the same framebuffer.
//
// INT32 used because of stack bug ?
void r2d_check_rectangle_overlap(INT16 src_x,INT16 src_y,INT16 dst_x,INT16 dst_y,
INT32 width,INT32 height,
INT32 *h_direction,INT32 *v_direction)
{
INT16 h,v;
INT16 rx,ry;
rx=dst_x-src_x;
ry=dst_y-src_y;
h=1;
v=1;
if ((rx>-width) && (rx < width) && (ry>-height) && (ry<height))
{
if (rx>0)
h=-1;
else
h=1;
if (ry>0)
v=-1;
else
v=1;
}
*h_direction=h;
*v_direction=v;
}
#if (R2D_ASM == R2D_OFF)
static UINT32 r2d_get_pixel_value(T_R2D_GC_PTR gc,R2D_BOOLEAN foreground,INT16 x,INT16 y)
{
UINT32 pixel_value;
if (foreground)
{
#if (R2D_DITHERING == R2D_OFF)
pixel_value=((T_R2D_GC*)gc)->foreground_pixel_value;
#else
pixel_value=r2d_get_dithering_matrix_entry(((T_R2D_GC*)gc)->p_foreground_dithered_cache,x,y);
#endif
}
else
{
#if (R2D_DITHERING == R2D_OFF)
pixel_value=((T_R2D_GC*)gc)->background_pixel_value;
#else
pixel_value=r2d_get_dithering_matrix_entry(((T_R2D_GC*)gc)->p_background_dithered_cache,x,y);
#endif
}
return(pixel_value);
}
// When foreground color is used, the source pixel
// is converted to the background or foreground color
// then dithered
static UINT32 r2d_convert_from_lcd_to_lcd(R2D_BOOLEAN use_foreground,UINT32 src,T_R2D_GC_PTR src_gc,T_R2D_GC_PTR dst_gc,INT16 x,INT16 y)
{
if (use_foreground)
{
UINT32 pixel_value;
if (IND_r2d_lcd_foreground_pixel(src,src_gc))
pixel_value=r2d_get_pixel_value(dst_gc,TRUE,x,y);
else
pixel_value=r2d_get_pixel_value(dst_gc,FALSE,x,y);
return(pixel_value);
}
else return(src);
}
static UINT32 r2d_convert_from_color_to_color(R2D_BOOLEAN use_foreground,UINT32 src,T_R2D_GC_PTR src_gc,T_R2D_GC_PTR dst_gc,INT16 x,INT16 y)
{
if (use_foreground)
{
UINT32 pixel_value;
if (IND_r2d_color_framebuffer_foreground_pixel(src,src_gc))
pixel_value=r2d_get_pixel_value(dst_gc,TRUE,x,y);
else
pixel_value=r2d_get_pixel_value(dst_gc,FALSE,x,y);
return(pixel_value);
}
else return(src);
}
static UINT32 r2d_convert_from_color_to_lcd(R2D_BOOLEAN use_foreground,UINT32 src,T_R2D_GC_PTR src_gc,T_R2D_GC_PTR dst_gc,INT16 x,INT16 y)
{
if (use_foreground)
{
UINT32 pixel_value;
if (IND_r2d_color_framebuffer_foreground_pixel(src,src_gc))
pixel_value=r2d_get_pixel_value(dst_gc,TRUE,x,y);
else
pixel_value=r2d_get_pixel_value(dst_gc,FALSE,x,y);
return(pixel_value);
}
else return(IND_r2d_color_to_lcd(src,x,y));
}
static UINT32 r2d_convert_from_lcd_to_color(R2D_BOOLEAN use_foreground,UINT32 src,T_R2D_GC_PTR src_gc,T_R2D_GC_PTR dst_gc,INT16 x,INT16 y)
{
if (use_foreground)
{
UINT32 pixel_value;
if (IND_r2d_lcd_foreground_pixel(src,src_gc))
pixel_value=r2d_get_pixel_value(dst_gc,TRUE,x,y);
else
pixel_value=r2d_get_pixel_value(dst_gc,FALSE,x,y);
return(pixel_value);
}
else
{
return(IND_r2d_lcd_to_color(src));
}
}
// FOR DEBUG
//#define dop(a,b) b
#define r2d_shift_pixel_down_and_write(dst,src) {\
dst##value =R2D_PIXEL_DOWN_OUT(dst##value); \
dst##value|=dop((dst##_current & R2D_PIXEL_MASK), \
r2d_convert_from_lcd_to_lcd(use_foreground_color,\
src##_current & R2D_PIXEL_MASK,src_gc,dst_gc,x,y)) \
<< ((1<<R2D_MEMORY_WORD) - R2D_PIXEL_DEPTH) ; \
src##_current=R2D_PIXEL_DOWN_OUT(src##_current); \
dst##_current=R2D_PIXEL_DOWN_OUT(dst##_current); \
dst##counter--; \
src##counter--; \
if (src##counter==0) \
{ \
src##counter=(1<<R2D_PIXELS_PER_MEMORY_WORD); \
src##_current=*++p_##src##_current; \
} \
if (dst##counter==0) \
{ \
dst##counter=(1<<R2D_PIXELS_PER_MEMORY_WORD); \
} \
}
#define r2d_shift_pixel_up_and_write(dst,src) {\
dst##value =R2D_PIXEL_UP_OUT(dst##value); \
dst##value |=dop( \
(dst##_current >> ((1<<R2D_MEMORY_WORD) - R2D_PIXEL_DEPTH)) & R2D_PIXEL_MASK, \
r2d_convert_from_lcd_to_lcd(use_foreground_color,\
(src##_current >> ((1<<R2D_MEMORY_WORD) - R2D_PIXEL_DEPTH)) & R2D_PIXEL_MASK, \
src_gc,dst_gc,x,y)); \
src##_current=R2D_PIXEL_UP_OUT(src##_current); \
dst##_current=R2D_PIXEL_UP_OUT(dst##_current); \
dst##counter--; \
src##counter--; \
if (src##counter==0) \
{ \
src##counter=(1<<R2D_PIXELS_PER_MEMORY_WORD); \
src##_current=*--p_##src##_current; \
} \
if (dst##counter==0) \
{ \
dst##counter=(1<<R2D_PIXELS_PER_MEMORY_WORD); \
} \
}
extern UINT32 r2d_lcd_or_operator(UINT32 old,UINT32 value);
// Requires shapes in graphic context coordinates
void r2d_blit_lcd_to_lcd(T_R2D_GC_PTR src_gc,T_R2D_GC_PTR dst_gc,
T_R2D_SHAPE_PTR src_rectangle,
T_R2D_SHAPE_PTR dst_rectangle,
R2D_BOOLEAN use_foreground_color)
{
UINT32 *p_src,*p_dst,*p_src_current,*p_dst_current,*p_src_start,*p_dst_start;
INT16 rect_width,rect_height,src_x,src_y,dst_x,dst_y;
INT16 src_offset,dst_offset,src_height,dst_height;
INT16 xnb,ynb,src_nb_rows,dst_nb_rows;
INT16 src_dy,dst_dy,end_dst_dy,end_src_dy; // distance from word boundary
// INT16 shift; // relative position (modulo a memory word) between both rectangles
// in bits
INT16 current_src_dy,current_dst_dy;
INT16 temp,dstcounter,srccounter;
register UINT32 dstvalue,dst_current;
register UINT32 src_current;//srcvalue;
INT32 h_direction,v_direction;
INT16 x,y;
T_R2D_DRAWING_MODE mode;
T_R2D_DRAWING_OP dop;
BOOLEAN compensate=TRUE;
dop=((T_R2D_GC*)dst_gc)->drawing_op;
{
p_src=((T_R2D_FRAMEBUFFER*)(((T_R2D_GC*)src_gc)->p_frame_buffer))->p_memory_words;
p_dst=((T_R2D_FRAMEBUFFER*)(((T_R2D_GC*)dst_gc)->p_frame_buffer))->p_memory_words;
rect_width=r2d_get_xmax(src_rectangle)-r2d_get_xmin(src_rectangle);
rect_height=r2d_get_ymax(src_rectangle)-r2d_get_ymin(src_rectangle);
if ((rect_width<=0) || (rect_height<=0))
goto end_blit;
mode=IND_r2d_get_drawing_mode(dst_gc);
src_x=r2d_get_xmin(src_rectangle);
src_y=r2d_get_ymin(src_rectangle);
dst_x=r2d_get_xmin(dst_rectangle);
dst_y=r2d_get_ymin(dst_rectangle);
src_dy=(src_y & R2D_WORD_POSITION_MASK);
dst_dy=(dst_y & R2D_WORD_POSITION_MASK);
// Clipping convention such end_dst_dy is the first y position which must not
// be copied at the end of a column
//printf("dest y max=%d\n",r2d_get_ymax(dst_rectangle));
end_dst_dy=((r2d_get_ymax(dst_rectangle)-1) & R2D_WORD_POSITION_MASK) ;
end_src_dy=((r2d_get_ymax(src_rectangle)-1) & R2D_WORD_POSITION_MASK) ;
//printf("dst_dy, end_dst_dy before reverse=%d,%d\n",dst_dy,end_dst_dy);
// Number of rows is word containing last point - word containing first point
// + 1
// We remove - 1 because last PIXEL is at 1 from the frontier line
dst_nb_rows=R2D_ALIGNED_MWLENGTH(r2d_get_ymax(dst_rectangle)-1)-R2D_ALIGNED_MWLENGTH(dst_y)+1;
src_nb_rows=R2D_ALIGNED_MWLENGTH(r2d_get_ymax(src_rectangle)-1)-R2D_ALIGNED_MWLENGTH(src_y)+1;
//printf("src_nb_rows %d\n",src_nb_rows);
//printf("dst_nb_rows %d\n",dst_nb_rows);
h_direction=1;
v_direction=1;
if (((T_R2D_FRAMEBUFFER*)(((T_R2D_GC*)src_gc)->p_frame_buffer))==
((T_R2D_FRAMEBUFFER*)(((T_R2D_GC*)dst_gc)->p_frame_buffer)))
r2d_check_rectangle_overlap(src_x,src_y,dst_x,dst_y,
rect_width,rect_height,&h_direction,&v_direction);
//printf("h,v=%d,%d\n",h_direction,v_direction);
#if (R2D_REFRESH == R2D_VERTICAL)
src_height=((T_R2D_FRAMEBUFFER*)(((T_R2D_GC*)src_gc)->p_frame_buffer))->height;
dst_height=((T_R2D_FRAMEBUFFER*)(((T_R2D_GC*)dst_gc)->p_frame_buffer))->height;
#else
src_height=((T_R2D_FRAMEBUFFER*)(((T_R2D_GC*)src_gc)->p_frame_buffer))->width;
dst_height=((T_R2D_FRAMEBUFFER*)(((T_R2D_GC*)dst_gc)->p_frame_buffer))->width;
#endif
src_offset=R2D_ALIGNED_MWLENGTH(src_height);
dst_offset=R2D_ALIGNED_MWLENGTH(dst_height);
//printf("%08X,dst offset=%08X\n",p_dst,dst_offset);
p_src_start=p_src
+((src_x*src_offset+(src_y>>R2D_PIXELS_PER_MEMORY_WORD)));
p_dst_start=p_dst
+((dst_x*dst_offset+(dst_y>>R2D_PIXELS_PER_MEMORY_WORD)));
xnb=rect_width;
//printf("src start %08X contains %08X\n",p_src_start,*p_src_start);
//printf("dst start %08X contains %08X\n",p_dst_start,*p_dst_start);
//printf("rect_width %d\n",rect_width);
if (h_direction==-1)
{
x=r2d_get_xmax(dst_rectangle)-1;
p_src_start+=(rect_width-1)*src_offset;
p_dst_start+=(rect_width-1)*dst_offset;
}
else
x=r2d_get_xmin(dst_rectangle);
//printf("src start %08X contains %08X\n",p_src_start,*p_src_start);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -