void MapGridCtrl::OnGetMapImageAsyncCompleted(const std::string& _mapname) { m_mutex.Lock(); // if mapname is empty, some error occurred in LSL::usync().GetMinimap... if (!m_async_ex.Connected() || !m_async_image.Connected() || _mapname.empty()) { m_mutex.Unlock(); return; } const wxString mapname = TowxString(_mapname); wxImage minimap(LSL::usync().GetScaledMapImage(_mapname, LSL::IMAGE_MAP_THUMB, MINIMAP_SIZE, MINIMAP_SIZE).wximage()); const int w = minimap.GetWidth(); const int h = minimap.GetHeight(); wxImage background(BorderInvariantResizeImage(m_img_background, w, h)); wxImage minimap_alpha(BorderInvariantResizeImage(m_img_minimap_alpha, w, h)); wxImage foreground(BorderInvariantResizeImage(m_img_foreground, w, h)); minimap.SetAlpha(minimap_alpha.GetAlpha(), true /* "static data" */); minimap = BlendImage(minimap, background, false); minimap = BlendImage(foreground, minimap, false); // set the minimap in all MapMaps m_maps[mapname].minimap = wxBitmap(minimap); m_maps[mapname].state = MapState_GotMinimap; if (m_async_ops_count > 0) //WTF, why is this needed? m_async_ops_count--; // never ever call a gui function here, it will crash! (in 1/100 cases) wxCommandEvent evt(REFRESH_EVENT, GetId()); evt.SetEventObject(this); wxPostEvent(this, evt); m_mutex.Unlock(); }
wxBitmap BlendBitmaps(const wxBitmap& background, const wxBitmap& overlay, const int /*dim*/) { wxImage back = background.ConvertToImage(); wxImage front = overlay.ConvertToImage(); wxImage ret = BlendImage(front, back); return wxBitmap(ret); }
MapGridCtrl::MapGridCtrl(wxWindow* parent, wxSize size, wxWindowID id) : wxPanel(parent, id, wxDefaultPosition, size, wxSIMPLE_BORDER | wxFULL_REPAINT_ON_RESIZE) , m_async_image(std::bind(&MapGridCtrl::OnGetMapImageAsyncCompleted, this, std::placeholders::_1)) , m_async_ex(std::bind(&MapGridCtrl::OnGetMapExAsyncCompleted, this, std::placeholders::_1)) , m_async_ops_count(0) , m_selection_follows_mouse(sett().GetMapSelectorFollowsMouse()) , m_size(0, 0) , m_pos(0, 0) , m_in_mouse_drag(false) , m_mouseover_map(NULL) , m_selected_map(NULL) { SetBackgroundStyle(wxBG_STYLE_CUSTOM); SetBackgroundColour(*wxLIGHT_GREY); m_img_background.Create(MINIMAP_SIZE, MINIMAP_SIZE, false /*don't clear*/); wxRect rect(0, 0, MINIMAP_SIZE, MINIMAP_SIZE); wxColour color(GetBackgroundColour()); m_img_background.SetRGB(rect, color.Red(), color.Green(), color.Blue()); m_img_minimap_alpha = charArr2wxImage(map_select_1_png, sizeof(map_select_1_png)); m_img_foreground = charArr2wxImage(map_select_2_png, sizeof(map_select_2_png)); ASSERT_EXCEPTION(m_img_minimap_alpha.HasAlpha(), _T("map_select_1_png must have an alpha channel")); ASSERT_EXCEPTION(m_img_foreground.HasAlpha(), _T("map_select_2_png must have an alpha channel")); m_img_minimap_loading = wxBitmap(BlendImage(m_img_foreground, m_img_background, false)); }
wxBitmap charArr2wxBitmapWithBlending(const unsigned char* dest, int dest_size, const unsigned char* text, int text_size) { wxImage dest_img(charArr2wxImage(dest, dest_size)); wxImage text_img(charArr2wxImage(text, text_size)); wxImage ret = BlendImage(text_img, dest_img); return wxBitmap(ret); }
LRESULT CozyCaptureWindow::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { HDC hdc = GetWindowDC(); BlendImage(); m_ResultImg.Draw(hdc, 0, 0, m_lWidth, m_lHeight); ReleaseDC(hdc); return 0; }
static bool ExportAllVisibleLayersAsImage(const char* filename, sTileset& tileset, std::vector<sLayer> layers) { if (!(layers.size() >= 1)) return false; int tile_width = tileset.GetTileWidth(); int tile_height = tileset.GetTileHeight(); int dest_image_width = 0; int dest_image_height = 0; unsigned int i; // find the size of the image we're going to create for (i = 0; i < layers.size(); i++) { if (layers[i].GetWidth() * tile_width > dest_image_width) { dest_image_width = layers[i].GetWidth() * tile_width; } if (layers[i].GetHeight() * tile_height > dest_image_height) { dest_image_height = layers[i].GetHeight() * tile_height; } } if (dest_image_width <= 0 || dest_image_height <= 0) return false; // create destination/output image CImage32 dest_image(dest_image_width, dest_image_height); if (layers.size() > 0) { // start from the bottom and work our way to the top ;) if (!LayerToImage(&dest_image, layers[0], tileset)) { return false; } } else // nothing to export return false; // we already have the first layer, now we do the rest for (i = 1; i < layers.size(); i++) { int image_width = layers[i].GetWidth() * tile_width; int image_height = layers[i].GetHeight() * tile_height; CImage32 src_image(image_width, image_height); if ( !LayerToImage(&src_image, layers[i], tileset) ) { return false; } else { // blend (dest_image, src_image) BlendImage(dest_image_width, dest_image_height, image_width, image_height, dest_image.GetPixels(), src_image.GetPixels()); } } return dest_image.Save(filename); }
/** This takes all the visible layers, and merges them into one, leaving the old layers in tact (but invisible) */ afx_msg void CLayerView::OnFlattenVisibleLayers() { unsigned int i; std::vector<sLayer> layers; // get a list of the visible layers for (i = 0; i < (unsigned int)m_Map->GetNumLayers(); i++) { if (m_Map->GetLayer(i).IsVisible()) { layers.push_back(m_Map->GetLayer(i)); } } if (!(layers.size() >= 1)) { MessageBox("No layers are visible!", "No layers are visible", MB_OK); return; } else if (layers.size() == 1) { return; } int result = MessageBox("Flatten all visible layers?", "Flatten Layers", MB_YESNOCANCEL | MB_ICONQUESTION | MB_DEFBUTTON3); if (result != IDYES) { return; } int width = 0; int height = 0; // find the size of the image we're going to create for (i = 0; i < layers.size(); i++) { if (layers[i].GetWidth() > width) { width = layers[i].GetWidth(); } if (layers[i].GetHeight() > height) { height = layers[i].GetHeight(); } } if (width <= 0 || height <= 0) return; sLayer new_layer; new_layer.SetName("flattened_layer"); new_layer.Resize(width, height); sTileset& tileset = m_Map->GetTileset(); sTile new_tile(tileset.GetTileWidth(), tileset.GetTileHeight()); std::vector<int> blended_tile_indexes; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { new_tile.Clear(); blended_tile_indexes.clear(); for (unsigned int i = 0; i < layers.size(); ++i) { if (y < layers[i].GetHeight() && x < layers[i].GetWidth()) { sTile& tile = tileset.GetTile(layers[i].GetTile(x, y)); bool is_empty = true; for (int iy = 0; iy < tile.GetHeight(); ++iy) { for (int ix = 0; ix < tile.GetWidth(); ++ix) { if (tile.GetPixel(ix, iy).alpha != 0) { is_empty = false; break; } } } if (is_empty == false) { blended_tile_indexes.push_back(layers[i].GetTile(x, y)); BlendImage(new_tile.GetWidth(), new_tile.GetHeight(), tile.GetWidth(), tile.GetHeight(), new_tile.GetPixels(), tile.GetPixels()); } } } if (blended_tile_indexes.size() == 1) { new_layer.SetTile(x, y, blended_tile_indexes[0]); } else { int tile_index = -1; // make the tile fully opaque new_tile.SetAlpha(255, true); // see if the new_tile already exists within the tileset for (int i = 0; i < tileset.GetNumTiles(); ++i) { if (tileset.GetTile(i) == new_tile) { tile_index = i; break; } } if (tile_index == -1) { tile_index = tileset.GetNumTiles(); tileset.AppendTiles(1); tileset.GetTile(tile_index) = new_tile; } new_layer.SetTile(x, y, tile_index); } } } // turn the layers that were visible off for (i = 0; i < layers.size(); i++) { m_Map->GetLayer(i).SetVisible(false); } m_Map->AppendLayer(new_layer); Invalidate(); m_Handler->LV_MapChanged(); }