| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| typedef PerlIO * InputStream; |
| 6 |
|
| |
| 7 |
|
| #define S_TXT 0 |
| 8 |
|
| #define S_CHK_B 1 |
| 9 |
|
| #define S_WAIT_LTR 2 |
| 10 |
|
| #define S_END 3 |
| 11 |
|
| |
| 12 |
|
| #define WRAP 80 |
| 13 |
|
| #define TABSTOP 8 |
| 14 |
|
| |
| 15 |
|
| static void |
| 16 |
204 |
| store( image, x, y, c, attr, is_truecolor, rgb_f, rgb_b, wrap, width, height, pal ) |
| 17 |
|
| SV *image; |
| 18 |
|
| int *x; |
| 19 |
|
| int *y; |
| 20 |
|
| unsigned char c; |
| 21 |
|
| int attr; |
| 22 |
|
| int is_truecolor; |
| 23 |
|
| int *rgb_f; |
| 24 |
|
| int *rgb_b; |
| 25 |
|
| int wrap; |
| 26 |
|
| int *width; |
| 27 |
|
| int *height; |
| 28 |
|
| AV *pal; |
| 29 |
|
| { |
| 30 |
204 |
| HV *pixel = newHV(); |
| 31 |
204 |
| hv_store( pixel, "char", 4, newSVpvn( &c, 1 ), 0 ); |
| 32 |
|
| |
| 33 |
204 |
▶ | if( is_truecolor == 1 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( is_truecolor == 1 ) { |
3 |
201 |
204 |
|
| 34 |
3 |
| AV *rgb = newAV(); |
| 35 |
3 |
| av_push( rgb, newSViv( rgb_f[ 0 ] ) ); |
| 36 |
3 |
| av_push( rgb, newSViv( rgb_f[ 1 ] ) ); |
| 37 |
3 |
| av_push( rgb, newSViv( rgb_f[ 2 ] ) ); |
| 38 |
3 |
| av_push( pal, newRV_noinc((SV *) rgb ) ); |
| 39 |
3 |
| hv_store( pixel, "fg", 2, newSViv( av_len( pal ) ), 0 ); |
| 40 |
|
| |
| 41 |
3 |
| rgb = newAV(); |
| 42 |
3 |
| av_push( rgb, newSViv( rgb_b[ 0 ] ) ); |
| 43 |
3 |
| av_push( rgb, newSViv( rgb_b[ 1 ] ) ); |
| 44 |
3 |
| av_push( rgb, newSViv( rgb_b[ 2 ] ) ); |
| 45 |
3 |
| av_push( pal, newRV_noinc((SV *) rgb ) ); |
| 46 |
3 |
| hv_store( pixel, "bg", 2, newSViv( av_len( pal ) ), 0 ); |
| 47 |
|
| } |
| 48 |
|
| else { |
| 49 |
201 |
| hv_store( pixel, "attr", 4, newSViv( attr ), 0 ); |
| 50 |
|
| } |
| 51 |
|
| |
| 52 |
204 |
| AV *rows = (AV *) SvRV( *hv_fetch( (HV *) SvRV( image ), "pixeldata", 9, 0 ) ); |
| 53 |
|
| |
| 54 |
204 |
| int newrow = 1; |
| 55 |
204 |
| AV *row = newAV(); |
| 56 |
204 |
| SV **elem_p = av_fetch( rows, *y, FALSE ); |
| 57 |
|
| |
| 58 |
204 |
▶ | if( elem_p ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( elem_p ) { |
178 |
26 |
204 |
|
| 59 |
178 |
| row = (AV *) SvRV( *elem_p ); |
| 60 |
178 |
| newrow = 0; |
| 61 |
|
| } |
| 62 |
|
| |
| 63 |
204 |
| av_store( row, *x, newRV_noinc((SV *) pixel ) ); |
| 64 |
|
| |
| 65 |
204 |
▶ | if( newrow ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( newrow ) { |
26 |
178 |
204 |
|
| 66 |
26 |
| av_store( rows, *y, newRV_noinc((SV *) row) ); |
| 67 |
|
| } |
| 68 |
|
| |
| 69 |
204 |
▶ | if( *x + 1 > *width ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if( *x + 1 > *width ){ |
182 |
22 |
204 |
|
| 70 |
182 |
| *width = *x + 1; |
| 71 |
|
| } |
| 72 |
|
| |
| 73 |
204 |
▶ | if( *y + 1 > *height ){ |
Branch: 1 branch
| Branch | True | False | Total |
| if( *y + 1 > *height ){ |
26 |
178 |
204 |
|
| 74 |
26 |
| *height = *y + 1; |
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
204 |
| (*x)++; |
| 78 |
204 |
▶ | if( *x == wrap ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( *x == wrap ) { |
2 |
202 |
204 |
|
| 79 |
2 |
| *x = 0; (*y)++; |
| 80 |
|
| } |
| 81 |
204 |
| } |
| 82 |
|
| |
| 83 |
|
| static void |
| 84 |
88 |
| set_attrs( attr, args, pal, rgb_f, rgb_b ) // set the current attribute byte |
| 85 |
|
| int *attr; |
| 86 |
|
| AV *args; |
| 87 |
|
| AV *pal; |
| 88 |
|
| int *rgb_f; |
| 89 |
|
| int *rgb_b; |
| 90 |
|
| { |
| 91 |
|
| int i; |
| 92 |
|
| int arg; |
| 93 |
|
| int oldfg; |
| 94 |
|
| int oldbg; |
| 95 |
|
| AV *c; |
| 96 |
|
| |
| 97 |
284 |
▶ | for( i = 0; i <= av_len( args ); i++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for( i = 0; i <= av_len( args ); i++ ) { |
196 |
88 |
284 |
|
| 98 |
196 |
| arg = SvIV(* av_fetch( args, i, 0 ) ); |
| 99 |
196 |
▶ | if ( arg == 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( arg == 0 ) { |
47 |
149 |
196 |
|
| 100 |
47 |
| *attr = 7; |
| 101 |
47 |
| c = (AV *) SvRV( *av_fetch( pal, 7, 0 ) ); |
| 102 |
47 |
| rgb_f[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 103 |
47 |
| rgb_f[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 104 |
47 |
| rgb_f[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 105 |
47 |
| c = (AV *) SvRV( *av_fetch( pal, 0, 0 ) ); |
| 106 |
47 |
| rgb_b[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 107 |
47 |
| rgb_b[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 108 |
47 |
| rgb_b[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 109 |
|
| } |
| 110 |
149 |
▶ | else if ( arg == 1 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( arg == 1 ) { |
14 |
135 |
149 |
|
| 111 |
14 |
| *attr |= 8; |
| 112 |
14 |
| c = (AV *) SvRV( *av_fetch( pal, *attr & 15, 0 ) ); |
| 113 |
14 |
| rgb_f[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 114 |
14 |
| rgb_f[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 115 |
14 |
| rgb_f[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 116 |
|
| } |
| 117 |
135 |
▶ | else if ( arg == 2 || arg == 22 ) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if ( arg == 2 || arg == 22 ) { |
135 |
0 |
135 |
| else if ( arg == 2 || arg == 22 ) { |
0 |
135 |
135 |
|
| 118 |
0 |
| *attr &= 247; |
| 119 |
0 |
| c = (AV *) SvRV( *av_fetch( pal, *attr & 15, 0 ) ); |
| 120 |
0 |
| rgb_f[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 121 |
0 |
| rgb_f[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 122 |
0 |
| rgb_f[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 123 |
|
| } |
| 124 |
135 |
▶ | else if ( arg == 5 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( arg == 5 ) { |
13 |
122 |
135 |
|
| 125 |
13 |
| *attr |= 128; |
| 126 |
13 |
| c = (AV *) SvRV( *av_fetch( pal, ( *attr & 240 ) >> 4, 0 ) ); |
| 127 |
13 |
| rgb_b[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 128 |
13 |
| rgb_b[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 129 |
13 |
| rgb_b[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 130 |
|
| } |
| 131 |
122 |
▶ | else if ( arg == 7 || arg == 27 ) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if ( arg == 7 || arg == 27 ) { |
122 |
0 |
122 |
| else if ( arg == 7 || arg == 27 ) { |
0 |
122 |
122 |
|
| 132 |
0 |
| oldfg = *attr & 15; |
| 133 |
0 |
| oldbg = ( *attr & 240 ) >> 4; |
| 134 |
0 |
| *attr = oldbg | ( oldfg << 4 ); |
| 135 |
0 |
| c = (AV *) SvRV( *av_fetch( pal, *attr & 15, 0 ) ); |
| 136 |
0 |
| rgb_f[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 137 |
0 |
| rgb_f[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 138 |
0 |
| rgb_f[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 139 |
0 |
| c = (AV *) SvRV( *av_fetch( pal, ( *attr & 240 ) >> 4, 0 ) ); |
| 140 |
0 |
| rgb_b[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 141 |
0 |
| rgb_b[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 142 |
0 |
| rgb_b[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 143 |
|
| } |
| 144 |
122 |
▶ | else if ( arg == 25 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if ( arg == 25 ) { |
0 |
122 |
122 |
|
| 145 |
0 |
| *attr &= 127; |
| 146 |
0 |
| c = (AV *) SvRV( *av_fetch( pal, ( *attr & 240 ) >> 4, 0 ) ); |
| 147 |
0 |
| rgb_b[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 148 |
0 |
| rgb_b[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 149 |
0 |
| rgb_b[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 150 |
|
| } |
| 151 |
122 |
▶ | else if ( arg >= 30 && arg <= 37 ) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if ( arg >= 30 && arg <= 37 ) { |
122 |
0 |
122 |
| else if ( arg >= 30 && arg <= 37 ) { |
68 |
54 |
122 |
|
| 152 |
68 |
| *attr &= 248; |
| 153 |
68 |
| *attr |= ( arg - 30 ); |
| 154 |
68 |
| c = (AV *) SvRV( *av_fetch( pal, *attr & 15, 0 ) ); |
| 155 |
68 |
| rgb_f[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 156 |
68 |
| rgb_f[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 157 |
68 |
| rgb_f[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 158 |
|
| } |
| 159 |
54 |
▶ | else if ( arg >= 40 && arg <= 47 ) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if ( arg >= 40 && arg <= 47 ) { |
54 |
0 |
54 |
| else if ( arg >= 40 && arg <= 47 ) { |
54 |
0 |
54 |
|
| 160 |
54 |
| *attr &= 143; |
| 161 |
54 |
| *attr |= ( ( arg - 40 ) << 4 ); |
| 162 |
54 |
| c = (AV *) SvRV( *av_fetch( pal, ( *attr & 240 ) >> 4, 0 ) ); |
| 163 |
54 |
| rgb_b[ 0 ] = SvIV(* av_fetch( c, 0, 0 ) ); |
| 164 |
54 |
| rgb_b[ 1 ] = SvIV(* av_fetch( c, 1, 0 ) ); |
| 165 |
54 |
| rgb_b[ 2 ] = SvIV(* av_fetch( c, 2, 0 ) ); |
| 166 |
|
| } |
| 167 |
|
| } |
| 168 |
88 |
| } |
| 169 |
|
| |
| 170 |
|
| MODULE = Image::TextMode::Reader::ANSI::XS PACKAGE = Image::TextMode::Reader::ANSI::XS |
| 171 |
|
| |
| 172 |
|
| PROTOTYPES: DISABLE |
| 173 |
|
| |
| 174 |
|
| SV * |
| 175 |
|
| _read( self, image, file, options ) |
| 176 |
|
| SV *self |
| 177 |
|
| SV *image |
| 178 |
|
| InputStream file |
| 179 |
|
| HV *options |
| 180 |
|
| PREINIT: |
| 181 |
|
| unsigned char c; |
| 182 |
18 |
| int state = S_TXT; |
| 183 |
|
| unsigned char argbuf[ 255 ]; |
| 184 |
18 |
| int arg_index = 0; |
| 185 |
18 |
| int x = 0; |
| 186 |
18 |
| int y = 0; |
| 187 |
18 |
| int save_x = 0; |
| 188 |
18 |
| int save_y = 0; |
| 189 |
18 |
| int attr = 7; |
| 190 |
18 |
| int wrap = WRAP; |
| 191 |
18 |
| int width = 0; |
| 192 |
18 |
| int height = 0; |
| 193 |
18 |
| int filesize = 0; |
| 194 |
18 |
| int is_truecolor = 0; |
| 195 |
|
| int rgb_f[3]; |
| 196 |
|
| int rgb_b[3]; |
| 197 |
18 |
| AV *args = newAV(); |
| 198 |
|
| CODE: |
| 199 |
|
| int i; |
| 200 |
|
| int count; |
| 201 |
|
| char *feature; |
| 202 |
|
| SV **temp_pv; |
| 203 |
18 |
| sv_2mortal( (SV * ) args ); |
| 204 |
|
| |
| 205 |
|
| // render options hashref |
| 206 |
18 |
| HV *render_opts = (HV *) SvRV( *hv_fetch( (HV *) SvRV( image ), "render_options", 14, 0 ) ); |
| 207 |
|
| |
| 208 |
|
| // palette |
| 209 |
18 |
| AV *pal = (AV *) SvRV( *hv_fetch( (HV *) SvRV( *hv_fetch( (HV *) SvRV( image ), "palette", 7, 0 ) ), "colors", 6, 0 ) ); |
| 210 |
|
| |
| 211 |
|
| // get options |
| 212 |
18 |
▶ | if( hv_exists( options, "width", 5 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( hv_exists( options, "width", 5 ) ) { |
1 |
17 |
18 |
|
| 213 |
1 |
| wrap = SvIV(* hv_fetch( options, "width", 5, 0 ) ); |
| 214 |
|
| } |
| 215 |
|
| |
| 216 |
18 |
▶ | if( !wrap ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !wrap ) { |
0 |
18 |
18 |
|
| 217 |
0 |
| wrap = WRAP; |
| 218 |
|
| } |
| 219 |
|
| |
| 220 |
|
| // blink mode |
| 221 |
18 |
| SV *saucerec = *hv_fetch( (HV *) SvRV( image ), "sauce", 5, 0 ); |
| 222 |
18 |
▶ | if( hv_exists( (HV *) SvRV( saucerec ), "has_sauce", 9 ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( hv_exists( (HV *) SvRV( saucerec ), "has_sauce", 9 ) ) { |
9 |
9 |
18 |
|
| 223 |
9 |
| SV *has_sauce = *hv_fetch( (HV *) SvRV( saucerec ), "has_sauce", 9, 0 ); |
| 224 |
9 |
▶ | if( SvOK( has_sauce ) && SvTRUE( has_sauce ) ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if( SvOK( has_sauce ) && SvTRUE( has_sauce ) ) { |
9 |
0 |
9 |
| if( SvOK( has_sauce ) && SvTRUE( has_sauce ) ) { |
1 |
8 |
9 |
|
| 225 |
1 |
| int flags = SvIV( *hv_fetch( (HV *) SvRV( saucerec ), "flags_id", 8, 0 ) ); |
| 226 |
1 |
| hv_store( render_opts, "blink_mode", 10, newSViv( 0 ), flags ^ 1 ); |
| 227 |
|
| } |
| 228 |
|
| } |
| 229 |
|
| |
| 230 |
18 |
| filesize = SvIV(* hv_fetch( options, "filesize", 8, 0 ) ); |
| 231 |
|
| |
| 232 |
18 |
| PerlIO_rewind( file ); |
| 233 |
|
| |
| 234 |
19047 |
▶ | while ( state != S_END && ( c = PerlIO_getc( file ) ) != -1 && !PerlIO_eof( file ) && PerlIO_tell( file ) <= filesize ) { |
Branch: 3 branches
| Branch | True | False | Total |
| while ( state != S_END && ( c = PerlIO_getc( file ) ) != -1 && !PerlIO_eof( file ) && PerlIO_tell( file ) <= filesize ) { |
19038 |
9 |
19047 |
| while ( state != S_END && ( c = PerlIO_getc( file ) ) != -1 && !PerlIO_eof( file ) && PerlIO_tell( file ) <= filesize ) { |
19029 |
9 |
19038 |
| while ( state != S_END && ( c = PerlIO_getc( file ) ) != -1 && !PerlIO_eof( file ) && PerlIO_tell( file ) <= filesize ) { |
19029 |
0 |
19029 |
|
| 235 |
19029 |
| switch ( state ) { |
| 236 |
18338 |
| case S_TXT : // parse text |
| 237 |
18338 |
| switch( c ) { |
| 238 |
9 |
| case '\x1a' : state = S_END; break; |
| 239 |
112 |
| case '\x1b' : state = S_CHK_B; break; |
| 240 |
9013 |
| case '\n' : |
| 241 |
9013 |
| x = 0; y++; |
| 242 |
18025 |
| case '\r' : break; |
| 243 |
2 |
| case '\t' : |
| 244 |
2 |
| count = ( x + 1 ) % TABSTOP; |
| 245 |
2 |
▶ | if( count ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( count ) { |
2 |
0 |
2 |
|
| 246 |
2 |
| count = TABSTOP - count; |
| 247 |
16 |
▶ | for ( i = 0; i < count; i++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for ( i = 0; i < count; i++ ) { |
14 |
2 |
16 |
|
| 248 |
14 |
| store( image, &x, &y, ' ', attr, is_truecolor, &rgb_f, &rgb_b, wrap, &width, &height, pal ); |
| 249 |
|
| } |
| 250 |
|
| } |
| 251 |
2 |
| break; |
| 252 |
190 |
| default : |
| 253 |
190 |
| store( image, &x, &y, c, attr, is_truecolor, &rgb_f, &rgb_b, wrap, &width, &height, pal ); |
| 254 |
190 |
| break; |
| 255 |
|
| } |
| 256 |
18338 |
| break; |
| 257 |
112 |
| case S_CHK_B : // check for a left square bracket |
| 258 |
112 |
▶ | if( c != '[' ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( c != '[' ) { |
0 |
112 |
112 |
|
| 259 |
0 |
| store( image, &x, &y, '\x1b', attr, is_truecolor, &rgb_f, &rgb_b, wrap, &width, &height, pal ); |
| 260 |
0 |
| store( image, &x, &y, c, attr, is_truecolor, &rgb_f, &rgb_b, wrap, &width, &height, pal ); |
| 261 |
0 |
| state = S_TXT; |
| 262 |
|
| } |
| 263 |
|
| else { |
| 264 |
112 |
| state = S_WAIT_LTR; |
| 265 |
|
| } |
| 266 |
112 |
| break; |
| 267 |
579 |
| case S_WAIT_LTR : // wait for a letter to exec. a command |
| 268 |
579 |
▶ | if ( isALPHA( c ) || c == ';' ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( isALPHA( c ) || c == ';' ) { |
467 |
112 |
579 |
| if ( isALPHA( c ) || c == ';' ) { |
115 |
352 |
467 |
|
| 269 |
227 |
| argbuf[arg_index] = 0; |
| 270 |
227 |
| av_push( args, newSVpv( argbuf, 0 ) ); |
| 271 |
227 |
| arg_index = 0; |
| 272 |
227 |
▶ | if( c == ';' ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( c == ';' ) |
115 |
112 |
227 |
|
| 273 |
115 |
| break; |
| 274 |
|
| } |
| 275 |
|
| |
| 276 |
464 |
▶ | if ( isALPHA( c ) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if ( isALPHA( c ) ) { |
112 |
352 |
464 |
|
| 277 |
112 |
| switch( c ) { |
| 278 |
88 |
| case 'm' : // set attributes |
| 279 |
88 |
| set_attrs( &attr, args, pal, rgb_f, rgb_b ); |
| 280 |
88 |
| break; |
| 281 |
2 |
| case 'H' : // set position |
| 282 |
|
| case 'f' : |
| 283 |
2 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 284 |
2 |
▶ | y = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| y = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
1 |
1 |
2 |
|
| 285 |
2 |
| temp_pv = av_fetch( args, 1, TRUE ); |
| 286 |
2 |
▶ | x = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| x = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
1 |
1 |
2 |
|
| 287 |
2 |
| y--; |
| 288 |
2 |
| x--; |
| 289 |
2 |
▶ | if( y < 0 ) y = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if( y < 0 ) y = 0; |
0 |
2 |
2 |
|
| 290 |
2 |
▶ | if( x < 0 ) x = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if( x < 0 ) x = 0; |
0 |
2 |
2 |
|
| 291 |
2 |
| break; |
| 292 |
2 |
| case 'A' : // move up |
| 293 |
2 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 294 |
2 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
1 |
1 |
2 |
|
| 295 |
2 |
| y -= i; |
| 296 |
2 |
▶ | if( y < 0 ) y = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if( y < 0 ) y = 0; |
0 |
2 |
2 |
|
| 297 |
2 |
| break; |
| 298 |
2 |
| case 'B' : // move down |
| 299 |
2 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 300 |
2 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
1 |
1 |
2 |
|
| 301 |
2 |
| y += i; |
| 302 |
2 |
| break; |
| 303 |
2 |
| case 'C' : // move right |
| 304 |
2 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 305 |
2 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
1 |
1 |
2 |
|
| 306 |
2 |
| x += i; |
| 307 |
2 |
| break; |
| 308 |
2 |
| case 'D' : // move left |
| 309 |
2 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 310 |
2 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
1 |
1 |
2 |
|
| 311 |
2 |
| x -= i; |
| 312 |
2 |
▶ | if( x < 0 ) x = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if( x < 0 ) x = 0; |
0 |
2 |
2 |
|
| 313 |
2 |
| break; |
| 314 |
0 |
| case 'E' : // next line |
| 315 |
0 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 316 |
0 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
0 |
0 |
0 |
|
| 317 |
0 |
| x = 0; |
| 318 |
0 |
| y += i; |
| 319 |
0 |
| break; |
| 320 |
1 |
| case 'F' : // previous line |
| 321 |
1 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 322 |
1 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
1 |
0 |
1 |
|
| 323 |
1 |
| x = 0; |
| 324 |
1 |
| y -= i; |
| 325 |
1 |
▶ | if( y < 0 ) y = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if( y < 0 ) y = 0; |
0 |
1 |
1 |
|
| 326 |
1 |
| break; |
| 327 |
0 |
| case 'G' : // horizontal move |
| 328 |
0 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 329 |
0 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 1; |
0 |
0 |
0 |
|
| 330 |
0 |
| x = i - 1; |
| 331 |
0 |
| break; |
| 332 |
1 |
| case 'h' : // feature on |
| 333 |
2 |
▶ | feature = av_len( args ) < 0 ? "" : SvPV_nolen(* av_fetch( args, 0, 0 ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| feature = av_len( args ) < 0 ? "" : SvPV_nolen(* av_fetch( args, 0, 0 ) ); |
1 |
0 |
1 |
|
| 334 |
1 |
▶ | if( strcmp( feature, "?33" ) == 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( strcmp( feature, "?33" ) == 0 ) { |
1 |
0 |
1 |
|
| 335 |
1 |
| hv_store( render_opts, "blink_mode", 10, newSViv( 0 ), 0 ); |
| 336 |
|
| } |
| 337 |
1 |
| break; |
| 338 |
0 |
| case 'l' : // feature off |
| 339 |
0 |
▶ | feature = av_len( args ) < 0 ? "" : SvPV_nolen(* av_fetch( args, 0, 0 ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| feature = av_len( args ) < 0 ? "" : SvPV_nolen(* av_fetch( args, 0, 0 ) ); |
0 |
0 |
0 |
|
| 340 |
0 |
▶ | if( strcmp( feature, "?33" ) == 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( strcmp( feature, "?33" ) == 0 ) { |
0 |
0 |
0 |
|
| 341 |
0 |
| hv_store( render_opts, "blink_mode", 10, newSViv( 1 ), 0 ); |
| 342 |
|
| } |
| 343 |
0 |
| break; |
| 344 |
1 |
| case 's' : // save position |
| 345 |
1 |
| save_x = x; save_y = y; |
| 346 |
1 |
| break; |
| 347 |
2 |
| case 't' : // rgb palette set |
| 348 |
2 |
| hv_store( render_opts, "truecolor", 9, newSViv( 1 ), 0 ); |
| 349 |
2 |
| is_truecolor = 1; |
| 350 |
2 |
| i = SvIV(* av_fetch( args, 0, TRUE ) ); |
| 351 |
2 |
▶ | if( i == 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( i == 0 ) { |
1 |
1 |
2 |
|
| 352 |
1 |
| rgb_b[ 0 ] = SvIV(* av_fetch( args, 1, TRUE ) ); |
| 353 |
1 |
| rgb_b[ 1 ] = SvIV(* av_fetch( args, 2, TRUE ) ); |
| 354 |
1 |
| rgb_b[ 2 ] = SvIV(* av_fetch( args, 3, TRUE ) ); |
| 355 |
|
| } |
| 356 |
|
| else { |
| 357 |
1 |
| rgb_f[ 0 ] = SvIV(* av_fetch( args, 1, TRUE ) ); |
| 358 |
1 |
| rgb_f[ 1 ] = SvIV(* av_fetch( args, 2, TRUE ) ); |
| 359 |
1 |
| rgb_f[ 2 ] = SvIV(* av_fetch( args, 3, TRUE ) ); |
| 360 |
|
| } |
| 361 |
2 |
| break; |
| 362 |
1 |
| case 'u' : // restore position |
| 363 |
1 |
| x = save_x; y = save_y; |
| 364 |
1 |
| break; |
| 365 |
5 |
| case 'J' : // clear screen |
| 366 |
5 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 367 |
5 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 0; |
4 |
1 |
5 |
|
| 368 |
|
| |
| 369 |
5 |
▶ | if( !i ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !i ) { |
1 |
4 |
5 |
|
| 370 |
|
| int row; |
| 371 |
1 |
| int next = y + 1; |
| 372 |
2 |
▶ | for( row = 1; row <= height - next + 1; row++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for( row = 1; row <= height - next + 1; row++ ) { |
1 |
1 |
2 |
|
| 373 |
1 |
| ENTER; |
| 374 |
1 |
| SAVETMPS; |
| 375 |
1 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
1 |
1 |
|
| 376 |
1 |
▶ | XPUSHs( image ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( image ); |
0 |
1 |
1 |
|
| 377 |
1 |
▶ | XPUSHs( sv_2mortal( newSViv( next ) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newSViv( next ) ) ); |
0 |
1 |
1 |
|
| 378 |
1 |
| PUTBACK; |
| 379 |
1 |
| call_method( "delete_line", G_DISCARD | G_VOID ); |
| 380 |
1 |
| SPAGAIN; |
| 381 |
1 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
1 |
0 |
1 |
|
| 382 |
1 |
| LEAVE; |
| 383 |
1 |
| height--; |
| 384 |
|
| } |
| 385 |
|
| |
| 386 |
1 |
| ENTER; |
| 387 |
1 |
| SAVETMPS; |
| 388 |
1 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
1 |
1 |
|
| 389 |
1 |
▶ | XPUSHs( image ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( image ); |
0 |
1 |
1 |
|
| 390 |
1 |
▶ | XPUSHs( sv_2mortal( newSViv( y ) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newSViv( y ) ) ); |
0 |
1 |
1 |
|
| 391 |
1 |
| AV *cols = newAV(); |
| 392 |
1 |
| av_store( cols, 0, newSViv( x ) ); |
| 393 |
1 |
| av_store( cols, 1, newSViv( -1 ) ); |
| 394 |
1 |
▶ | XPUSHs( sv_2mortal( newRV_noinc((SV *) cols) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newRV_noinc((SV *) cols) ) ); |
0 |
1 |
1 |
|
| 395 |
1 |
| PUTBACK; |
| 396 |
1 |
| call_method( "clear_line", G_DISCARD | G_VOID ); |
| 397 |
1 |
| SPAGAIN; |
| 398 |
1 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
1 |
0 |
1 |
|
| 399 |
1 |
| LEAVE; |
| 400 |
|
| } |
| 401 |
4 |
▶ | else if( i == 1 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if( i == 1 ) { |
1 |
3 |
4 |
|
| 402 |
|
| int row; |
| 403 |
2 |
▶ | for( row = 0; row < y; row++ ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for( row = 0; row < y; row++ ) { |
1 |
1 |
2 |
|
| 404 |
1 |
| ENTER; |
| 405 |
1 |
| SAVETMPS; |
| 406 |
1 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
1 |
1 |
|
| 407 |
1 |
▶ | XPUSHs( image ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( image ); |
0 |
1 |
1 |
|
| 408 |
1 |
▶ | XPUSHs( sv_2mortal( newSViv( row ) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newSViv( row ) ) ); |
0 |
1 |
1 |
|
| 409 |
1 |
| PUTBACK; |
| 410 |
1 |
| call_method( "clear_line", G_DISCARD | G_VOID ); |
| 411 |
1 |
| SPAGAIN; |
| 412 |
1 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
1 |
0 |
1 |
|
| 413 |
1 |
| LEAVE; |
| 414 |
|
| } |
| 415 |
|
| |
| 416 |
1 |
| ENTER; |
| 417 |
1 |
| SAVETMPS; |
| 418 |
1 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
1 |
1 |
|
| 419 |
1 |
▶ | XPUSHs( image ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( image ); |
0 |
1 |
1 |
|
| 420 |
1 |
▶ | XPUSHs( sv_2mortal( newSViv( y ) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newSViv( y ) ) ); |
0 |
1 |
1 |
|
| 421 |
1 |
| AV *cols = newAV(); |
| 422 |
1 |
| av_store( cols, 0, newSViv( 0 ) ); |
| 423 |
1 |
| av_store( cols, 1, newSViv( x ) ); |
| 424 |
1 |
▶ | XPUSHs( sv_2mortal( newRV_noinc((SV *) cols) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newRV_noinc((SV *) cols) ) ); |
0 |
1 |
1 |
|
| 425 |
1 |
| PUTBACK; |
| 426 |
1 |
| call_method( "clear_line", G_DISCARD | G_VOID ); |
| 427 |
1 |
| SPAGAIN; |
| 428 |
1 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
1 |
0 |
1 |
|
| 429 |
1 |
| LEAVE; |
| 430 |
|
| } |
| 431 |
3 |
▶ | else if( i == 2 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if( i == 2 ) { |
3 |
0 |
3 |
|
| 432 |
3 |
| ENTER; |
| 433 |
3 |
| SAVETMPS; |
| 434 |
3 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
3 |
3 |
|
| 435 |
3 |
▶ | XPUSHs( image ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( image ); |
0 |
3 |
3 |
|
| 436 |
3 |
| PUTBACK; |
| 437 |
3 |
| call_method( "clear_screen", G_DISCARD | G_VOID ); |
| 438 |
3 |
| SPAGAIN; |
| 439 |
3 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
3 |
0 |
3 |
|
| 440 |
3 |
| LEAVE; |
| 441 |
3 |
| width = 0; |
| 442 |
3 |
| height = 0; |
| 443 |
3 |
| x = 0; |
| 444 |
3 |
| y = 0; |
| 445 |
|
| } |
| 446 |
5 |
| break; |
| 447 |
3 |
| case 'K' : // clear line |
| 448 |
3 |
| temp_pv = av_fetch( args, 0, TRUE ); |
| 449 |
3 |
▶ | i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| i = looks_like_number( *temp_pv ) ? SvIV( *temp_pv ) : 0; |
2 |
1 |
3 |
|
| 450 |
|
| |
| 451 |
3 |
| ENTER; |
| 452 |
3 |
| SAVETMPS; |
| 453 |
3 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
3 |
3 |
|
| 454 |
3 |
▶ | XPUSHs( image ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( image ); |
0 |
3 |
3 |
|
| 455 |
3 |
▶ | XPUSHs( sv_2mortal( newSViv( y ) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newSViv( y ) ) ); |
0 |
3 |
3 |
|
| 456 |
|
| |
| 457 |
3 |
▶ | if( !i ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( !i ) { |
1 |
2 |
3 |
|
| 458 |
1 |
| AV *cols = newAV(); |
| 459 |
1 |
| av_store( cols, 0, newSViv( x ) ); |
| 460 |
1 |
| av_store( cols, 1, newSViv( -1 ) ); |
| 461 |
1 |
▶ | XPUSHs( sv_2mortal( newRV_noinc((SV *) cols) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newRV_noinc((SV *) cols) ) ); |
0 |
1 |
1 |
|
| 462 |
|
| } |
| 463 |
2 |
▶ | else if( i == 1 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if( i == 1 ) { |
1 |
1 |
2 |
|
| 464 |
1 |
| AV *cols = newAV(); |
| 465 |
1 |
| av_store( cols, 0, newSViv( 0 ) ); |
| 466 |
1 |
| av_store( cols, 1, newSViv( x ) ); |
| 467 |
1 |
▶ | XPUSHs( sv_2mortal( newRV_noinc((SV *) cols) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newRV_noinc((SV *) cols) ) ); |
0 |
1 |
1 |
|
| 468 |
|
| } |
| 469 |
|
| else if( i == 2 ) { // no additional args |
| 470 |
|
| } |
| 471 |
|
| |
| 472 |
3 |
| PUTBACK; |
| 473 |
3 |
| call_method( "clear_line", G_DISCARD | G_VOID ); |
| 474 |
3 |
| SPAGAIN; |
| 475 |
3 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
3 |
0 |
3 |
|
| 476 |
3 |
| LEAVE; |
| 477 |
|
| |
| 478 |
3 |
| break; |
| 479 |
0 |
| default: |
| 480 |
0 |
| break; |
| 481 |
|
| } |
| 482 |
112 |
| av_clear( args ); |
| 483 |
112 |
| state = S_TXT; |
| 484 |
112 |
| break; |
| 485 |
|
| } |
| 486 |
352 |
| argbuf[ arg_index ] = c; |
| 487 |
352 |
| arg_index++; |
| 488 |
352 |
| break; |
| 489 |
0 |
| case S_END : // done parsing |
| 490 |
0 |
| default : break; |
| 491 |
|
| } |
| 492 |
|
| } |
| 493 |
|
| |
| 494 |
|
| // set width + height of the image |
| 495 |
18 |
| ENTER; |
| 496 |
18 |
| SAVETMPS; |
| 497 |
18 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
18 |
18 |
|
| 498 |
18 |
▶ | XPUSHs( image ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( image ); |
0 |
18 |
18 |
|
| 499 |
18 |
▶ | XPUSHs( sv_2mortal( newSViv( width ) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newSViv( width ) ) ); |
0 |
18 |
18 |
|
| 500 |
18 |
| PUTBACK; |
| 501 |
18 |
| call_method( "width", G_DISCARD | G_VOID ); |
| 502 |
18 |
| SPAGAIN; |
| 503 |
18 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
18 |
0 |
18 |
|
| 504 |
18 |
| LEAVE; |
| 505 |
|
| |
| 506 |
18 |
| ENTER; |
| 507 |
18 |
| SAVETMPS; |
| 508 |
18 |
▶ | PUSHMARK( SP ); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK( SP ); |
0 |
18 |
18 |
|
| 509 |
18 |
▶ | XPUSHs( image ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( image ); |
0 |
18 |
18 |
|
| 510 |
18 |
▶ | XPUSHs( sv_2mortal( newSViv( height ) ) ); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs( sv_2mortal( newSViv( height ) ) ); |
0 |
18 |
18 |
|
| 511 |
18 |
| PUTBACK; |
| 512 |
18 |
| call_method( "height", G_DISCARD | G_VOID ); |
| 513 |
18 |
| SPAGAIN; |
| 514 |
18 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
18 |
0 |
18 |
|
| 515 |
18 |
| LEAVE; |
| 516 |
|
| |
| 517 |
18 |
| RETVAL = SvREFCNT_inc( image ); |
| 518 |
|
| OUTPUT: |
| 519 |
|
| RETVAL |