/* Function: al_clone_bitmap */ ALLEGRO_BITMAP *al_clone_bitmap(ALLEGRO_BITMAP *bitmap) { ALLEGRO_BITMAP *clone; ALLEGRO_LOCKED_REGION *dst_region; ALLEGRO_LOCKED_REGION *src_region; ASSERT(bitmap); clone = al_create_bitmap(bitmap->w, bitmap->h); if (!clone) return NULL; if (!(src_region = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY))) return NULL; if (!(dst_region = al_lock_bitmap(clone, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY))) { al_unlock_bitmap(bitmap); return NULL; } _al_convert_bitmap_data( src_region->data, src_region->format, src_region->pitch, dst_region->data, dst_region->format, dst_region->pitch, 0, 0, 0, 0, bitmap->w, bitmap->h); al_unlock_bitmap(bitmap); al_unlock_bitmap(clone); return clone; }
ALLEGRO_BITMAP* ImageManager::Scaler_PixelPerfect( ALLEGRO_BITMAP* Source, int ScaleSize ) { uint32_t pixelData; int imgW = al_get_bitmap_width( Source ); int imgH = al_get_bitmap_height( Source ); ALLEGRO_BITMAP* Scaled = al_create_bitmap( al_get_bitmap_width( Source ) * ScaleSize, al_get_bitmap_height( Source ) * ScaleSize ); ALLEGRO_LOCKED_REGION* rgnSrc = al_lock_bitmap( Source, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, ALLEGRO_LOCK_READONLY ); ALLEGRO_LOCKED_REGION* rgnDst = al_lock_bitmap( Scaled, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, ALLEGRO_LOCK_READWRITE ); for( int y = 0; y < imgH; y++ ) { for( int yM = 0; yM < ScaleSize; yM++ ) { int DestY = (y * ScaleSize) + yM; for( int x = 0; x < imgW; x++ ) { pixelData = ((uint32_t*)rgnSrc->data)[(y * imgW) + x]; for( int xM = 0; xM < ScaleSize; xM++ ) { ((uint32_t*)rgnDst->data)[ (DestY * (imgW * ScaleSize)) + (x * ScaleSize) + xM] = pixelData; } } } } al_unlock_bitmap( Scaled ); al_unlock_bitmap( Source ); return Scaled; }
// Colision de píxel perfecto bool PixelCol(ALLEGRO_BITMAP *player, ALLEGRO_BITMAP *enemy, float x, float y, float w, float h, float ex, float ey, float ew, float eh) { // El valor más alto entre la parte de arriba del jugador y del enemigo float top = fmax(y, ey); // El valor más bajo entre la parte de abajo del jugador y del enemigo float bottom = fmin(y + h, ey + eh); // El valor más alto entre la parte izquierda del jugador y del enemigo float left = fmax(x, ex); // El valor más bajo entre la parte derecha del jugador y del enemigo float right = fmin(x + w, ex + ew); // Hace un par de for's para revisar si hace colisión for(int i = top; i < bottom; i++) { for(int j = left; j < right; j++) { al_lock_bitmap(player, al_get_bitmap_format(player), ALLEGRO_LOCK_READONLY); al_lock_bitmap(enemy, al_get_bitmap_format(enemy), ALLEGRO_LOCK_READONLY); ALLEGRO_COLOR color = al_get_pixel(player, j - x, i - y); ALLEGRO_COLOR color2 = al_get_pixel(enemy, j - ex, i - ey); // Si el color alpha del jugador es diferente de 0 y el color alpha del enemigo es diferente de 0, // y están en la misma posición, entonces detecta una colisión if(color.a != 0 && color2.a != 0) return true; } } // Pero de lo contrario, devuelve false return false; }
static bool transfer_bitmap_data(ALLEGRO_BITMAP *src, ALLEGRO_BITMAP *dst) { ALLEGRO_LOCKED_REGION *dst_region; ALLEGRO_LOCKED_REGION *src_region; int src_format = al_get_bitmap_format(src); int dst_format = al_get_bitmap_format(dst); bool src_compressed = _al_pixel_format_is_compressed(src_format); bool dst_compressed = _al_pixel_format_is_compressed(dst_format); int copy_w = src->w; int copy_h = src->h; if (src_compressed && dst_compressed && src_format == dst_format) { int block_width = al_get_pixel_block_width(src_format); int block_height = al_get_pixel_block_height(src_format); if (!(src_region = al_lock_bitmap_blocked(src, ALLEGRO_LOCK_READONLY))) return false; if (!(dst_region = al_lock_bitmap_blocked(dst, ALLEGRO_LOCK_WRITEONLY))) { al_unlock_bitmap(src); return false; } copy_w = _al_get_least_multiple(copy_w, block_width); copy_h = _al_get_least_multiple(copy_h, block_height); ALLEGRO_DEBUG("Taking fast clone path.\n"); } else { int lock_format = ALLEGRO_PIXEL_FORMAT_ANY; /* Go through a non-compressed intermediate */ if (src_compressed && !dst_compressed) { lock_format = dst_format; } else if (!src_compressed && dst_compressed) { lock_format = src_format; } if (!(src_region = al_lock_bitmap(src, lock_format, ALLEGRO_LOCK_READONLY))) return false; if (!(dst_region = al_lock_bitmap(dst, lock_format, ALLEGRO_LOCK_WRITEONLY))) { al_unlock_bitmap(src); return false; } } _al_convert_bitmap_data( src_region->data, src_region->format, src_region->pitch, dst_region->data, dst_region->format, dst_region->pitch, 0, 0, 0, 0, copy_w, copy_h); al_unlock_bitmap(src); al_unlock_bitmap(dst); return true; }
void special_effects_update_before (void) { return; t_skin *skin = Skins_GetCurrentSkin(); al_lock_bitmap(gui_buffer, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE); al_set_target_bitmap(gui_buffer); switch (skin->effect) { // BLOOD DROPS ------------------------------------------------------------- case SKIN_EFFECT_BLOOD: for (int i = 0; i < MAX_BLOOD_DROP; i ++) { t_skinfx_particle* p = &g_skinfx_particles[i]; if (p->v && p->save.a != 0) al_put_pixel(p->x, p->y, p->save); } break; case SKIN_EFFECT_HEARTS: // Save old graphics -------------------------------------------------- const int w = al_get_bitmap_width(Graphics.Misc.Heart1); const int h = al_get_bitmap_height(Graphics.Misc.Heart1); for (int i = 0; i < MAX_HEARTS; i ++) { t_skinfx_particle* p = &g_skinfx_particles[i]; al_draw_bitmap_region(hearts_save[i], 0, 0, w, h, p->x, p->y, 0x0000); } break; } al_unlock_bitmap(gui_buffer); }
ALLEGRO_BITMAP *generate_noise_bitmap(float w, float h, float min_intensity, float max_intensity) { // set everything up ALLEGRO_BITMAP *surface = al_create_bitmap(w, h); ALLEGRO_STATE state; al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP); // set the drawing surface al_set_target_bitmap(surface); // write the (randomly colored) pixels al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ARGB_8888, ALLEGRO_LOCK_WRITEONLY); for (int x=0; x<w; x++) { for (int y=0; y<h; y++) { float val = random_float(min_intensity, max_intensity); al_put_pixel(x, y, al_map_rgba_f(val, val, val, 1.0)); } } al_unlock_bitmap(surface); // return everything back to the way it was al_restore_state(&state); // return the generated image return surface; }
ALLEGRO_BITMAP *create_pixel_pattern_4(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int x_distance, float slope) { //TODO this function is not complete, and may not return expected results when other values than the default values are given. // Further development is needed to provide this flexibility to the function, but at the default values, it returns the intended // pattern int bitmap_size_x = x_distance * 8; int bitmap_size_y = x_distance * 8; ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size_x, bitmap_size_y); ALLEGRO_STATE state; al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP); al_set_target_bitmap(surface); if (x_distance < 0) { al_restore_state(&state); return surface; } while (slope < 0) { slope += x_distance; } // clear to the back color al_clear_to_color(pixel2_color); // begin drawing the surface al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct? for (int y=0; y<bitmap_size_y; y+=1) for (int x=0; x<bitmap_size_x; x+=x_distance) { al_put_pixel(x + ((int)(y*slope))%x_distance, y, pixel1_color); } al_unlock_bitmap(surface); al_restore_state(&state); return surface; }
void bitmap_para_matriz(ALLEGRO_BITMAP *bitmap, unsigned char ***matriz){ ALLEGRO_LOCKED_REGION *region = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ARGB_8888, ALLEGRO_LOCK_READWRITE); char *row = region->data; for(int y = 0; y < altura; y++) { char *pixel = row; for(int x = 0; x < largura; x++) { matriz[y][x][0] = *pixel; pixel++; matriz[y][x][1] = *pixel; pixel++; matriz[y][x][2] = *pixel; pixel++; //Alpha matriz[y][x][3] = *pixel; pixel++; } row += region->pitch; } al_unlock_bitmap(bitmap); }
static ALLEGRO_BITMAP *create_bitmap(void) { const int checkers_size = 8; const int bitmap_size = 24; ALLEGRO_BITMAP *bitmap; ALLEGRO_LOCKED_REGION *locked; int x, y, p; unsigned char *rgba; bitmap = al_create_bitmap(bitmap_size, bitmap_size); locked = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ABGR_8888, 0); rgba = locked->data; p = locked->pitch; for (y = 0; y < bitmap_size; y++) { for (x = 0; x < bitmap_size; x++) { int c = (((x / checkers_size) + (y / checkers_size)) & 1) * 255; rgba[y * p + x * 4 + 0] = 0; rgba[y * p + x * 4 + 1] = 0; rgba[y * p + x * 4 + 2] = 0; rgba[y * p + x * 4 + 3] = c; } } al_unlock_bitmap(bitmap); return bitmap; }
static void draw_pattern(ALLEGRO_BITMAP *b) { int w = al_get_bitmap_width(b); int h = al_get_bitmap_height(b); int x, y; int format = ALLEGRO_PIXEL_FORMAT_BGR_888; ALLEGRO_COLOR light = al_map_rgb_f(1, 1, 1); ALLEGRO_COLOR dark = al_map_rgb_f(1, 0.9, 0.8); ALLEGRO_LOCKED_REGION *lock; lock = al_lock_bitmap(b, format, ALLEGRO_LOCK_WRITEONLY); for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { ALLEGRO_COLOR c = (x + y) & 1 ? light : dark; unsigned char r, g, b; unsigned char *data = lock->data; al_unmap_rgb(c, &r, &g, &b); data += y * lock->pitch; data += x * 3; data[0] = r; data[1] = g; data[2] = b; } } al_unlock_bitmap(b); }
static bool raspberrypi_set_mouse_cursor(ALLEGRO_DISPLAY *display, ALLEGRO_MOUSE_CURSOR *cursor) { ALLEGRO_DISPLAY_RASPBERRYPI *d = (void *)display; ALLEGRO_MOUSE_CURSOR_RASPBERRYPI *pi_cursor = (void *)cursor; int w = al_get_bitmap_width(pi_cursor->bitmap); int h = al_get_bitmap_height(pi_cursor->bitmap); int pitch = w * sizeof(uint32_t); uint32_t *data = al_malloc(pitch * h); ALLEGRO_LOCKED_REGION *lr = al_lock_bitmap(pi_cursor->bitmap, ALLEGRO_PIXEL_FORMAT_ARGB_8888, ALLEGRO_LOCK_READONLY); int y; for (y = 0; y < h; y++) { uint8_t *p = (uint8_t *)lr->data + lr->pitch * y; uint8_t *p2 = (uint8_t *)data + pitch * y; memcpy(p2, p, pitch); } al_unlock_bitmap(pi_cursor->bitmap); delete_cursor_data(d); set_cursor_data(d, data, w, h); al_free(data); if (cursor_added) { hide_cursor(d); show_cursor(d); } return true; }
static ALLEGRO_BITMAP *example_bitmap(int w, int h) { int i, j; float mx = w * 0.5; float my = h * 0.5; ALLEGRO_STATE state; ALLEGRO_BITMAP *pattern = al_create_bitmap(w, h); al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP); al_set_target_bitmap(pattern); al_lock_bitmap(pattern, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); for (i = 0; i < w; i++) { for (j = 0; j < h; j++) { float a = atan2(i - mx, j - my); float d = sqrt(pow(i - mx, 2) + pow(j - my, 2)); float sat = pow(1.0 - 1 / (1 + d * 0.1), 5); float hue = 3 * a * 180 / ALLEGRO_PI; hue = (hue / 360 - floorf(hue / 360)) * 360; al_put_pixel(i, j, al_color_hsv(hue, sat, 1)); } } al_put_pixel(0, 0, al_map_rgb(0, 0, 0)); al_unlock_bitmap(pattern); al_restore_state(&state); return pattern; }
/* Function: al_convert_mask_to_alpha */ void al_convert_mask_to_alpha(ALLEGRO_BITMAP *bitmap, ALLEGRO_COLOR mask_color) { ALLEGRO_LOCKED_REGION *lr; int x, y; ALLEGRO_COLOR pixel; ALLEGRO_COLOR alpha_pixel; ALLEGRO_STATE state; if (!(lr = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ANY, 0))) { ALLEGRO_ERROR("Couldn't lock bitmap."); return; } al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP); al_set_target_bitmap(bitmap); alpha_pixel = al_map_rgba(0, 0, 0, 0); for (y = 0; y < bitmap->h; y++) { for (x = 0; x < bitmap->w; x++) { pixel = al_get_pixel(bitmap, x, y); if (memcmp(&pixel, &mask_color, sizeof(ALLEGRO_COLOR)) == 0) { al_put_pixel(x, y, alpha_pixel); } } } al_unlock_bitmap(bitmap); al_restore_state(&state); }
/* Create an example bitmap. */ static ALLEGRO_BITMAP *create_example_bitmap(void) { ALLEGRO_BITMAP *bitmap; int i, j; ALLEGRO_LOCKED_REGION *locked; unsigned char *data; bitmap = al_create_bitmap(100, 100); locked = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ABGR_8888, ALLEGRO_LOCK_WRITEONLY); data = locked->data; for (j = 0; j < 100; j++) { for (i = 0; i < 100; i++) { int x = i - 50, y = j - 50; int r = sqrt(x * x + y * y); float rc = 1 - r / 50.0; if (rc < 0) rc = 0; data[i * 4 + 0] = i * 255 / 100; data[i * 4 + 1] = j * 255 / 100; data[i * 4 + 2] = rc * 255; data[i * 4 + 3] = rc * 255; } data += locked->pitch; } al_unlock_bitmap(bitmap); return bitmap; }
ALLEGRO_BITMAP * apply_palette (ALLEGRO_BITMAP *bitmap, palette p) { if (! bitmap) return NULL; ALLEGRO_BITMAP *cached = get_cached_palette (bitmap, p); if (cached) return cached; int x, y; ALLEGRO_BITMAP *rbitmap = clone_bitmap (bitmap); int w = al_get_bitmap_width (bitmap); int h = al_get_bitmap_height (bitmap); al_lock_bitmap (rbitmap, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE); set_target_bitmap (rbitmap); for (y = 0; y < h; y++) for (x = 0; x < w; x++) al_put_pixel (x, y, p (al_get_pixel (rbitmap, x, y))); al_unlock_bitmap (rbitmap); struct palette_cache pc; pc.ib = bitmap; pc.pal = p; pc.ob = rbitmap; palette_cache = add_to_array (&pc, 1, palette_cache, &palette_cache_nmemb, palette_cache_nmemb, sizeof (pc)); qsort (palette_cache, palette_cache_nmemb, sizeof (pc), compare_palette_caches); return rbitmap; }
Cursor::Cursor( Palette* ColourPalette ) { ALLEGRO_FILE* f = al_fopen( "data/TACDATA/MOUSE.DAT", "rb" ); while( images.size() < al_fsize( f ) / 576 ) { ALLEGRO_BITMAP* b = al_create_bitmap( 24, 24 ); ALLEGRO_LOCKED_REGION* r = al_lock_bitmap( b, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, 0 ); for( int y = 0; y < 24; y++ ) { for( int x = 0; x < 24; x++ ) { int palidx = al_fgetc( f ); Colour* rowptr = (Colour*)(&((char*)r->data)[ (y * r->pitch) + (x * 4) ]); Colour* palcol = ColourPalette->GetColour( palidx ); rowptr->a = palcol->a; rowptr->r = palcol->r; rowptr->g = palcol->g; rowptr->b = palcol->b; } } al_unlock_bitmap( b ); images.push_back( b ); } CurrentType = CursorType::Normal; cursorx = 0; cursory = 0; }
ALLEGRO_BITMAP *create_pixel_pattern_3(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int x_distance, int y_distance) { int bitmap_size_x = x_distance * 8; int bitmap_size_y = y_distance * 8; ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size_x, bitmap_size_y); ALLEGRO_STATE state; al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP); al_set_target_bitmap(surface); // clear to the back color al_clear_to_color(pixel2_color); // begin drawing the surface int slope = (int)(x_distance * 1.5); al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct? for (int y=0; y<bitmap_size_y; y+=y_distance) for (int x=0; x<bitmap_size_x; x+=x_distance) { al_put_pixel(x + (y*slope)%x_distance, y, pixel1_color); } al_unlock_bitmap(surface); al_restore_state(&state); return surface; }
ALLEGRO_BITMAP *create_pixel_pattern_1(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int checker_size) { int bitmap_size = 64; ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size, bitmap_size); ALLEGRO_STATE state; al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP); al_set_target_bitmap(surface); // clear to the back color al_clear_to_color(pixel2_color); // begin drawing the surface al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct? int num_rows_cols = bitmap_size / checker_size; for (int row=0; row<num_rows_cols; row++) for (int col=0; col<num_rows_cols; col++) { if ((row+col) % 2 == 1) continue; // skip if the square is even // draw a square of n x n size, at (x, y) for (int yy=0; yy<checker_size; yy++) for (int xx=0; xx<checker_size; xx++) { al_put_pixel(col*checker_size + xx, row*checker_size + yy, pixel1_color); } } al_unlock_bitmap(surface); al_restore_state(&state); return surface; }
ALLEGRO_MOUSE_CURSOR *_al_xwin_create_mouse_cursor(ALLEGRO_BITMAP *bmp, int x_focus, int y_focus) { ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver(); Display *xdisplay = system->x11display; int bmp_w; int bmp_h; ALLEGRO_MOUSE_CURSOR_XGLX *xcursor; XcursorImage *image; int c, ix, iy; bool was_locked; bmp_w = al_get_bitmap_width(bmp); bmp_h = al_get_bitmap_height(bmp); xcursor = al_malloc(sizeof *xcursor); if (!xcursor) { return NULL; } image = XcursorImageCreate(bmp->w, bmp->h); if (image == None) { al_free(xcursor); return NULL; } was_locked = al_is_bitmap_locked(bmp); if (!was_locked) { al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY); } c = 0; for (iy = 0; iy < bmp_h; iy++) { for (ix = 0; ix < bmp_w; ix++) { ALLEGRO_COLOR col; unsigned char r, g, b, a; col = al_get_pixel(bmp, ix, iy); al_unmap_rgba(col, &r, &g, &b, &a); image->pixels[c++] = (a<<24) | (r<<16) | (g<<8) | (b); } } if (!was_locked) { al_unlock_bitmap(bmp); } image->xhot = x_focus; image->yhot = y_focus; _al_mutex_lock(&system->lock); xcursor->cursor = XcursorImageLoadCursor(xdisplay, image); _al_mutex_unlock(&system->lock); XcursorImageDestroy(image); return (ALLEGRO_MOUSE_CURSOR *)xcursor; }
void draw_star (struct star *s, struct stars_bitmap *sb, enum vm vm) { al_lock_bitmap (sb->b, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE); al_set_target_bitmap (sb->b); al_put_pixel (s->x - sb->c.x, s->y - sb->c.y, get_star_color (s->color, vm)); al_unlock_bitmap (sb->b); }
void validate_bitmap_for_mingw (ALLEGRO_BITMAP *bitmap) { /* work around a bug (MinGW target), where bitmaps are loaded as black/transparent images */ al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE); al_unlock_bitmap(bitmap); }
void draw_star (struct stars *stars, int i, enum vm vm) { al_lock_bitmap (stars->b, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE); set_target_bitmap (stars->b); al_put_pixel (stars->s[i].x - stars->c.x, stars->s[i].y - stars->c.y, get_star_color (stars->s[i].color, vm)); al_unlock_bitmap (stars->b); }
ALLEGRO_BITMAP* ImageManager::GetGrayscaleImage( std::string Filename ) { ALLEGRO_BITMAP* gsImg; PackedARGB8888* gsCol; ImageCache* fc; std::string EncodedFilename; EncodedFilename.clear(); EncodedFilename.append( Filename ); EncodedFilename.append( ":GREY" ); gsImg = GetImage( EncodedFilename ); if( gsImg != 0 ) return gsImg; #ifdef PANDORA // Whilst ptitSeb looks at fixing the al_lock_bitmap function return GetImage( Filename ); #else gsImg = GetImage( Filename ); if( gsImg == 0 ) return 0; fc = (ImageCache*)malloc( sizeof(ImageCache) ); fc->Path = new std::string(EncodedFilename); fc->Image = al_load_bitmap( Filename.c_str() ); fc->LastAccess = al_get_time(); int imgW = al_get_bitmap_width( fc->Image ); int imgH = al_get_bitmap_height( fc->Image ); ALLEGRO_LOCKED_REGION* rgn = al_lock_bitmap( fc->Image, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, ALLEGRO_LOCK_READWRITE ); for( int y = 0; y < imgH; y++ ) { for( int x = 0; x < imgW; x++ ) { gsCol = &((PackedARGB8888*)rgn->data)[(y * imgW) + x]; gsCol->r = (unsigned char)(((float)gsCol->r * 0.35) + ((float)gsCol->g * 0.5) + ((float)gsCol->b * 0.15)); gsCol->g = gsCol->r; gsCol->b = gsCol->r; } } al_unlock_bitmap( fc->Image ); #endif Cached.push_front( fc ); return fc->Image; }
void m_draw_scaled_backbuffer(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, MBITMAP *dest) { ALLEGRO_BITMAP *old_target = al_get_target_bitmap(); int old_format = al_get_new_bitmap_format(); al_set_new_bitmap_format(al_get_bitmap_format(al_get_backbuffer(display))); MBITMAP *tmp = m_create_bitmap(sw, sh); int scr_w = al_get_display_width(display); int scr_h = al_get_display_height(display); if (sx+sw > scr_w) { sw = scr_w-sx; } else if (sx < 0) { sw -= sx; sx = 0; } if (sy+sh > scr_h) { sh = scr_h-sy; } else if (sy < 0) { sh -= sy; sy = 0; } #if defined ALLEGRO_RASPBERRYPI || defined ALLEGRO_IPHONE || defined ALLEGRO_ANDROID ALLEGRO_LOCKED_REGION *lr1 = al_lock_bitmap(tmp->bitmap, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); ALLEGRO_LOCKED_REGION *lr2 = al_lock_bitmap_region( al_get_backbuffer(display), sx, sy, sw, sh, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY ); int pixel_size = al_get_pixel_size(al_get_bitmap_format(al_get_backbuffer(display))); for (int y = 0; y < sh; y++) { uint8_t *d1 = (uint8_t *)lr1->data + lr1->pitch * y; uint8_t *d2 = (uint8_t *)lr2->data + lr2->pitch * y; memcpy(d1, d2, pixel_size*sw); } al_unlock_bitmap(tmp->bitmap); al_unlock_bitmap(al_get_backbuffer(display)); #else m_set_target_bitmap(tmp); al_draw_bitmap_region(al_get_backbuffer(display), sx, sy, sw, sh, 0, 0, 0); #endif m_set_target_bitmap(dest); al_draw_scaled_bitmap( tmp->bitmap, 0, 0, sw, sh, dx, dy, dw, dh, 0 ); m_destroy_bitmap(tmp); al_set_target_bitmap(old_target); al_set_new_bitmap_format(old_format); }
void draw_pattern (ALLEGRO_BITMAP *bitmap, int ox, int oy, int w, int h, ALLEGRO_COLOR color_0, ALLEGRO_COLOR color_1) { int x, y; set_target_bitmap (bitmap); al_lock_bitmap (bitmap, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE); for (y = oy; y < oy + h; y++) for (x = ox; x < ox + w; x++) al_put_pixel (x, y, (x % 2 != y % 2) ? color_0 : color_1); al_unlock_bitmap (bitmap); }
bool Imgui_ImplA5_CreateDeviceObjects() { ImGuiIO &io = ImGui::GetIO(); // Build texture unsigned char *pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); // Create texture int flags = al_get_new_bitmap_flags(); int fmt = al_get_new_bitmap_format(); al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP|ALLEGRO_MIN_LINEAR|ALLEGRO_MAG_LINEAR); al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE); ALLEGRO_BITMAP* img = al_create_bitmap(width, height); al_set_new_bitmap_flags(flags); al_set_new_bitmap_format(fmt); if (!img) return false; ALLEGRO_LOCKED_REGION *locked_img = al_lock_bitmap(img, al_get_bitmap_format(img), ALLEGRO_LOCK_WRITEONLY); if (!locked_img) { al_destroy_bitmap(img); return false; } memcpy(locked_img->data, pixels, sizeof(int)*width*height); al_unlock_bitmap(img); // Convert software texture to hardware texture. ALLEGRO_BITMAP* cloned_img = al_clone_bitmap(img); al_destroy_bitmap(img); if (!cloned_img) return false; // Store our identifier io.Fonts->TexID = (void*)cloned_img; g_Texture = cloned_img; // Cleanup (don't clear the input data if you want to append new fonts later) io.Fonts->ClearInputData(); io.Fonts->ClearTexData(); // Create an invisible mouse cursor // Because al_hide_mouse_cursor() seems to mess up with the actual inputs.. ALLEGRO_BITMAP* mouse_cursor = al_create_bitmap(8,8); g_MouseCursorInvisible = al_create_mouse_cursor(mouse_cursor, 0, 0); al_destroy_bitmap(mouse_cursor); return true; }
ALLEGRO_BITMAP * t3f_resize_bitmap(ALLEGRO_BITMAP * bp, int w, int h) { ALLEGRO_BITMAP * rbp = NULL; int start_w = al_get_bitmap_width(bp); int start_h = al_get_bitmap_height(bp); int x, y; float pixx, pixx_f, pixy, pixy_f; ALLEGRO_COLOR a, b, c, d, ab, cd, result; ALLEGRO_STATE old_state; /* don't resize if size is already correct */ if(w == start_w && h == start_h) { return al_clone_bitmap(bp); } /* scale with software filtering */ rbp = al_create_bitmap(w, h); if(!rbp) { printf("failed to create return bitmap\n"); return NULL; } al_lock_bitmap(rbp, ALLEGRO_LOCK_READWRITE, ALLEGRO_PIXEL_FORMAT_ANY); al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP); al_set_target_bitmap(rbp); for(y = 0; y < h; y++) { pixy = ((float)y / h) * ((float)start_h - 1); pixy_f = floor(pixy); for(x = 0; x < w; x++) { pixx = ((float)x / w) * ((float)start_w - 1); pixx_f = floor(pixx); a = al_get_pixel(bp, pixx_f, pixy_f); b = al_get_pixel(bp, pixx_f + 1, pixy_f); c = al_get_pixel(bp, pixx_f, pixy_f + 1); d = al_get_pixel(bp, pixx_f + 1, pixy_f + 1); ab = interpolate(a, b, pixx - pixx_f); cd = interpolate(c, d, pixx - pixx_f); result = interpolate(ab, cd, pixy - pixy_f); al_put_pixel(x, y, result); } } al_unlock_bitmap(rbp); al_restore_state(&old_state); return rbp; }
ALLEGRO_BITMAP* ImageManager::GetNegativeImage(std::string Filename) { ALLEGRO_BITMAP* gsImg; PackedARGB8888* gsCol; ImageCache* fc; std::string EncodedFilename; EncodedFilename.clear(); EncodedFilename.append( Filename ); EncodedFilename.append( ":NEG" ); #ifdef WRITE_LOG printf( "ImageManager: Loading Negative Image '%s'\n", Filename.c_str() ); #endif gsImg = GetImage( EncodedFilename ); if( gsImg != 0 ) return gsImg; gsImg = GetImage( Filename ); if( gsImg == 0 ) return 0; fc = (ImageCache*)malloc( sizeof(ImageCache) ); fc->Path = new std::string(EncodedFilename); fc->Image = al_load_bitmap( Filename.c_str() ); fc->LastAccess = al_get_time(); int imgW = al_get_bitmap_width( fc->Image ); int imgH = al_get_bitmap_height( fc->Image ); ALLEGRO_LOCKED_REGION* rgn = al_lock_bitmap( fc->Image, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, ALLEGRO_LOCK_READWRITE ); for( int y = 0; y < imgH; y++ ) { for( int x = 0; x < imgW; x++ ) { gsCol = &((PackedARGB8888*)rgn->data)[(y * imgW) + x]; gsCol->r = (unsigned char)(255 - gsCol->r); gsCol->g = (unsigned char)(255 - gsCol->g); gsCol->b = (unsigned char)(255 - gsCol->b); } } al_unlock_bitmap( fc->Image ); Cached.push_back( fc ); return fc->Image; }
void WhiteNoise(struct Game *game) { ALLEGRO_BITMAP *bitmap = al_get_target_bitmap(); al_lock_bitmap(bitmap, ALLEGRO_LOCK_WRITEONLY, 0); float val; int width, height; width = al_get_bitmap_width(bitmap); height = al_get_bitmap_height(bitmap); for (int i=0; i < width; i++) { for (int j=0; j < height; j++) { val = (float)rand()/(float)RAND_MAX; al_put_pixel(i, j, al_map_rgb_f(val, val, val)); } } al_unlock_bitmap(bitmap); }
void KinectPlayer::Render() { // if (!mPlayerPresent) { // return; // } std::vector<UserData> users; mUserTracking.GetUsers(users); if (users.empty()) { return; } al_set_target_bitmap(mBitmap); al_clear_to_color(al_map_rgb(0x00, 0x00, 0x00)); al_convert_mask_to_alpha(mBitmap, al_map_rgb(0x00, 0x00, 0x00)); xn::SceneMetaData scene_meta; mUserTracking.GetUserPixels(users[0], scene_meta); const XnRGB24Pixel* pRgbBuf = mKinect.GetImageData(); const XnLabel* pLabelBuf = scene_meta.Data(); ALLEGRO_LOCKED_REGION* lock = al_lock_bitmap(mBitmap, al_get_bitmap_format(mBitmap), ALLEGRO_LOCK_WRITEONLY); al_set_target_bitmap(mBitmap); for (int y = 0; y < mBitmapHeight; y++) { for (int x = 0; x < mBitmapWidth; x++, pLabelBuf++, pRgbBuf++) { if (*pLabelBuf == users[0].GetId()) { al_put_pixel(x, y, al_map_rgb(pRgbBuf->nRed, pRgbBuf->nGreen, pRgbBuf->nBlue)); } } } al_unlock_bitmap(mBitmap); const int screen_x_res = al_get_display_width(al_get_current_display()); const int screen_y_res = al_get_display_height(al_get_current_display()); al_set_target_bitmap(al_get_backbuffer(al_get_current_display())); al_draw_scaled_bitmap(mBitmap, 0, 0, mBitmapWidth, mBitmapHeight, GetXPos(), GetYPos(), GetWidth(), GetHeight(), 0); }