VECBITMAP<unsigned char> *bitmap_to_patches(Params *p, BITMAP *a) { //int n = -1, d = -1; //unsigned char *data = im2patches_ub(a, p->patch_w, n, d); //VECBITMAP<unsigned char> *ans = new VECBITMAP<unsigned char>(); //ans->w = a->w; //ans->h = a->h; //ans->n = d; //ans->data = data; if (p->vec_len != p->patch_w*p->patch_w*3) { fprintf(stderr, "vec_len (%d) != 3*patch_w**2 (%d)\n", p->vec_len, p->patch_w*p->patch_w*3); exit(1); } VECBITMAP<unsigned char> *ans = new VECBITMAP<unsigned char>(a->w, a->h, p->vec_len); unsigned char *ptr = ans->data; for (int y = 0; y < a->h; y++) { for (int x = 0; x < a->w; x++) { for (int dy = 0; dy < p->patch_w; dy++) { for (int dx = 0; dx < p->patch_w; dx++) { int xp = x+dx, yp = y+dy; if (xp >= a->w) { xp = a->w - 1; } if (yp >= a->h) { yp = a->h - 1; } int c = _getpixel32(a, xp, yp); *ptr++ = getr32(c); *ptr++ = getg32(c); *ptr++ = getb32(c); } } } } int npatches = ptr - ans->data; int n = a->w * a->h * p->vec_len; if (n != npatches) { fprintf(stderr, "n != npatches (%d != %d)\n", n, npatches); exit(1); } return ans; }
bool Blotter::cut_into_list(BITMAP* shapebit) { for (int y = 0; y < shapebit->h; ++y) for (int x = 0; x < shapebit->w; ++x) { if (getpixel(shapebit, x, y) != pink) { Area area(shapebit); find_connected_area(area, x, y); BITMAP* piece = create_bitmap(area.x_max - area.x_min + 1, area.y_max - area.y_min + 1); if (!piece || piece->w <= 0 || piece->h <= 0) { if (piece) destroy_bitmap(piece); return false; } clear_to_color(piece, pink); for (std::set <Xy> ::const_iterator itr = area.Xy.begin(); itr != area.Xy.end(); ++itr) { _putpixel32(piece, itr->first - area.x_min, itr->second - area.y_min, _getpixel32(area.ground, itr->first, itr->second)); } shapes.push_back(piece); fill_area_with_color(area, pink); } } return true; }
int Bitmap::GetPixel(int x, int y) const { if (x < 0 || x >= _alBitmap->w || y < 0 || y >= _alBitmap->h) { return -1; // Allegros getpixel() implementation returns -1 in this case } switch (bitmap_color_depth(_alBitmap)) { case 8: return _getpixel(_alBitmap, x, y); case 15: return _getpixel15(_alBitmap, x, y); case 16: return _getpixel16(_alBitmap, x, y); case 24: return _getpixel24(_alBitmap, x, y); case 32: return _getpixel32(_alBitmap, x, y); } assert(0); // this should not normally happen return getpixel(_alBitmap, x, y); }
inline OL_LIB_DECLSPEC int OlGetAlpha( OL_MEMORY_IMG *bitmap, int x, int y ) { return geta32( _getpixel32( bitmap, x, y )); }