add BGRA support to Image_SavePNG
	
		
			
	
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
					Details
				
			
		
	
				
					
				
			
				
	
				continuous-integration/drone/push Build is passing
				
					Details
				
			
		
	
							parent
							
								
									fbff906aa3
								
							
						
					
					
						commit
						c9290c90ce
					
				|  | @ -68,17 +68,19 @@ REFRESHAPI void Refresh_Image_Free(uint8_t *mem); | ||||||
| 
 | 
 | ||||||
| /* Image Write API */ | /* Image Write API */ | ||||||
| 
 | 
 | ||||||
| /* Encodes RGBA8 image data into PNG data.
 | /* Encodes 32-bit color data into PNG data.
 | ||||||
|  * |  * | ||||||
|  * filename:    The filename that the image will be written to. |  * filename:    The filename that the image will be written to. | ||||||
|  * w:	        The width of the PNG data. |  * w:	        The width of the PNG data. | ||||||
|  * h:	        The height of the PNG data. |  * h:	        The height of the PNG data. | ||||||
|  * data:	    The raw RGBA8 image data. |  * bgra:		Whether the data is in BGRA8 format. Otherwise will assume RBGA8. | ||||||
|  |  * data:	    The raw color data. | ||||||
|  */ |  */ | ||||||
| REFRESHAPI void Refresh_Image_SavePNG( | REFRESHAPI void Refresh_Image_SavePNG( | ||||||
| 	char const *filename, | 	char const *filename, | ||||||
| 	int32_t w, | 	int32_t w, | ||||||
| 	int32_t h, | 	int32_t h, | ||||||
|  | 	uint8_t bgra, | ||||||
| 	uint8_t *data | 	uint8_t *data | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -209,9 +209,32 @@ void Refresh_Image_SavePNG( | ||||||
| 	const char *filename, | 	const char *filename, | ||||||
| 	int32_t w, | 	int32_t w, | ||||||
| 	int32_t h, | 	int32_t h, | ||||||
|  | 	uint8_t bgra, | ||||||
| 	uint8_t *data | 	uint8_t *data | ||||||
| ) { | ) { | ||||||
| 	stbi_write_png(filename, w, h, 4, data, w * 4); | 	uint32_t i; | ||||||
|  | 	uint8_t *bgraData; | ||||||
|  | 
 | ||||||
|  | 	if (bgra) | ||||||
|  | 	{ | ||||||
|  | 		bgraData = SDL_malloc(w * h * 4); | ||||||
|  | 
 | ||||||
|  | 		for (i = 0; i < w * h * 4; i += 4) | ||||||
|  | 		{ | ||||||
|  | 			bgraData[i]     = data[i + 2]; | ||||||
|  | 			bgraData[i + 1] = data[i + 1]; | ||||||
|  | 			bgraData[i + 2] = data[i]; | ||||||
|  | 			bgraData[i + 3] = data[i + 3]; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		stbi_write_png(filename, w, h, 4, bgraData, w * 4); | ||||||
|  | 
 | ||||||
|  | 		SDL_free(bgraData); | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		stbi_write_png(filename, w, h, 4, data, w * 4); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* vim: set noexpandtab shiftwidth=8 tabstop=8: */ | /* vim: set noexpandtab shiftwidth=8 tabstop=8: */ | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue