ALLEGRO_COLOR selection_palette (ALLEGRO_COLOR c) { unsigned char r, g, b, a; al_unmap_rgba (c, &r, &g, &b, &a); if (a == 0) return c; signed char d; if (vm == CGA && ! hgc) d = -128; else if (vm == CGA && hgc && em == DUNGEON) d = -96; else if (vm == VGA && em == PALACE) d = +32; else d = +64; r = add_char (r, d); g = add_char (g, d); b = add_char (b, d); return al_map_rgb (r, g, b); }
void pp2_intro_setup(void) { int i, j, r; ALLEGRO_COLOR color; unsigned char cr, cg, cb, ca; /* find all pixels */ for(i = 0; i < 40; i++) { for(j = 0; j < 40; j++) { color = al_get_pixel(pp2_bitmap[PP2_BITMAP_T3_LOGO_MEMORY], j * 10 + 5, i * 10 + 5); al_unmap_rgba(color, &cr, &cg, &cb, &ca); if(ca == 255) { pp2_intro_pixel[pp2_intro_pixels].x = j * 10 + 120; pp2_intro_pixel[pp2_intro_pixels].y = i * 10 + 40; pp2_intro_pixel[pp2_intro_pixels].color = color; pp2_intro_pixel_list[pp2_intro_pixel_list_size] = pp2_intro_pixels; pp2_intro_pixel_list_size++; pp2_intro_pixels++; } } } /* place pixels */ for(i = 0; i < pp2_intro_pixels; i++) { r = rand() % pp2_intro_pixel_list_size; pp2_intro_pixel[pp2_intro_pixel_list[r]].vz = 5.0 + (i * 0.05); pp2_intro_pixel[pp2_intro_pixel_list[r]].z = 0.0; for(j = 0; j < 120 + i / 10; j++) { pp2_intro_pixel[pp2_intro_pixel_list[r]].z -= pp2_intro_pixel[pp2_intro_pixel_list[r]].vz; } for(j = r; j < pp2_intro_pixel_list_size - 1; j++) { pp2_intro_pixel_list[j] = pp2_intro_pixel_list[j + 1]; } pp2_intro_pixel_list_size--; } qsort(pp2_intro_pixel, pp2_intro_pixels, sizeof(PP2_INTRO_PIXEL), pixel_sorter); }
/* get_dib_from_bitmap_32: * Creates a Windows device-independent bitmap (DIB) from an Allegro BITMAP. * You have to free the memory allocated by this function. * * This version always creates a 32-bit DIB. */ static BYTE *get_dib_from_bitmap_32(ALLEGRO_BITMAP *bitmap) { int w, h; int x, y; int pitch; BYTE *pixels; BYTE *dst; w = al_get_bitmap_width(bitmap); h = al_get_bitmap_height(bitmap); pitch = w * 4; pixels = (BYTE *) al_malloc(h * pitch); if (!pixels) return NULL; for (y = 0; y < h; y++) { dst = pixels + y * pitch; for (x = 0; x < w; x++) { ALLEGRO_COLOR col; unsigned char r, g, b, a; col = al_get_pixel(bitmap, x, y); al_unmap_rgba(col, &r, &g, &b, &a); /* BGR */ dst[0] = b; dst[1] = g; dst[2] = r; dst[3] = a; dst += 4; } } return pixels; }
static ALLEGRO_COLOR e_dark_red_palette (ALLEGRO_COLOR c) { /* honor transparency */ unsigned char r, g, b, a; al_unmap_rgba (c, &r, &g, &b, &a); if (a == 0) return c; /* KID */ if (color_eq (c, E_KID_CLOTHES_COLOR_01)) return E_KID_SHADOW_CLOTHES_COLOR_01; if (color_eq (c, E_KID_CLOTHES_COLOR_02)) return E_KID_SHADOW_CLOTHES_COLOR_02; if (color_eq (c, E_KID_SKIN_COLOR)) return E_KID_SHADOW_SKIN_COLOR; if (color_eq (c, E_KID_HAIR_COLOR)) return E_KID_SHADOW_HAIR_COLOR; if (color_eq (c, E_KID_EYE_COLOR)) return E_KID_SHADOW_EYE_COLOR; /* SKELETON */ if (color_eq (c, SKELETON_COLOR)) return E_SKELETON_COLOR; /* GUARD, FAT_GUARD, VIZIER */ if (color_eq (c, GUARD_SHOES_COLOR)) return E_DARK_RED_GUARD_SHOES_COLOR; if (color_eq (c, GUARD_PANTS_COLOR_01)) return E_DARK_RED_GUARD_PANTS_COLOR_01; if (color_eq (c, GUARD_PANTS_COLOR_02)) return E_DARK_RED_GUARD_PANTS_COLOR_02; if (color_eq (c, GUARD_CAPE_COLOR_01)) return E_DARK_RED_GUARD_CAPE_COLOR_01; if (color_eq (c, GUARD_CAPE_COLOR_02)) return E_DARK_RED_GUARD_CAPE_COLOR_02; if (color_eq (c, GUARD_CAPE_COLOR_03)) return E_DARK_RED_GUARD_CAPE_COLOR_03; if (color_eq (c, GUARD_BELT_COLOR)) return E_DARK_RED_GUARD_BELT_COLOR; if (color_eq (c, GUARD_HAT_COLOR_01)) return E_DARK_RED_GUARD_HAT_COLOR_01; if (color_eq (c, GUARD_HAT_COLOR_02)) return E_DARK_RED_GUARD_HAT_COLOR_02; if (color_eq (c, GUARD_SKIN_COLOR_01)) return E_DARK_RED_GUARD_SKIN_COLOR_01; if (color_eq (c, GUARD_SKIN_COLOR_02)) return E_DARK_RED_GUARD_SKIN_COLOR_02; if (color_eq (c, GUARD_EYES_COLOR)) return E_DARK_RED_GUARD_EYES_COLOR; if (color_eq (c, GUARD_CLOSED_EYES_COLOR)) return E_DARK_RED_GUARD_CLOSED_EYES_COLOR; if (color_eq (c, GUARD_BLOOD_COLOR)) return E_DARK_RED_GUARD_BLOOD_COLOR; if (color_eq (c, GUARD_SPLASH_COLOR)) return E_DARK_RED_GUARD_SPLASH_COLOR; return c; }
BUTTONPTR create_new_button(char *label, char *bimage_label, char *text, ALLEGRO_FONT *font, ALLEGRO_COLOR text_color, ALLEGRO_COLOR button_color, float x, float y, float limit, CBANIMATIONS aflags, BPROPERTIES bflags, _Bool add_to_list) { BUTTONPTR newptr; BIMAGESPTR bcurrentptr = search_button_image_list_for_element(bitoptr, bimage_label); unsigned char r, g, b, a; if((newptr = (BUTTONPTR)malloc(sizeof(BUTTON))) == NULL) return NULL; newptr->blabel = label; newptr->bimage = bcurrentptr; newptr->btext.text = text; newptr->btext.text_f = font; newptr->btext.text_c = text_color; newptr->bdata.x = x; newptr->bdata.y = y; newptr->bdata.ox = x; newptr->bdata.oy = y; newptr->bdata.limit = limit; newptr->bdata.b_color = button_color; newptr->bdata.sflags = 0; newptr->bdata.aflags = aflags; newptr->bdata.bflags = bflags; al_unmap_rgba(newptr->bdata.b_color, &r, &g, &b, &a); newptr->bdata.alpha = a; if(add_to_list) add_element_to_button_list(&newptr); return newptr; }
Color::Color(ALLEGRO_COLOR color) { al_unmap_rgba(color, &r, &g, &b, &a); }
/* [gtk thread] */ static GtkWidget *build_menu_item(ALLEGRO_MENU_ITEM *aitem) { GtkWidget *gitem; if (!aitem->caption) { gitem = gtk_separator_menu_item_new(); } else { ALLEGRO_USTR *caption = al_ustr_dup(aitem->caption); /* convert & to _ using unprintable chars as placeholders */ al_ustr_find_replace_cstr(caption, 0, "_", "\x01\x02"); al_ustr_find_replace_cstr(caption, 0, "&", "_"); al_ustr_find_replace_cstr(caption, 0, "\x01\x02", "__"); if (aitem->flags & ALLEGRO_MENU_ITEM_CHECKBOX) { gitem = gtk_check_menu_item_new_with_mnemonic(al_cstr(caption)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gitem), aitem->flags & ALLEGRO_MENU_ITEM_CHECKED); g_signal_connect_swapped (gitem, "toggled", G_CALLBACK(checkbox_on_toggle), (gpointer) aitem); } else { /* always create an image menu item, in case the user ever sets an icon */ gitem = gtk_image_menu_item_new_with_mnemonic(al_cstr(caption)); if (aitem->icon) { const int w = al_get_bitmap_width(aitem->icon), h = al_get_bitmap_height(aitem->icon); const int stride = w * 4; int x, y, i; GdkPixbuf *pixbuf; uint8_t *data = al_malloc(stride * h); if (data) { for (y = 0, i = 0; y < h; ++y) { for (x = 0; x < w; ++x, i += 4) { al_unmap_rgba(al_get_pixel(aitem->icon, x, y), &data[i], &data[i + 1], &data[i + 2], &data[i + 3] ); } } pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, TRUE, 8, w, h, stride, destroy_pixbuf, NULL); aitem->extra2 = gtk_image_new_from_pixbuf(pixbuf); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gitem), aitem->extra2); /* Subtract the main reference. the image still holds a reference, so the * pixbuf won't be destroyed until the image itself is. */ g_object_unref(pixbuf); } } } al_ustr_free(caption); gtk_widget_set_sensitive(gitem, !(aitem->flags & ALLEGRO_MENU_ITEM_DISABLED)); aitem->extra1 = gitem; if (aitem->popup) { GtkWidget *gsubmenu = gtk_menu_new(); build_menu(gsubmenu, aitem->popup); aitem->popup->extra1 = gsubmenu; gtk_widget_show(gsubmenu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(gitem), gsubmenu); } else if (aitem->id) { g_signal_connect_swapped (gitem, "activate", G_CALLBACK(menuitem_response), (gpointer) aitem); } } gtk_widget_show(gitem); return gitem; }
static bool init_nine_patch_side(NINE_PATCH_SIDE *ps, ALLEGRO_BITMAP *bmp, int vertical) { const int len = vertical ? al_get_bitmap_height(bmp) : al_get_bitmap_width(bmp); int i, s, t, n, z; ALLEGRO_COLOR c; int alloc = 8; ps->m = al_malloc(alloc * sizeof(*ps->m)); for (i = 1, s = -1, t = 0, n = 0, z = -1; i < len; ++i) { int zz; uint8_t r, g, b, a; c = vertical ? al_get_pixel(bmp, 0, i) : al_get_pixel(bmp, i, 0); al_unmap_rgba(c, &r, &g, &b, &a); if (i == len - 1) zz = -1; else if (r == 0 && g == 0 && b == 0 && a == 255) zz = 0; else if (a == 0 || r + g + b + a == 255 * 4) zz = 1; else return false; if (z != zz) { if (s != -1) { ps->m[n].offset = s; ps->m[n].length = i - s; if (z == 0) { ps->m[n].ratio = 1; t += ps->m[n].length; } else { ps->m[n].ratio = 0; } ++n; } s = i; z = zz; } if (n == alloc) { alloc *= 2; ps->m = al_realloc(ps->m, alloc * sizeof(*ps->m)); } } if (n != alloc) { ps->m = al_realloc(ps->m, n * sizeof(*ps->m)); } ps->count = n; ps->fix = len - 2 - t; for (i = 0; i < n; ++i) { if (ps->m[i].ratio) ps->m[i].ratio = ps->m[i].length / (float) t; } return true; }
/** assignment from allegro color. @param color color. @return reference to this. */ Color &operator = (const ALLEGRO_COLOR &color) { al_unmap_rgba(color, &m_color.m_red, &m_color.m_green, &m_color.m_blue, &m_color.m_alpha); return *this; }
int main(int argc, char **argv) { al_init(); al_init_image_addon(); al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP | ALLEGRO_NO_PREMULTIPLIED_ALPHA); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); ALLEGRO_BITMAP *tilemap = al_load_bitmap(argv[1]); ALLEGRO_BITMAP *result = al_create_bitmap(1024, 1024); al_set_target_bitmap(result); al_clear_to_color(al_map_rgba(0, 0, 0, 0)); int tx = 0, ty = 0; int mx = 0, my = 0; int mapping[(512/16)*(2048/16)]; memset(mapping, 0, sizeof(mapping)); int i = 0; mapping[i++] = 0; mx = 16; for (int y = 0; y < 2048/16; y++) { int x; if (y == 0) x = 1; else x = 0; for (; x < 512/16; x++) { // 1 == skip first alpha img int ox = x * 16; int oy = y * 16; bool all_alpha = true; // FIXME: tile index 96 is all alpha and still in the packed.png. keep for legacy reasons. if (i == 96) { all_alpha = false; } else { for (int py = 0; py < 16; py++) { for (int px = 0; px < 16; px++) { ALLEGRO_COLOR pix = al_get_pixel(tilemap, px+ox, py+oy); unsigned char r, g, b, a; al_unmap_rgba(pix, &r, &g, &b, &a); if (!(a == 0)) { all_alpha = false; break; } } if (!all_alpha) break; } } if (!all_alpha) { mapping[(y*32)+x] = i++; if (ox == 0 && oy == (3*16)) { } else { al_draw_bitmap_region(tilemap, ox, oy, 16, 16, mx, my, 0); } mx += 16; if (mx == 1024) { mx = 0; my += 16; } } } } printf("int mapping[4096] = {\n\t"); for (int i = 0; i < 4096; i++) { if ((i % 10) == 0) printf(",\n\t"); else printf(", "); printf("%4d", mapping[i]); } printf("\n};\n"); al_save_bitmap("packed.png", result); }
BUTTONPTR standard_button_animations(BUTTONPTR button) { const int dx = 1, dy = 1, limit = 20; unsigned char r, g, b, a; al_unmap_rgba(button->bdata.b_color, &r, &g, &b, &a); if((button->bdata.bflags & BMOUSEOVER)) { button->bdata.b_color = BCOLOR(r, g, b, 255); switch(sb) { default: case SBLEFT: case SBRIGHT: case SBUP: case SBDOWN: case SBNONE: break; case BBOUNCEHORZ: { if(button->bdata.sflags == SBRIGHT) button->bdata.x += dx; else if(button->bdata.sflags == SBLEFT) button->bdata.x -= dx; if(button->bdata.x >= button->bdata.ox+limit) button->bdata.sflags = SBLEFT; if(button->bdata.x <= button->bdata.ox-limit) button->bdata.sflags = SBRIGHT; if(button->bdata.sflags == 0) button->bdata.sflags = SBRIGHT; } break; case BSHIFTRIGHT: { if(button->bdata.x < button->bdata.ox+limit) button->bdata.x += 1; } break; case BSHIFTLEFT: { if(button->bdata.x > button->bdata.ox-limit) button->bdata.x -= 1; } break; case BBOUNCEVERT: { if(button->bdata.sflags == SBDOWN) button->bdata.y += dy; else if(button->bdata.sflags == SBUP) button->bdata.y -= dy; if(button->bdata.y >= button->bdata.oy+limit) button->bdata.sflags = SBUP; if(button->bdata.y <= button->bdata.oy-limit) button->bdata.sflags = SBDOWN; if(button->bdata.sflags == 0) button->bdata.sflags = SBDOWN; } } } else { button->bdata.b_color = BCOLOR(r, g, b, button->bdata.alpha); button->bdata.sflags = 0; if(button->bdata.x > button->bdata.ox) button->bdata.x -= 1; if(button->bdata.x < button->bdata.ox) button->bdata.x += 1; if(button->bdata.y > button->bdata.oy) button->bdata.y -= 1; if(button->bdata.y < button->bdata.oy) button->bdata.y += 1; } return button; }
HICON _al_win_create_icon(HWND wnd, ALLEGRO_BITMAP *sprite, int xfocus, int yfocus, bool is_cursor, bool resize) { int x, y; int sys_sm_cx, sys_sm_cy; HDC h_dc; HDC h_and_dc; HDC h_xor_dc; ICONINFO iconinfo; HBITMAP and_mask; HBITMAP xor_mask; HBITMAP hOldAndMaskBitmap; HBITMAP hOldXorMaskBitmap; HICON icon; if (resize) { if (is_cursor) { /* Get allowed cursor size - Windows can't make cursors of arbitrary size */ sys_sm_cx = GetSystemMetrics(SM_CXCURSOR); sys_sm_cy = GetSystemMetrics(SM_CYCURSOR); } else { sys_sm_cx = GetSystemMetrics(SM_CXICON); sys_sm_cy = GetSystemMetrics(SM_CYICON); } if ((sprite->w > sys_sm_cx) || (sprite->h > sys_sm_cy)) { return NULL; } } else { sys_sm_cx = al_get_bitmap_width(sprite); sys_sm_cy = al_get_bitmap_height(sprite); } /* Create bitmap */ h_dc = GetDC(wnd); h_xor_dc = CreateCompatibleDC(h_dc); h_and_dc = CreateCompatibleDC(h_dc); /* Prepare AND (monochrome) and XOR (colour) mask */ and_mask = CreateBitmap(sys_sm_cx, sys_sm_cy, 1, 1, NULL); xor_mask = CreateCompatibleBitmap(h_dc, sys_sm_cx, sys_sm_cy); hOldAndMaskBitmap = (HBITMAP) SelectObject(h_and_dc, and_mask); hOldXorMaskBitmap = (HBITMAP) SelectObject(h_xor_dc, xor_mask); /* Create transparent cursor */ for (y = 0; y < sys_sm_cy; y++) { for (x = 0; x < sys_sm_cx; x++) { SetPixel(h_and_dc, x, y, WINDOWS_RGB(255, 255, 255)); SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0)); } } local_draw_to_hdc(h_xor_dc, sprite, 0, 0); /* Make cursor background transparent */ for (y = 0; y < sprite->h; y++) { for (x = 0; x < sprite->w; x++) { ALLEGRO_COLOR c; unsigned char r, g, b, a; c = al_get_pixel(sprite, x, y); al_unmap_rgba(c, &r, &g, &b, &a); if (a != 0) { /* Don't touch XOR value */ SetPixel(h_and_dc, x, y, 0); } else { /* No need to touch AND value */ SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0)); } } } SelectObject(h_and_dc, hOldAndMaskBitmap); SelectObject(h_xor_dc, hOldXorMaskBitmap); DeleteDC(h_and_dc); DeleteDC(h_xor_dc); ReleaseDC(wnd, h_dc); iconinfo.fIcon = is_cursor ? false : true; iconinfo.xHotspot = xfocus; iconinfo.yHotspot = yfocus; iconinfo.hbmMask = and_mask; iconinfo.hbmColor = xor_mask; icon = CreateIconIndirect(&iconinfo); DeleteObject(and_mask); DeleteObject(xor_mask); return icon; }