int starcrus_collision_check_s1s2(void) { int org_x, org_y; int sx, sy; struct rectangle clip; clip.min_x=0; clip.max_x=15; clip.min_y=0; clip.max_y=15; fillbitmap(ship1_vid,Machine->pens[0],&clip); fillbitmap(ship2_vid,Machine->pens[0],&clip); /* origin is with respect to ship1 */ org_x = s1_x; org_y = s1_y; /* Draw ship 1 */ drawgfx(ship1_vid, Machine->gfx[8+((s1_sprite&0x04)>>2)], (s1_sprite&0x03)^0x03, 0, (s1_sprite&0x08)>>3,(s1_sprite&0x10)>>4, s1_x-org_x,s1_y-org_y, &clip, TRANSPARENCY_NONE, 0); /* Draw ship 2 */ drawgfx(ship2_vid, Machine->gfx[10+((s2_sprite&0x04)>>2)], (s2_sprite&0x03)^0x03, 0, (s2_sprite&0x08)>>3,(s2_sprite&0x10)>>4, s2_x-org_x,s2_y-org_y, &clip, TRANSPARENCY_NONE, 0); /* Now check for collisions */ for (sy=0;sy<16;sy++) { for (sx=0;sx<16;sx++) { if (read_pixel(ship1_vid, sx, sy)==Machine->pens[1]) { /* Condition 1 - ship 1 = ship 2 */ if (read_pixel(ship2_vid, sx, sy)==Machine->pens[1]) return 1; } } } return 0; }
static int collision_check( mame_bitmap *bitmap, int which ) { int bgcolor = Machine->pens[0]; int sprite_transp = Machine->pens[0x24]; const rectangle *clip = &Machine->visible_area; int y0 = 240-grchamp_player_ypos; int x0 = 256-grchamp_player_xpos; int x,y,sx,sy; int pixel; int result = 0; if( which==0 ) { /* draw the current player sprite into a work bitmap */ drawgfx( work_bitmap, Machine->gfx[2], grchamp_tile_number&0xf, 1, /* color */ 0,0, 0,0, 0, TRANSPARENCY_NONE, 0 ); } for( y = 0; y <32; y++ ) { for( x = 0; x<32; x++ ) { pixel = read_pixel(work_bitmap,x,y); if( pixel != sprite_transp ){ sx = x+x0; sy = y+y0; if( (sx >= clip->min_x) && (sx <= clip->max_x) && (sy >= clip->min_y) && (sy <= clip->max_y) ) { /* Collision check uses only 16 pens! */ pixel = read_pixel(bitmap, sx, sy) % 16; if( pixel != bgcolor ) { result = 1; /* flag collision */ /* wipe this pixel, so collision checks with the ** next layer work */ plot_pixel( bitmap, sx, sy, bgcolor ); } } } } } return result?(1<<which):0; }
static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) { SkBitmap store; SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF)); SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get())); canvas->clear(0x00000000); // verify that the clear() was deferred REPORTER_ASSERT(reporter, 0xFFFFFFFF == read_pixel(surface, 0, 0)); SkBitmap accessed = canvas->getDevice()->accessBitmap(false); // verify that clear was executed REPORTER_ASSERT(reporter, 0 == read_pixel(surface, 0, 0)); }
int bmp_read_raw(FILE *f, BITMAPINFOHEADER *bmp, RGBA **buffer) { #define MXT_ABS(v) ((v)<0?-(v):(v)) DWORD w = MXT_ABS(bmp->width); DWORD h = MXT_ABS(bmp->height); RGBA *buf = NULL; RGBA *img = NULL; int x, y; int dx = bmp->width < 0 ? -1 : 1; int dy = bmp->height < 0 ? -1 : 1; #undef MXT_ABS if((x = read_raw_buffer(f, &buf, bmp->bpp, bmp->data_length, w, h))) return x; img = malloc(w * h * sizeof(RGBA)); #define MXT_MAX(a,b) ((a)>(b)?(a):(b)) for(y = MXT_MAX(1, bmp->height) - 1 ; y != MXT_MAX(-1, -bmp->height) ; y -= dy) { for(x = MXT_MAX(1, -bmp->width) - 1 ; x != MXT_MAX(-1, bmp->width) ; x += dx) { buf += read_pixel(buf, bmp->bpp, img + (x + y * w)); } } #undef MXT_MAX *buffer = img; free(buf); return BMP_ERR_NO; }
int main() { /* Provides a user interface for the fill algorithm. */ char filename[BUFSIZ] ; int x, y, old_color, new_color ; printf( "Enter image file name. " ) ; scanf( "%s", filename ) ; if( init_image( filename ) == - 1 ) { printf( "Error initializing the image.\n" ) ; exit( 1 ) ; } while( TRUE ) { display_image() ; printf( "Enter the point at which the fill should start ( x, y ) : " ) ; scanf( "%d, %d", &x, &y ) ; if( ( x == -1 ) && ( y == -1 ) ) break ; old_color = read_pixel( x, y ) ; do { printf( "Pixel color is %d. Enter the new color: ", old_color ) ; scanf( "%d", &new_color ) ; } while( old_color == new_color || new_color < 0 || new_color > 9 ) ; fill( x, y, old_color, new_color ) ; } printf( "All done.\n" ) ; return 0 ; }
void CanvasX11::update() { Options::FrameEnd m = Options::frame_end; if (m == Options::FrameEndDefault) { if (offscreen_) m = Options::FrameEndFinish; else m = Options::FrameEndSwap; } switch(m) { case Options::FrameEndSwap: swap_buffers(); break; case Options::FrameEndFinish: glFinish(); break; case Options::FrameEndReadPixels: read_pixel(width_ / 2, height_ / 2); break; case Options::FrameEndNone: default: break; } }
static void draw_headlights( struct mame_bitmap *bitmap, const struct rectangle *cliprect, int bFog ) { int sx, sy, color; int x0 = 256-grchamp_player_xpos-64; int y0 = 240-grchamp_player_ypos-64; const UINT8 *source = memory_region( REGION_GFX4 ); int x,y,bit; if( !bFog ) source += 0x400; for( y=0; y<128; y++ ) { for( x=0; x<64; x+=8 ) { int data = *source++; if( data ) { for( bit=0; bit<8; bit++ ) { if( data&0x80 ){ sx = x0+x+bit; sy = y0+y; if( sx>=cliprect->min_x && sy>=cliprect->min_y && sx<=cliprect->max_x && sy<=cliprect->max_y ) { color = read_pixel( headlight_bitmap, x+bit, y ); plot_pixel( bitmap, sx,sy, color ); } } data <<= 1; } } } } }
static UINT8 collision_check(rectangle* rect) { UINT8 data = 0; int x; int y; for (y = rect->min_y; y <= rect->max_y; y++) { for (x = rect->min_x; x <= rect->max_x; x++) { pen_t a = read_pixel(helper, x, y); if (a == 0) { data |= 0x40; } if (a == 3) { data |= 0x80; } } } return data; }
static int zapper_hit_pixel(const UINT32 *input) { UINT16 pix; UINT8 r, g, b; pix = read_pixel(Machine->scrbitmap, input[1], input[2]); palette_get_color(pix, &r, &g, &b); return (((UINT16) r) + ((UINT16) g) + ((UINT16) b)) >= 240*3; }
static void draw_fog( mame_bitmap *bitmap, const rectangle *cliprect, int fog ){ int x,y,pen,offs; /* Emulation of analog fog effect */ for(x=0;x<100;x++) { offs = 0x40; if(x > (100-FOG_SIZE-1)) offs = 0x40*(x-(100-FOG_SIZE-1)); for(y=16;y<240;y++) { pen = read_pixel(bitmap, x, y); plot_pixel(bitmap,x, y, pen + offs); } } }
static void draw_stars( mame_bitmap *bitmap, const rectangle *cliprect ) { if (1) { int bpen,star_cntr; int set_a, set_b; /* two sets of stars controlled by these bits */ set_a = bosco_starblink[0]; set_b = bosco_starblink[1] |0x2; bpen = Machine->pens[0x1f]; for (star_cntr = 0;star_cntr < MAX_STARS;star_cntr++) { int x,y; if ( (set_a == star_seed_tab[star_cntr].set) || ( set_b == star_seed_tab[star_cntr].set) ) { x = ( star_seed_tab[star_cntr].x + stars_scrollx) % 256; y = ( star_seed_tab[star_cntr].y + stars_scrolly) % 256; /* dont draw the stars that are off the screen */ if ( x < 224 && y < 224 ) { if (flip_screen) x += 64; if (y >= Machine->screen[0].visarea.min_y && y <= Machine->screen[0].visarea.max_y) { if (read_pixel(bitmap, x, y) == bpen) plot_pixel(bitmap, x, y, STARS_COLOR_BASE + star_seed_tab[star_cntr].col ); } } } } } }
static void draw_stars( mame_bitmap *bitmap, const rectangle *cliprect ) { /* draw the stars */ /* $a005 controls the stars ON/OFF */ if ( galaga_starcontrol[5] == 1 ) { int bpen, star_cntr; int set_a, set_b; bpen = Machine->pens[0x1f]; /* two sets of stars controlled by these bits */ set_a = galaga_starcontrol[3]; set_b = galaga_starcontrol[4] | 0x2; for (star_cntr = 0;star_cntr < MAX_STARS ;star_cntr++) { int x,y; if ( (set_a == star_seed_tab[star_cntr].set) || ( set_b == star_seed_tab[star_cntr].set) ) { x = (star_seed_tab[star_cntr].x + stars_scrollx) % 256 + 16; y = (112 + star_seed_tab[star_cntr].y + stars_scrolly) % 256; /* 112 is a tweak to get alignment about perfect */ if (y >= Machine->visible_area.min_y && y <= Machine->visible_area.max_y) { if (read_pixel(bitmap, x, y) == bpen) plot_pixel(bitmap, x, y, STARS_COLOR_BASE + star_seed_tab[ star_cntr ].col); } } } } }
static void chaknpop_draw_bitmap(mame_bitmap *bitmap) { int dx = flip_x ? -1 : 1; int offs, i; for (offs = 0; offs < 0x2000; offs++) { int x = ((offs & 0x1f) << 3) + 7; int y = offs >> 5; if (!flip_x) x = 255 - x; if (!flip_y) y = 255 - y; for (i = 0x80; i > 0; i >>= 1, x += dx) { pen_t color = 0; if (vram1[offs] & i) color |= 0x200; /* green lower cage */ if (vram2[offs] & i) color |= 0x080; if (vram3[offs] & i) color |= 0x100; /* green upper cage */ if (vram4[offs] & i) color |= 0x040; /* tx mask */ if (color) { pen_t pen = read_pixel(bitmap, x, y); pen |= color; plot_pixel(bitmap, x, y, pen); } } } }
void fill( int x, int y, int old_color, int new_color ) { /* Perform an interior-defined 4-connected fill. */ stack S ; if( init_stack( &S ) == ERROR ) { printf( INIT_ERR ) ; return ; } push_xy( &S, x, y ) ; while( !empty_stack( &S ) ) { pop_xy( &S, &x, &y ) ; if( read_pixel( x, y ) == old_color ) { write_pixel( x, y, new_color ) ; PUSH_XY( &S, x, ( y - 1 ) ) ; PUSH_XY( &S, x, ( y + 1 ) ) ; PUSH_XY( &S, ( x - 1 ), y ) ; PUSH_XY( &S, ( x + 1 ), y ) ; } } }
static void triplhnt_draw_sprites(mame_bitmap* bitmap, const rectangle* cliprect) { int i; int hit_line = 999; int hit_code = 999; for (i = 0; i < 16; i++) { rectangle rect; int j = (triplhnt_orga_ram[i] & 15) ^ 15; /* software sorts sprites by x and stores order in orga RAM */ int hpos = triplhnt_hpos_ram[j] ^ 255; int vpos = triplhnt_vpos_ram[j] ^ 255; int code = triplhnt_code_ram[j] ^ 255; if (hpos == 255) { continue; } /* sprite placement might be wrong */ if (triplhnt_sprite_zoom) { rect.min_x = hpos - 16; rect.min_y = 196 - vpos; rect.max_x = rect.min_x + 63; rect.max_y = rect.min_y + 63; } else { rect.min_x = hpos - 16; rect.min_y = 224 - vpos; rect.max_x = rect.min_x + 31; rect.max_y = rect.min_y + 31; } /* render sprite to auxiliary bitmap */ drawgfx(helper, Machine->gfx[triplhnt_sprite_zoom], 2 * code + triplhnt_sprite_bank, 0, code & 8, 0, rect.min_x, rect.min_y, cliprect, TRANSPARENCY_NONE, 0); if (rect.min_x < cliprect->min_x) rect.min_x = cliprect->min_x; if (rect.min_y < cliprect->min_y) rect.min_y = cliprect->min_y; if (rect.max_x > cliprect->max_x) rect.max_x = cliprect->max_x; if (rect.max_y > cliprect->max_y) rect.max_y = cliprect->max_y; /* check for collisions and copy sprite */ { int x; int y; for (x = rect.min_x; x <= rect.max_x; x++) { for (y = rect.min_y; y <= rect.max_y; y++) { pen_t a = read_pixel(helper, x, y); pen_t b = read_pixel(bitmap, x, y); if (a == 2 && b == 7) { hit_code = j; hit_line = y; } if (a != 1) { plot_pixel(bitmap, x, y, a); } } } } } if (hit_line != 999 && hit_code != 999) { timer_set(cpu_getscanlinetime(hit_line), hit_code, triplhnt_hit_callback); } }
static void draw_sprites(mame_bitmap *bitmap, const rectangle *cliprect, int sprite_priority) { UINT16 *mem1 = &tceptor_sprite_ram[0x000/2]; UINT16 *mem2 = &tceptor_sprite_ram[0x100/2]; int need_mask = 0; int i; for (i = 0; i < 0x100; i += 2) { int scalex = (mem1[1 + i] & 0xfc00) << 1; int scaley = (mem1[0 + i] & 0xfc00) << 1; int pri = 7 - ((mem1[1 + i] & 0x3c0) >> 6); if (pri == sprite_priority && scalex && scaley) { int x = mem2[1 + i] & 0x3ff; int y = 512 - (mem2[0 + i] & 0x3ff); int flipx = mem2[0 + i] & 0x4000; int flipy = mem2[0 + i] & 0x8000; int color = mem1[1 + i] & 0x3f; int gfx; int code; if (mem2[0 + i] & 0x2000) { gfx = sprite32; code = mem1[0 + i] & 0x3ff; } else { gfx = sprite16; code = mem1[0 + i] & 0x1ff; scaley *= 2; } if (is_mask_spr[color]) { if (!need_mask) { // backup previous bitmap copybitmap(temp_bitmap, bitmap, 0, 0, 0, 0, cliprect, TRANSPARENCY_NONE, 0); } need_mask = 1; } // round off scalex += 0x800; scaley += 0x800; x -= 64; y -= 78; drawgfxzoom(bitmap, Machine->gfx[gfx], code, color, flipx, flipy, x, y, cliprect, TRANSPARENCY_COLOR, SPR_TRANS_COLOR, scalex, scaley); } } /* if SPR_MASK_COLOR pen is used, restore pixels from previous bitmap */ if (need_mask) { int x, y; for (x = cliprect->min_x; x <= cliprect->max_x; x++) for (y = cliprect->min_y; y <= cliprect->max_y; y++) if (read_pixel(bitmap, x, y) == SPR_MASK_COLOR) { int color = read_pixel(temp_bitmap, x, y); // restore pixel plot_pixel(bitmap, x, y, color); } } }
void crbaloon_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh) { int offs,x,y; int bx,by; /* for every character in the Video RAM, check if it has been modified */ /* since last time and update it accordingly. */ for (offs = videoram_size - 1; offs >= 0; offs--) { if (dirtybuffer[offs]) { int sx,sy; dirtybuffer[offs] = 0; sx = offs % 32; sy = offs / 32; if (flipscreen == 0) { sx = 31 - sx; sy = 35 - sy; } drawgfx(tmpbitmap,Machine->gfx[0], videoram[offs], colorram[offs] & 0x0f, flipscreen,flipscreen, 8*sx,8*sy, &Machine->visible_area,TRANSPARENCY_NONE,0); } } /* copy the character mapped graphics */ copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0); /* Check Collision - Draw balloon in background colour, if no */ /* collision occured, bitmap will be same as tmpbitmap */ bx = spritectrl[1]; by = spritectrl[2]; drawgfx(bitmap,Machine->gfx[1], spritectrl[0] & 0x0f, 15, 0,0, bx,by, &Machine->visible_area,TRANSPARENCY_PEN,0); crbaloon_collision = 0; for (x = bx; x < bx + Machine->gfx[1]->width; x++) { for (y = by; y < by + Machine->gfx[1]->height; y++) { if ((x < Machine->visible_area.min_x) || (x > Machine->visible_area.max_x) || (y < Machine->visible_area.min_y) || (y > Machine->visible_area.max_y)) { continue; } if (read_pixel(bitmap, x, y) != read_pixel(tmpbitmap, x, y)) { crbaloon_collision = -1; break; } } } /* actually draw the balloon */ drawgfx(bitmap,Machine->gfx[1], spritectrl[0] & 0x0f, (spritectrl[0] & 0xf0) >> 4, 0,0, bx,by, &Machine->visible_area,TRANSPARENCY_PEN,0); }
static void *load_tga(FILE *fp, int *xsz, int *ysz) { struct tga_header hdr; unsigned long x, y, sz; int i; uint32_t *pix, ppixel = 0; int rle_mode = 0, rle_pix_left = 0; int rdalpha; /* read header */ fseek(fp, 0, SEEK_SET); hdr.idlen = fgetc(fp); hdr.cmap_type = fgetc(fp); hdr.img_type = fgetc(fp); hdr.cmap_first = read_int16_le(fp); hdr.cmap_len = read_int16_le(fp); hdr.cmap_entry_sz = fgetc(fp); hdr.img_x = read_int16_le(fp); hdr.img_y = read_int16_le(fp); hdr.img_width = read_int16_le(fp); hdr.img_height = read_int16_le(fp); hdr.img_bpp = fgetc(fp); hdr.img_desc = fgetc(fp); if(feof(fp)) { return 0; } /* only read true color images */ if(!IS_RGBA(hdr.img_type)) { fprintf(stderr, "only true color tga images supported\n"); return 0; } fseek(fp, hdr.idlen, SEEK_CUR); /* skip the image ID */ /* skip the color map if it exists */ if(hdr.cmap_type == 1) { fseek(fp, hdr.cmap_len * hdr.cmap_entry_sz / 8, SEEK_CUR); } x = hdr.img_width; y = hdr.img_height; sz = x * y; if(!(pix = malloc(sz * 4))) { return 0; } rdalpha = hdr.img_desc & 0xf; for(i=0; i<y; i++) { uint32_t *ptr; int j; ptr = pix + ((hdr.img_desc & 0x20) ? i : y-(i+1)) * x; for(j=0; j<x; j++) { /* if the image is raw, then just read the next pixel */ if(!IS_RLE(hdr.img_type)) { ppixel = read_pixel(fp, rdalpha); } else { /* otherwise, for RLE... */ /* if we have pixels left in the packet ... */ if(rle_pix_left) { /* if it's a raw packet, read the next pixel, otherwise keep the same */ if(!rle_mode) { ppixel = read_pixel(fp, rdalpha); } rle_pix_left--; } else { /* read the RLE packet header */ unsigned char packet_hdr = getc(fp); rle_mode = (packet_hdr & 128); /* last bit shows the mode for this packet (1: rle, 0: raw) */ rle_pix_left = (packet_hdr & ~128); /* the rest gives the count of pixels minus one (we also read one here, so no +1) */ ppixel = read_pixel(fp, rdalpha); /* and read the first pixel of the packet */ } } *ptr++ = ppixel; if(feof(fp)) break; } } *xsz = x; *ysz = y; return pix; }