neaten up the code for reading bitmap pixels :)
This commit is contained in:
		
							parent
							
								
									ea96b298b3
								
							
						
					
					
						commit
						0fca3e3d43
					
				
					 1 changed files with 27 additions and 11 deletions
				
			
		
							
								
								
									
										38
									
								
								src/image.c
									
										
									
									
									
								
							
							
						
						
									
										38
									
								
								src/image.c
									
										
									
									
									
								
							|  | @ -104,22 +104,37 @@ static uint8_t rgb_to_2bpp(uint8_t r, uint8_t g, uint8_t b, size_t x, size_t y) | |||
|     return (slot & (0x8000 >> ((y & 3) << 2) >> (x & 3)))? to: from; | ||||
| } | ||||
| 
 | ||||
| static inline uint8_t bitmap_read_channel(uint8_t *buf, | ||||
|                                           size_t x, size_t y, size_t stride, | ||||
|                                           int channels, | ||||
|                                           int channel) { | ||||
|     return buf[channels*stride*y + channels*x + channel]; | ||||
| } | ||||
| 
 | ||||
| static inline void bitmap_read(uint8_t *buf, | ||||
|                                size_t x, size_t y, size_t stride, | ||||
|                                uint8_t *r, uint8_t *g, uint8_t *b, | ||||
|                                int channels) { | ||||
|     *r = buf[channels*stride*y + channels*x]; | ||||
|     *g = buf[channels*stride*y + channels*x + 1]; | ||||
|     *b = buf[channels*stride*y + channels*x + 2]; | ||||
|     *r = bitmap_read_channel(buf, x, y, stride, channels, 0); | ||||
|     *r = bitmap_read_channel(buf, x, y, stride, channels, 1); | ||||
|     *r = bitmap_read_channel(buf, x, y, stride, channels, 2); | ||||
| } | ||||
| 
 | ||||
| static inline void bitmap_write_channel(uint8_t *buf, | ||||
|                                         size_t x, size_t y, size_t stride, | ||||
|                                         int channels, | ||||
|                                         int channel, | ||||
|                                         uint8_t v) { | ||||
|     buf[channels*stride*y + channels*x + channel] = v; | ||||
| } | ||||
| 
 | ||||
| static inline void bitmap_write(uint8_t *buf, | ||||
|                                 size_t x, size_t y, size_t stride, | ||||
|                                 uint8_t r, uint8_t g, uint8_t b, | ||||
|                                 int channels) { | ||||
|     buf[channels*stride*y + channels*x]     = r; | ||||
|     buf[channels*stride*y + channels*x + 1] = g; | ||||
|     buf[channels*stride*y + channels*x + 2] = b; | ||||
|                                 int channels, | ||||
|                                 uint8_t r, uint8_t g, uint8_t b) { | ||||
|     bitmap_write_channel(buf, x, y, stride, channels, 0, r); | ||||
|     bitmap_write_channel(buf, x, y, stride, channels, 1, g); | ||||
|     bitmap_write_channel(buf, x, y, stride, channels, 2, b); | ||||
| } | ||||
| 
 | ||||
| static inline size_t size_2bpp_tile(size_t width, size_t height) { | ||||
|  | @ -547,7 +562,8 @@ static void bitmap_copy(cammy_image *dest, | |||
|                          to->x + x, | ||||
|                          to->y + y, | ||||
|                          dest->width, | ||||
|                          r, g, b, channels_dest); | ||||
|                          channels_dest, | ||||
|                          r, g, b); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -614,10 +630,10 @@ static void tile_copy_to_bitmap(cammy_image *dest, | |||
|                          x, | ||||
|                          y, | ||||
|                          from->width, | ||||
|                          channels, | ||||
|                          src->palette[c].r, | ||||
|                          src->palette[c].g, | ||||
|                          src->palette[c].b, | ||||
|                          channels); | ||||
|                          src->palette[c].b); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue