mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 18:30:06 +00:00 
			
		
		
		
	Replace black with transparent, increase atlas size
This commit is contained in:
		
							parent
							
								
									bc1bf8cef6
								
							
						
					
					
						commit
						f0bdeb09b1
					
				
					 2 changed files with 19 additions and 5 deletions
				
			
		|  | @ -92,7 +92,7 @@ void LoadImageResources(const std::vector<std::string>& urlStrings) | ||||||
|    if (textureCached) |    if (textureCached) | ||||||
|    { |    { | ||||||
|       util::TextureAtlas& textureAtlas = util::TextureAtlas::Instance(); |       util::TextureAtlas& textureAtlas = util::TextureAtlas::Instance(); | ||||||
|       textureAtlas.BuildAtlas(1024, 1024); |       textureAtlas.BuildAtlas(2048, 2048); | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -119,7 +119,7 @@ static void LoadTextures() | ||||||
|                                 ":/res/textures/lines/default-1x7.png"); |                                 ":/res/textures/lines/default-1x7.png"); | ||||||
|    textureAtlas.RegisterTexture("lines/test-pattern", |    textureAtlas.RegisterTexture("lines/test-pattern", | ||||||
|                                 ":/res/textures/lines/test-pattern.png"); |                                 ":/res/textures/lines/test-pattern.png"); | ||||||
|    textureAtlas.BuildAtlas(1024, 1024); |    textureAtlas.BuildAtlas(2048, 2048); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| } // namespace ResourceManager
 | } // namespace ResourceManager
 | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
| #include <scwx/network/cpr.hpp> | #include <scwx/network/cpr.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
|  | #include <execution> | ||||||
| #include <shared_mutex> | #include <shared_mutex> | ||||||
| #include <unordered_map> | #include <unordered_map> | ||||||
| #include <variant> | #include <variant> | ||||||
|  | @ -404,18 +405,31 @@ TextureAtlas::Impl::LoadImage(const std::string& imagePath) | ||||||
|          } |          } | ||||||
| 
 | 
 | ||||||
|          // Create a view pointing to the STB image data
 |          // Create a view pointing to the STB image data
 | ||||||
|          auto imageView = boost::gil::interleaved_view( |          auto stbView = boost::gil::interleaved_view( | ||||||
|             width, |             width, | ||||||
|             height, |             height, | ||||||
|             reinterpret_cast<boost::gil::rgba8_pixel_t*>(pixelData), |             reinterpret_cast<boost::gil::rgba8_pixel_t*>(pixelData), | ||||||
|             width * desiredChannels); |             width * desiredChannels); | ||||||
| 
 | 
 | ||||||
|          // Copy the view to the destination image
 |          // Copy the view to the destination image
 | ||||||
|          image = boost::gil::rgba8_image_t(imageView); |          image      = boost::gil::rgba8_image_t(stbView); | ||||||
|  |          auto& view = boost::gil::view(image); | ||||||
| 
 | 
 | ||||||
|  |          // If no alpha channel, replace black with transparent
 | ||||||
|          if (numChannels == 3) |          if (numChannels == 3) | ||||||
|          { |          { | ||||||
|             // TODO: If no alpha channel, replace black with transparent
 |             std::for_each( | ||||||
|  |                std::execution::par_unseq, | ||||||
|  |                view.begin(), | ||||||
|  |                view.end(), | ||||||
|  |                [](boost::gil::rgba8_pixel_t& pixel) | ||||||
|  |                { | ||||||
|  |                   static const boost::gil::rgba8_pixel_t kBlack {0, 0, 0, 255}; | ||||||
|  |                   if (pixel == kBlack) | ||||||
|  |                   { | ||||||
|  |                      pixel[3] = 0; | ||||||
|  |                   } | ||||||
|  |                }); | ||||||
|          } |          } | ||||||
| 
 | 
 | ||||||
|          stbi_image_free(pixelData); |          stbi_image_free(pixelData); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat