summaryrefslogtreecommitdiff
path: root/atari/plot/plot.c
diff options
context:
space:
mode:
Diffstat (limited to 'atari/plot/plot.c')
-rwxr-xr-xatari/plot/plot.c238
1 files changed, 143 insertions, 95 deletions
diff --git a/atari/plot/plot.c b/atari/plot/plot.c
index ca3f2b726..2a8fd6868 100755
--- a/atari/plot/plot.c
+++ b/atari/plot/plot.c
@@ -22,7 +22,8 @@
#include <limits.h>
#include <math.h>
#include <stdbool.h>
-#include <windom.h>
+
+#include <mt_gem.h>
#include "image/bitmap.h"
#include "utils/log.h"
@@ -36,6 +37,8 @@
#include "desktop/options.h"
#include "atari/plot/plot.h"
+void vq_scrninfo(VdiHdl handle, short *work_out);
+
struct s_view {
short x; /* drawing (screen) offset x */
short y; /* drawing (screen) offset y */
@@ -154,7 +157,7 @@ static HermesFormat vfmt;
/* netsurf source bitmap format */
static HermesFormat nsfmt;
-static struct s_vdi_sysinfo vdi_sysinfo;
+struct s_vdi_sysinfo vdi_sysinfo;
/* bit depth of framebuffers: */
static int atari_plot_bpp_virt;
static struct s_view view;
@@ -166,7 +169,7 @@ static HermesHandle hermes_res_h;
static short prev_vdi_clip[4];
static struct bitmap snapshot;
-int atari_plot_vdi_handle;
+VdiHdl atari_plot_vdi_handle = -1;
unsigned long atari_plot_flags;
unsigned long atari_font_flags;
@@ -190,9 +193,10 @@ inline static void vsl_rgbcolor(short vdih, colour cin)
#ifdef WITH_8BPP_SUPPORT
if( vdi_sysinfo.scr_bpp > 8 ) {
#endif
- unsigned short c[4];
- rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c);
- vs_color(vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c[0]);
+ //unsigned short c[4];
+ RGB1000 c;
+ rgb_to_vdi1000( (unsigned char*)&cin, &c);
+ vs_color(vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c);
vsl_color(vdih, OFFSET_CUSTOM_COLOR);
#ifdef WITH_8BPP_SUPPORT
} else {
@@ -216,9 +220,9 @@ inline static void vsf_rgbcolor(short vdih, colour cin)
#ifdef WITH_8BPP_SUPPORT
if( vdi_sysinfo.scr_bpp > 8 ) {
#endif
- unsigned short c[4];
- rgb_to_vdi1000( (unsigned char*)&cin, (unsigned short*)&c );
- vs_color( vdih, OFFSET_CUSTOM_COLOR, &c[0] );
+ RGB1000 c;
+ rgb_to_vdi1000( (unsigned char*)&cin, &c);
+ vs_color( vdih, OFFSET_CUSTOM_COLOR, (unsigned short*)&c);
vsf_color( vdih, OFFSET_CUSTOM_COLOR );
#ifdef WITH_8BPP_SUPPORT
} else {
@@ -255,9 +259,9 @@ inline static void plot_get_visible_grect(GRECT * out)
/* all values of the region are set to zero. */
inline static void update_visible_rect(void)
{
- GRECT screen;
- GRECT common;
- GRECT frame;
+ GRECT screen; // dimensions of the screen
+ GRECT frame; // dimensions of the drawing area
+ GRECT common; // dimensions of intersection of both
screen.g_x = 0;
screen.g_y = 0;
@@ -269,14 +273,14 @@ inline static void update_visible_rect(void)
common.g_w = frame.g_w = view.w;
common.g_h = frame.g_h = view.h;
- if( rc_intersect( &screen, &common ) ) {
+ if (rc_intersect(&screen, &common)) {
view.vis_w = common.g_w;
view.vis_h = common.g_h;
- if( view.x < screen.g_x )
+ if (view.x < screen.g_x)
view.vis_x = frame.g_w - common.g_w;
else
view.vis_x = 0;
- if( view.y <screen.g_y )
+ if (view.y <screen.g_y)
view.vis_y = frame.g_h - common.g_h;
else
view.vis_y = 0;
@@ -321,32 +325,6 @@ inline static bool fbrect_to_screen(GRECT box, GRECT * ret)
return ( true );
}
-/* convert framebuffer clipping to vdi clipping and activates it */
-inline static void plot_vdi_clip(bool set)
-{
- // TODO : check this
- return;
- if( set == true ) {
- struct rect c;
- short vdiflags[58];
- short newclip[4];
- plot_get_clip(&c);
- vq_extnd(atari_plot_vdi_handle, 1, (short*)&vdiflags);
- prev_vdi_clip[0] = vdiflags[45];
- prev_vdi_clip[1] = vdiflags[46];
- prev_vdi_clip[2] = vdiflags[47];
- prev_vdi_clip[3] = vdiflags[48];
- newclip[0] = view.x + MAX(c.x0, 0);
- newclip[1] = view.y + MAX(c.y0, 0);
- newclip[2] = MIN(view.x+view.w, newclip[0] + (c.x1 - c.x0) )-1;
- newclip[3] = MIN(view.y+view.h, newclip[1] + (c.y1 - c.y0) )-1;
- vs_clip(atari_plot_vdi_handle, 1, (short*)&newclip );
- } else {
- vs_clip(atari_plot_vdi_handle, 1, (short *)&prev_vdi_clip );
- }
-}
-
-
/* copy an rectangle from the plot buffer to screen */
/* because this is an on-screen plotter, this is an screen to screen copy. */
bool plot_copy_rect(GRECT src, GRECT dst)
@@ -535,14 +513,14 @@ static struct s_vdi_sysinfo * read_vdi_sysinfo(short vdih, struct s_vdi_sysinfo
/*
Convert an RGB color to an VDI Color
*/
-inline void rgb_to_vdi1000(unsigned char * in, unsigned short * out)
+inline void rgb_to_vdi1000(unsigned char * in, RGB1000 *out)
{
double r = ((double)in[3]/255); /* prozentsatz red */
double g = ((double)in[2]/255); /* prozentsatz green */
double b = ((double)in[1]/255); /* prozentsatz blue */
- out[0] = 1000 * r + 0.5;
- out[1] = 1000 * g + 0.5;
- out[2] = 1000 * b + 0.5;
+ out->red = 1000 * r + 0.5;
+ out->green = 1000 * g + 0.5;
+ out->blue = 1000 * b + 0.5;
return;
}
@@ -766,7 +744,7 @@ static MFDB * snapshot_create_std_mfdb(int x, int y, int w, int h)
/* allocate memory for the snapshot */
{
int scr_stride = MFDB_STRIDE( w );
- int scr_size = ( ((scr_stride >> 3) * h) * app.nplanes );
+ int scr_size = ( ((scr_stride >> 3) * h) * vdi_sysinfo.scr_bpp );
if(size_buf_std == 0 ){
/* init screen mfdb */
buf_std.fd_addr = malloc( scr_size );
@@ -783,7 +761,7 @@ static MFDB * snapshot_create_std_mfdb(int x, int y, int w, int h)
size_buf_std = 0;
return( NULL );
}
- buf_std.fd_nplanes = app.nplanes;
+ buf_std.fd_nplanes = 8;
buf_std.fd_w = scr_stride;
buf_std.fd_h = h;
buf_std.fd_stand = 1;
@@ -793,7 +771,7 @@ static MFDB * snapshot_create_std_mfdb(int x, int y, int w, int h)
MFDB * native = snapshot_create_native_mfdb(x,y,w,h );
assert( native );
- vr_trnfm(atari_plot_vdi_handle, native, &buf_std );
+ vr_trnfm(atari_plot_vdi_handle, native, &buf_std);
return( &buf_std );
}
@@ -1464,14 +1442,14 @@ bool plot_blit_bitmap(struct bitmap * bmp, int x, int y,
return(true);
}
-bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor,
+bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, short fgcolor,
uint32_t flags)
{
MFDB screen, tran;
MFDB * src;
short pxy[8];
- short c[2] = {fgcolor, WHITE};
+ short c[2] = {fgcolor, 0};
GRECT off;
plot_get_clip_grect(&off);
@@ -1480,29 +1458,30 @@ bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor,
}
init_mfdb( 0, loc->g_w, loc->g_h, 0, &screen );
-
- if( insrc->fd_stand ){
- int size = init_mfdb( insrc->fd_nplanes, loc->g_w, loc->g_h,
- MFDB_FLAG_NOALLOC,
- &tran
- );
- if( size_buf_scr == 0 ){
- buf_scr.fd_addr = malloc( size );
- size_buf_scr = size;
- } else {
- if( size > size_buf_scr ) {
- buf_scr.fd_addr = realloc(
- buf_scr.fd_addr, size
- );
- size_buf_scr = size;
- }
- }
- tran.fd_addr = buf_scr.fd_addr;
- vr_trnfm(atari_plot_vdi_handle, insrc, &tran );
- src = &tran;
- } else {
+//
+// if( insrc->fd_stand){
+// printf("st\n");
+// int size = init_mfdb( insrc->fd_nplanes, loc->g_w, loc->g_h,
+// MFDB_FLAG_NOALLOC,
+// &tran
+// );
+// if( size_buf_scr == 0 ){
+// buf_scr.fd_addr = malloc( size );
+// size_buf_scr = size;
+// } else {
+// if( size > size_buf_scr ) {
+// buf_scr.fd_addr = realloc(
+// buf_scr.fd_addr, size
+// );
+// size_buf_scr = size;
+// }
+// }
+// tran.fd_addr = buf_scr.fd_addr;
+// vr_trnfm(atari_plot_vdi_handle, insrc, &tran );
+// src = &tran;
+// } else {
src = insrc;
- }
+// }
pxy[0] = off.g_x - loc->g_x;
pxy[1] = off.g_y - loc->g_y;
@@ -1515,7 +1494,7 @@ bool plot_blit_mfdb(GRECT * loc, MFDB * insrc, unsigned char fgcolor,
if( flags & PLOT_FLAG_TRANS && src->fd_nplanes == 1){
- vrt_cpyfm(atari_plot_vdi_handle, MD_TRANS, (short*)pxy, src, &screen, (short*)&c );
+ vrt_cpyfm(atari_plot_vdi_handle, MD_REPLACE/*MD_TRANS*/, (short*)pxy, src, &screen, (short*)&c);
} else {
/* this method only plots transparent bitmaps, right now... */
}
@@ -1541,7 +1520,15 @@ int plot_init(char * fdrvrname)
if( nsoption_int(atari_font_monochrom) == 1 )
atari_font_flags |= FONTPLOT_FLAG_MONOGLYPH;
- atari_plot_vdi_handle = app.graf.handle;
+ if(atari_plot_vdi_handle == -1) {
+
+ short dummy;
+ short work_in[12] = {Getrez()+2,1,1,1,1,1,1,1,1,1,2,1};
+ short work_out[57];
+ atari_plot_vdi_handle=graf_handle(&dummy, &dummy, &dummy, &dummy);
+ v_opnvwk(work_in, &atari_plot_vdi_handle, work_out);
+ LOG(("Plot VDI handle: %d", atari_plot_vdi_handle));
+ }
read_vdi_sysinfo(atari_plot_vdi_handle, &vdi_sysinfo);
if(verbose_log) {
dump_vdi_info(atari_plot_vdi_handle) ;
@@ -1556,7 +1543,7 @@ int plot_init(char * fdrvrname)
}
memset(&view, 0, sizeof(struct s_view));
- atari_plot_bpp_virt = app.nplanes;
+ atari_plot_bpp_virt = vdi_sysinfo.scr_bpp;
view.x = loc_pos.g_x;
view.y = loc_pos.g_y;
view.w = loc_pos.g_w;
@@ -1583,14 +1570,14 @@ int plot_init(char * fdrvrname)
assert(Hermes_Init());
#ifdef WITH_8BPP_SUPPORT
- bitmap_convert = (app.nplanes > 8) ? bitmap_convert_tc : bitmap_convert_8;
+ bitmap_convert = (vdi_sysinfo.scr_bpp > 8) ? bitmap_convert_tc : bitmap_convert_8;
/* Setup color lookup tables and palette */
i = 0;
unsigned char * col;
unsigned char rgbcol[4];
unsigned char graytone=0;
- if( app.nplanes <= 8 ){
+ if( vdi_sysinfo.scr_bpp <= 8 ){
for( i=0; i<=255; i++ ) {
// get the current color and save it for restore:
@@ -1599,7 +1586,7 @@ int plot_init(char * fdrvrname)
pal[i][0] = sys_pal[i][0];
pal[i][1] = sys_pal[i][1];
pal[i][2] = sys_pal[i][2];
- } else if( app.nplanes >= 8 ) {
+ } else if( vdi_sysinfo.scr_bpp >= 8 ) {
if ( i < OFFSET_CUST_PAL ){
pal[i][0] = vdi_web_pal[i-OFFSET_WEB_PAL][0];
pal[i][1] = vdi_web_pal[i-OFFSET_WEB_PAL][1];
@@ -1700,6 +1687,7 @@ bool plot_unlock(void)
wind_update(END_MCTRL);
wind_update(END_UPDATE);
graf_mouse(M_ON, NULL);
+ vs_clip_off(atari_plot_vdi_handle);
atari_plot_flags &= ~PLOT_FLAG_LOCKED;
return(false);
}
@@ -1816,12 +1804,23 @@ bool plot_line(int x0, int y0, int x1, int y1,
uint32_t lt;
int sw = pstyle->stroke_width;
- pxy[0] = view.x + x0;
- pxy[1] = view.y + y0;
- pxy[2] = view.x + x1;
- pxy[3] = view.y + y1;
+ if((x0 < 0 && x1 < 0) || (y0 < 0 && y1 < 0)){
+ return(true);
+ }
+
+ pxy[0] = view.x + MAX(0,x0);
+ pxy[1] = view.y + MAX(0,y0);
+ pxy[2] = view.x + MAX(0,x1);
+ pxy[3] = view.y + MAX(0,y1);
+
+ if((y0 > view.h-1) && (y1 > view.h-1))
+ return(true);
+
+ //printf("view: %d,%d,%d,%d\n", view.x, view.y, view.w, view.h);
+ //printf("line: %d,%d,%d,%d\n", x0, y0, x1, y1);
+
- plot_vdi_clip(true);
+ //plot_vdi_clip(true);
if( sw == 0)
sw = 1;
NSLT2VDI(lt, pstyle)
@@ -1833,8 +1832,8 @@ bool plot_line(int x0, int y0, int x1, int y1,
vsl_width(atari_plot_vdi_handle, (short)sw);
vsl_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
v_pline(atari_plot_vdi_handle, 2, (short *)&pxy );
- plot_vdi_clip(false);
- return ( true );
+ //plot_vdi_clip(false);
+ return (true);
}
static bool plot_polygon(const int *p, unsigned int n,
@@ -1845,7 +1844,7 @@ static bool plot_polygon(const int *p, unsigned int n,
short d[4];
if (vdi_sysinfo.maxpolycoords > 0)
assert( (signed int)n < vdi_sysinfo.maxpolycoords);
- plot_vdi_clip(true);
+
vsf_interior(atari_plot_vdi_handle, FIS_SOLID);
vsf_style(atari_plot_vdi_handle, 1);
for (i = 0; i<n*2; i=i+2) {
@@ -1861,7 +1860,7 @@ static bool plot_polygon(const int *p, unsigned int n,
vsl_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
v_pline(atari_plot_vdi_handle, n+1, (short *)&pxy);
}
- plot_vdi_clip(false);
+
return ( true );
}
@@ -1888,13 +1887,61 @@ bool plot_set_dimensions(int x, int y, int w, int h)
return(true);
}
+bool plot_get_dimensions(GRECT *dst)
+{
+
+ dst->g_x = view.x;
+ dst->g_y = view.y;
+ dst->g_w = view.w;
+ dst->g_h = view.h;
+ return(true);
+}
+
bool plot_clip(const struct rect *clip)
{
- // FIXME: consider the canvas size
- view.clipping.x0 = clip->x0;
+ GRECT canvas, screen, gclip, isection;
+ short pxy[4];
+
+ screen.g_x = 0;
+ screen.g_y = 0;
+ screen.g_w = vdi_sysinfo.scr_w;
+ screen.g_h = vdi_sysinfo.scr_h;
+
+ plot_get_dimensions(&canvas);
+
view.clipping.y0 = clip->y0;
- view.clipping.x1 = clip->x1;
view.clipping.y1 = clip->y1;
+ view.clipping.x0 = clip->x0;
+ view.clipping.x1 = clip->x1;
+
+ plot_get_clip_grect(&gclip);
+
+ gclip.g_x += canvas.g_x;
+ gclip.g_y += canvas.g_y;
+
+ rc_intersect(&canvas, &gclip);
+
+ if(gclip.g_h < 0){
+ gclip.g_h = 0;
+ }
+
+ if (!rc_intersect(&screen, &gclip)) {
+ dbg_rect("cliprect: ", &view.clipping);
+ dbg_grect("screen: ", &canvas);
+ dbg_grect("canvas clipped: ", &gclip);
+ //assert(1 == 0);
+ }
+
+ //assert(rc_intersect(&screen, &gclip));
+
+ //dbg_grect("canvas clipped to screen", &gclip);
+
+ pxy[0] = gclip.g_x;
+ pxy[1] = gclip.g_y;
+ pxy[2] = pxy[0] + gclip.g_w;
+ pxy[3] = pxy[1] + gclip.g_h;
+
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&pxy);
return ( true );
}
@@ -1912,7 +1959,9 @@ bool plot_get_clip(struct rect * out)
void plot_get_clip_grect(GRECT * out)
{
struct rect clip={0,0,0,0};
+
plot_get_clip(&clip);
+
out->g_x = clip.x0;
out->g_y = clip.y0;
out->g_w = clip.x1 - clip.x0;
@@ -1927,7 +1976,6 @@ static bool plot_text(int x, int y, const char *text, size_t length, const plot_
static bool plot_disc(int x, int y, int radius, const plot_style_t *pstyle)
{
- plot_vdi_clip(true);
if (pstyle->fill_type != PLOT_OP_TYPE_SOLID) {
vsf_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
vsf_perimeter(atari_plot_vdi_handle, 1);
@@ -1939,14 +1987,14 @@ static bool plot_disc(int x, int y, int radius, const plot_style_t *pstyle)
vsf_interior(atari_plot_vdi_handle, FIS_SOLID);
v_circle(atari_plot_vdi_handle, view.x + x, view.y + y, radius);
}
- plot_vdi_clip(false);
- return ( true );
+
+ return(true);
}
static bool plot_arc(int x, int y, int radius, int angle1, int angle2,
const plot_style_t *pstyle)
{
- //plot_vdi_clip(true);
+
vswr_mode(atari_plot_vdi_handle, MD_REPLACE );
if (pstyle->fill_type == PLOT_OP_TYPE_NONE)
return(true);
@@ -1961,7 +2009,7 @@ static bool plot_arc(int x, int y, int radius, int angle1, int angle2,
vsf_perimeter(atari_plot_vdi_handle, 1);
v_arc(atari_plot_vdi_handle, view.x + x, view.y + y, radius, angle1*10, angle2*10);
}
- //plot_vdi_clip(true);
+
return (true);
}