📄 r2d.c
字号:
y=0;
for(i=0;i<length;i++) // Horizontal
for(j=0;j<length;j++) // Vertical
{
r2d_convert_background_color_color(gc,ft->pattern[i*length+j]);
#if (R2D_REFRESH == R2D_VERTICAL)
#ifdef R2D_MIRRORED_X
ni=(length-1)-i;
#else
ni=i;
#endif
#ifdef R2D_MIRRORED_Y
nj=(length-1)-j;
#else
nj=j;
#endif
p[ni*length+nj]=((T_R2D_GC*)gc)->background_pixel_value;
#else
#ifdef R2D_MIRRORED_X
nj=(length-1)-j;
#else
nj=j;
#endif
#ifdef R2D_MIRRORED_Y
ni=(length-1)-i;
#else
ni=i;
#endif
p[nj*length+ni]=((T_R2D_GC*)gc)->background_pixel_value;
#endif
}
}
else
{
for(i=0;i<length;i++)
for(j=0;j<length;j++)
{
r2d_convert_background_color(gc,ft->pattern[i*length+j]);
#if (R2D_REFRESH == R2D_VERTICAL)
#ifdef R2D_MIRRORED_X
ni=(length-1)-i;
#else
ni=i;
#endif
#ifdef R2D_MIRRORED_Y
nj=(length-1)-j;
#else
nj=j;
#endif
pos=ni*length+nj;
#else
#ifdef R2D_MIRRORED_X
nj=(length-1)-j;
#else
nj=j;
#endif
#ifdef R2D_MIRRORED_Y
ni=(length-1)-i;
#else
ni=i;
#endif
pos=nj*length+ni;
#endif
#if (R2D_DITHERING == R2D_OFF)
p[pos]=((T_R2D_GC*)gc)->background_pixel_value;
#else
p[pos]=r2d_get_dithering_matrix_entry(((T_R2D_GC*)gc)->p_background_dithered_cache,x,y);
#endif
#if (R2D_REFRESH == R2D_VERTICAL)
y++;
if (y==length)
{
y=0;
x++;
}
#else
x++;
if (x==length)
{
x=0;
y++;
}
#endif
}
}
// Force change
r2d_set_background_color(gc,b^1);
r2d_set_background_color(gc,b);
return((T_R2D_ANCHORED_TEXTURE_PTR)at);
erroranchored: return(NULL);
}
void r2d_release_anchored_texture(T_R2D_ANCHORED_TEXTURE_PTR texture)
{
if (texture)
{
// Remove the array of words if needed
// (refcount must be 1 else the array should not be deleted)
if (R2D_REFCOUNT(texture)==1)
{
if (((T_R2D_ANCHORED_TEXTURE*)texture)->pattern)
R2D_FREE(((T_R2D_ANCHORED_TEXTURE*)texture)->pattern);
}
}
// Autorelease
r2d_release(texture);
}
////////////////////////////////////////
//
// Framebuffer
//
T_R2D_FRAMEBUFFER_PTR r2d_new_framebuffer(T_RVF_MB_ID bank,T_R2D_FRAMEBUFFER_KIND the_kind,UINT16 width, UINT16 height)
{
UINT32 length;
T_R2D_FRAMEBUFFER *p;
UINT32 *elem;
T_RVF_RET err;
R2D_MALLOC(bank,T_R2D_FRAMEBUFFER,sizeof(T_R2D_FRAMEBUFFER),p);
if (p)
{
switch(the_kind)
{
case R2D_LCD_KIND:
#if (R2D_REFRESH==R2D_VERTICAL)
// Column is contiguous in memory
length=width*R2D_ALIGNED_MWLENGTH(height);
R2D_MALLOC(bank,UINT32,((length+1)<<R2D_LONGSIZE_FACTOR),p->p_memory_words);
if (!(p->p_memory_words))
{
R2D_FREE(p);
p=NULL;
#if (R2D_DEBUG == R2D_ON)
if (p==NULL)
{
rvf_send_trace("R2D : Framebuffer null",22, NULL_PARAM,
RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
}
#endif
return(p);
}
p->refcount=1;
p->kind=R2D_LCD_KIND;
p->p_frame_buffer_end=p->p_memory_words+length;
p->width=width;
p->height=height;
R2D_MALLOC(bank,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),p->mutex);
if (p->mutex!=NULL)
{
err=rvf_initialize_mutex(p->mutex);
if (err!=RVF_OK)
{
R2D_FREE(p->mutex);
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
}
else
{
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
#else
// Line is contiguous in memory
length=height*R2D_ALIGNED_MWLENGTH(width);
R2D_MALLOC(bank,UINT32,((length+1)<<R2D_LONGSIZE_FACTOR),p->p_memory_words);
if (!(p->p_memory_words))
{
R2D_FREE(p);
p=NULL;
#if (R2D_DEBUG == R2D_ON)
if (p==NULL)
{
rvf_send_trace("R2D : Framebuffer null",22, NULL_PARAM,
RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
}
#endif
return(p);
}
p->refcount=1;
p->kind=R2D_LCD_KIND;
p->p_frame_buffer_end=p->p_memory_words+length;
p->width=width;
p->height=height;
R2D_MALLOC(bank,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),p->mutex);
if (p->mutex!=NULL)
{
err=rvf_initialize_mutex(p->mutex);
if (err!=RVF_OK)
{
R2D_FREE(p->mutex);
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
}
else
{
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
#endif
break;
default:
length=width*height;
R2D_MALLOC(bank,UINT32,((length+1)<<R2D_LONGSIZE_FACTOR),p->p_memory_words);
if (!(p->p_memory_words))
{
R2D_FREE(p);
p=NULL;
#if (R2D_DEBUG == R2D_ON)
if (p==NULL)
{
rvf_send_trace("R2D : Framebuffer null",22, NULL_PARAM,
RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
}
#endif
return(p);
}
p->refcount=1;
p->kind=R2D_FULL_KIND;
p->p_frame_buffer_end=p->p_memory_words+length;
p->width=width;
p->height=height;
R2D_MALLOC(bank,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),p->mutex);
if (p->mutex!=NULL)
{
err=rvf_initialize_mutex(p->mutex);
if (err!=RVF_OK)
{
R2D_FREE(p->mutex);
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
}
else
{
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
break;
}
} else p=NULL;
#if (R2D_DEBUG == R2D_ON)
if (p==NULL)
{
rvf_send_trace("R2D : Framebuffer null",22, NULL_PARAM,
RV_TRACE_LEVEL_ERROR, R2D_USE_ID );
}
#endif
return(p);
}
static T_R2D_FONT_CACHE_FRAMEBUFFER* r2d_new_font_framebuffer(T_RVF_MB_ID bank,T_R2D_FRAMEBUFFER_KIND the_kind,UINT16 width, UINT16 height)
{
UINT32 length;
T_R2D_FONT_CACHE_FRAMEBUFFER *p;
UINT32 *elem;
T_RVF_RET err;
R2D_MALLOC(bank,T_R2D_FONT_CACHE_FRAMEBUFFER,sizeof(T_R2D_FONT_CACHE_FRAMEBUFFER),p);
if (p)
{
switch(the_kind)
{
case R2D_LCD_KIND:
#if (R2D_REFRESH==R2D_VERTICAL)
// Column is contiguous in memory
length=width*R2D_ALIGNED_MWLENGTH(height);
R2D_MALLOC(bank,UINT32,((length+1)<<R2D_LONGSIZE_FACTOR),p->p_memory_words);
if (!(p->p_memory_words))
{
R2D_FREE(p);
p=NULL;
return(p);
}
p->refcount=1;
p->kind=R2D_LCD_KIND;
p->p_frame_buffer_end=p->p_memory_words+length;
p->width=width;
p->height=height;
R2D_MALLOC(bank,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),p->mutex);
if (p->mutex!=NULL)
{
err=rvf_initialize_mutex(p->mutex);
if (err!=RVF_OK)
{
R2D_FREE(p->mutex);
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
}
else
{
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
#else
// Line is contiguous in memory
length=height*R2D_ALIGNED_MWLENGTH(width);
R2D_MALLOC(bank,UINT32,((length+1)<<R2D_LONGSIZE_FACTOR),p->p_memory_words);
if (!(p->p_memory_words))
{
R2D_FREE(p);
p=NULL;
return(p);
}
p->refcount=1;
p->kind=R2D_LCD_KIND;
p->p_frame_buffer_end=p->p_memory_words+length;
p->width=width;
p->height=height;
R2D_MALLOC(bank,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),p->mutex);
if (p->mutex!=NULL)
{
err=rvf_initialize_mutex(p->mutex);
if (err!=RVF_OK)
{
R2D_FREE(p->mutex);
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
}
else
{
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
#endif
break;
default:
length=width*height;
R2D_MALLOC(bank,UINT32,((length+1)<<R2D_LONGSIZE_FACTOR),p->p_memory_words);
if (!(p->p_memory_words))
{
R2D_FREE(p);
p=NULL;
return(p);
}
p->refcount=1;
p->kind=R2D_FULL_KIND;
p->p_frame_buffer_end=p->p_memory_words+length;
p->width=width;
p->height=height;
R2D_MALLOC(bank,T_RVF_MUTEX,sizeof(T_RVF_MUTEX),p->mutex);
if (p->mutex!=NULL)
{
err=rvf_initialize_mutex(p->mutex);
if (err!=RVF_OK)
{
R2D_FREE(p->mutex);
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
}
else
{
R2D_FREE(p->p_memory_words);
R2D_FREE(p);
p=NULL;
return(p);
}
break;
}
} else p=NULL;
return(p);
}
// Release a framebuffer
void r2d_release_framebuffer(T_R2D_FRAMEBUFFER_PTR p)
{
if (p)
{
// Remove the array of words if needed
// (refcount must be 1 else the array should not be deleted)
if (R2D_REFCOUNT(p)==1)
{
R2D_FREE(((T_R2D_FRAMEBUFFER*)p)->p_memory_words);
rvf_delete_mutex(((T_R2D_FRAMEBUFFER*)p)->mutex);
R2D_FREE(((T_R2D_FRAMEBUFFER*)p)->mutex);
}
}
// Autorelease
r2d_release(p);
}
////////////////////////////////////////
//
// Graphic context
//
static T_R2D_GC_PTR r2d_new_font_buffer_context(T_RVF_MB_ID bank,
T_R2D_FRAMEBUFFER_KIND kind,
UINT16 max_width,
UINT16 ascent)
{
T_R2D_FRAMEBUFFER_PTR cache_buffer;
T_R2D_GC_PTR result;
//printf("width=%d,height=%d\n",the_width,((T_R2D_FRAMEBUFFER*)font_frame_buffer)->height);
cache_buffer=r2d_new_font_framebuffer(bank,kind,
max_width,ascent);
if (cache_buffer!=NULL)
{
result=r2d_new_context(bank,cache_buffer);
r2d_release_framebuffer(cache_buffer);
return(result);
} else return(NULL);
}
T_R2D_GC_PTR r2d_new_context(T_RVF_MB_ID bank,T_R2D_FRAMEBUFFER_PTR the_frame_buffer)
{
T_R2D_GC *gc;
// Allocate a new gc structure
R2D_MALLOC(bank,T_R2D_GC,sizeof(T_R2D_GC),gc);
if (gc)
{
// gc is pointing to the LCD framebuffer
gc->p_frame_buffer=(T_R2D_FRAMEBUFFER*)the_frame_buffer;
r2d_retain(the_frame_buffer);
// Default initialization for a gc
gc->background_texture=NULL;
gc->foreground_color=r2d_get_standard_argb_color(R2D_BLACK);
gc->background_color=r2d_get_standard_argb_color(R2D_WHITE);
#if (R2D_REFRESH == R2D_VERTICAL)
gc->p_s_clipping_shape=r2d_new_rectangle(bank,0,0,((T_R2D_FRAMEBUFFER*)the_frame_buffer)->width,
((T_R2D_FRAMEBUFFER*)the_frame_buffer)->height);
#else
gc->p_s_clipping_shape=r2d_new_rectangle(bank,0,0,((T_R2D_FRAMEBUFFER*)the_frame_buffer)->height,((T_R2D_FRAMEBUFFER*)the_frame_buffer)->width);
#endif
if (gc->p_s_clipping_shape==NULL)
{
r2d_release_framebuffer(the_frame_buffer);
R2D_FREE(gc);
gc=NULL;
return(NULL);
}
gc->p_clipping_shape=r2d_new_rectangle(bank,0,0,((T_R2D_FRAMEBUFFER*)the_frame_buffer)->width,
((T_R2D_FRAMEBUFFER*)the_frame_buffer)->height);
gc->drawing_mode=R2D_COPY_MODE;
gc->drawing_op=r2d_get_drawing_op(gc,R2D_COPY_MODE);
gc->org_x=gc->org_y=0;
gc->s_org_x=gc->s_org_y=0;
gc->pen_size=1;
gc->dash=0;
gc->text_face=R2D_SYSTEM;
gc->text_style=R2D_PLAIN;
gc->internal_text_style=R2D_PLAIN;
gc->text_size=R2D_SMALL;
gc->font_frame_buffer=r2d_g_default_font_framebuffer;
gc->font_metrics=r2d_g_default_font_metrics;
gc->font_table=r2d_g_default_font_table;
if (gc->p_clipping_shape)
{
r2d_retain(r2d_g_default_font_framebuffer);
// refcount set to 1 for creation
gc->refcount=1;
R2D_MALLOC(bank,UINT32,sizeof(UINT32)*4,gc->p_foreground_dithered_cache);
if (gc->p_foreground_dithered_cache)
{
R2D_MALLOC(bank,UINT32,sizeof(UINT32)*4,gc->p_background_dithered_cache);
if (gc->p_background_dithered_cache)
{
if (((T_R2D_FRAMEBUFFER*)the_frame_buffer)->kind==R2D_FULL_KIND)
{
r2d_convert_foreground_color_color(gc,gc->foreground_color);
r2d_convert_background_color_color(gc,gc->background_color);
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -