Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "plDevs.h"
00017
00018 #ifdef PLD_mem
00019
00020 #include "plplotP.h"
00021 #include "drivers.h"
00022
00023
00024 PLDLLIMPEXP_DRIVER const char* plD_DEVICE_INFO_mem = "mem:User-supplied memory device:-1:mem:46:mem\n";
00025
00026 void plD_dispatch_init_mem( PLDispatchTable *pdt );
00027
00028 void plD_init_mem( PLStream * );
00029 void plD_line_mem( PLStream *, short, short, short, short );
00030 void plD_polyline_mem( PLStream *, short *, short *, PLINT );
00031 void plD_eop_mem( PLStream * );
00032 void plD_bop_mem( PLStream * );
00033 void plD_tidy_mem( PLStream * );
00034 void plD_state_mem( PLStream *, PLINT );
00035 void plD_esc_mem( PLStream *, PLINT, void * );
00036
00037 #undef MAX
00038 #undef ABS
00039 #define MAX( a, b ) ( ( a > b ) ? a : b )
00040 #define ABS( a ) ( ( a < 0 ) ? -a : a )
00041
00042 #define MAX_INTENSITY 255
00043
00044 void plD_dispatch_init_mem( PLDispatchTable *pdt )
00045 {
00046 #ifndef ENABLE_DYNDRIVERS
00047 pdt->pl_MenuStr = "User-supplied memory device";
00048 pdt->pl_DevName = "mem";
00049 #endif
00050 pdt->pl_type = plDevType_Null;
00051 pdt->pl_seq = 45;
00052 pdt->pl_init = (plD_init_fp) plD_init_mem;
00053 pdt->pl_line = (plD_line_fp) plD_line_mem;
00054 pdt->pl_polyline = (plD_polyline_fp) plD_polyline_mem;
00055 pdt->pl_eop = (plD_eop_fp) plD_eop_mem;
00056 pdt->pl_bop = (plD_bop_fp) plD_bop_mem;
00057 pdt->pl_tidy = (plD_tidy_fp) plD_tidy_mem;
00058 pdt->pl_state = (plD_state_fp) plD_state_mem;
00059 pdt->pl_esc = (plD_esc_fp) plD_esc_mem;
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 void
00069 plD_init_mem( PLStream *pls )
00070 {
00071
00072
00073
00074
00075
00076 if ( ( pls->phyxma == 0 ) || ( pls->dev == NULL ) )
00077 {
00078 plexit( "Must call plsmem first to set user plotting area!" );
00079 }
00080
00081 if ( pls->dev_mem_alpha == 1 )
00082 {
00083 plexit( "The mem driver does not support alpha values! Use plsmem!" );
00084 }
00085
00086 plP_setpxl( (PLFLT) 4, (PLFLT) 4 );
00087
00088
00089 pls->color = 1;
00090 pls->dev_fill0 = 0;
00091 pls->dev_fill1 = 0;
00092 pls->nopause = 1;
00093 }
00094
00095 #define sign( a ) ( ( a < 0 ) ? -1 : ( ( a == 0 ) ? 0 : 1 ) )
00096
00097
00098 void
00099 plD_line_mem( PLStream *pls, short x1a, short y1a, short x2a, short y2a )
00100 {
00101 int i;
00102 PLINT idx;
00103 int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
00104 PLINT x1b, y1b, x2b, y2b;
00105 PLFLT length, fx, fy, dx, dy;
00106 unsigned char *mem = (unsigned char *) pls->dev;
00107 PLINT xm = pls->phyxma;
00108 PLINT ym = pls->phyyma;
00109
00110
00111
00112 y1 = ym - ( y1 - 0 );
00113 y2 = ym - ( y2 - 0 );
00114
00115 x1b = x1, x2b = x2, y1b = y1, y2b = y2;
00116 length = (PLFLT) sqrt( (double)
00117 ( ( x2b - x1b ) * ( x2b - x1b ) + ( y2b - y1b ) * ( y2b - y1b ) ) );
00118
00119 if ( length == 0. )
00120 length = 1.;
00121 dx = ( x2 - x1 ) / length;
00122 dy = ( y2 - y1 ) / length;
00123
00124 fx = x1;
00125 fy = y1;
00126 mem[3 * xm * y1 + 3 * x1 + 0] = pls->curcolor.r;
00127 mem[3 * xm * y1 + 3 * x1 + 1] = pls->curcolor.g;
00128 mem[3 * xm * y1 + 3 * x1 + 2] = pls->curcolor.b;
00129
00130 mem[3 * xm * y2 + 3 * x2 + 0] = pls->curcolor.r;
00131 mem[3 * xm * y2 + 3 * x2 + 1] = pls->curcolor.g;
00132 mem[3 * xm * y2 + 3 * x2 + 2] = pls->curcolor.b;
00133
00134 for ( i = 1; i <= (int) length; i++ )
00135 {
00136 fx += dx;
00137 fy += dy;
00138 idx = 3 * xm * (PLINT) fy + 3 * (PLINT) fx;
00139 mem[idx + 0] = pls->curcolor.r;
00140 mem[idx + 1] = pls->curcolor.g;
00141 mem[idx + 2] = pls->curcolor.b;
00142 }
00143 }
00144
00145 void
00146 plD_polyline_mem( PLStream *pls, short *xa, short *ya, PLINT npts )
00147 {
00148 int i;
00149 for ( i = 0; i < npts - 1; i++ )
00150 plD_line_mem( pls, xa[i], ya[i], xa[i + 1], ya[i + 1] );
00151 }
00152
00153 void
00154 plD_eop_mem( PLStream *pls )
00155 {
00156
00157
00158
00159
00160 pls->dev = NULL;
00161 }
00162
00163 void
00164 plD_bop_mem( PLStream *pls )
00165 {
00166
00167 }
00168
00169 void
00170 plD_tidy_mem( PLStream *pls )
00171 {
00172
00173 }
00174
00175 void
00176 plD_state_mem( PLStream *pls, PLINT op )
00177 {
00178
00179 }
00180
00181 void
00182 plD_esc_mem( PLStream *pls, PLINT op, void *ptr )
00183 {
00184
00185 }
00186
00187 #endif // PLD_mem