this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Made some improvements for BGR, BGRA, and ABGR format support.

+271 -14
+4 -1
include/SDL_gpu.h
··· 231 231 GPU_FORMAT_ALPHA = 5, 232 232 GPU_FORMAT_RG = 6, 233 233 GPU_FORMAT_YCbCr422 = 7, 234 - GPU_FORMAT_YCbCr420P = 8 234 + GPU_FORMAT_YCbCr420P = 8, 235 + GPU_FORMAT_BGR = 9, 236 + GPU_FORMAT_BGRA = 10, 237 + GPU_FORMAT_ABGR = 11 235 238 } GPU_FormatEnum; 236 239 237 240 /*! \ingroup ImageControls
+117 -7
src/renderer_GL_common.inl
··· 2192 2192 num_layers = 1; 2193 2193 bytes_per_pixel = 4; 2194 2194 break; 2195 + #ifdef GL_BGR 2196 + case GPU_FORMAT_BGR: 2197 + gl_format = GL_BGR; 2198 + num_layers = 1; 2199 + bytes_per_pixel = 3; 2200 + break; 2201 + #endif 2202 + #ifdef GL_BGRA 2203 + case GPU_FORMAT_BGRA: 2204 + gl_format = GL_BGRA; 2205 + num_layers = 1; 2206 + bytes_per_pixel = 4; 2207 + break; 2208 + #endif 2209 + #ifdef GL_ABGR 2210 + case GPU_FORMAT_ABGR: 2211 + gl_format = GL_ABGR; 2212 + num_layers = 1; 2213 + bytes_per_pixel = 4; 2214 + break; 2215 + #endif 2195 2216 case GPU_FORMAT_ALPHA: 2196 2217 gl_format = GL_ALPHA; 2197 2218 num_layers = 1; ··· 2388 2409 num_layers = 1; 2389 2410 bytes_per_pixel = 4; 2390 2411 break; 2412 + #ifdef GL_BGR 2413 + case GL_BGR: 2414 + format = GPU_FORMAT_BGR; 2415 + num_layers = 1; 2416 + bytes_per_pixel = 3; 2417 + break; 2418 + #endif 2419 + #ifdef GL_BGRA 2420 + case GL_BGRA: 2421 + format = GPU_FORMAT_BGRA; 2422 + num_layers = 1; 2423 + bytes_per_pixel = 4; 2424 + break; 2425 + #endif 2426 + #ifdef GL_ABGR 2427 + case GL_ABGR: 2428 + format = GPU_FORMAT_ABGR; 2429 + num_layers = 1; 2430 + bytes_per_pixel = 4; 2431 + break; 2432 + #endif 2391 2433 case GL_ALPHA: 2392 2434 format = GPU_FORMAT_ALPHA; 2393 2435 num_layers = 1; ··· 3102 3144 { 3103 3145 case GPU_FORMAT_RGB: 3104 3146 case GPU_FORMAT_RGBA: 3147 + case GPU_FORMAT_BGR: 3148 + case GPU_FORMAT_BGRA: 3149 + case GPU_FORMAT_ABGR: 3105 3150 // Copy via framebuffer blitting (fast) 3106 3151 { 3107 3152 GPU_Target* target; ··· 3668 3713 format = GPU_FORMAT_RGB; 3669 3714 } 3670 3715 else 3716 + { 3717 + // TODO: Choose the best format for the texture depending on endianness. 3671 3718 format = GPU_FORMAT_RGBA; 3719 + } 3672 3720 3673 3721 image = renderer->impl->CreateImage(renderer, surface->w, surface->h, format); 3674 3722 if(image == NULL) ··· 3774 3822 3775 3823 status = glCheckFramebufferStatusPROC(GL_FRAMEBUFFER); 3776 3824 if(status != GL_FRAMEBUFFER_COMPLETE) 3825 + { 3826 + GPU_PushErrorCode("GPU_GetTarget", GPU_ERROR_DATA_ERROR, "Framebuffer incomplete with status: 0x%x. Format 0x%x for framebuffers might not be supported on this hardware.", status, ((GPU_IMAGE_DATA*)image->data)->format); 3777 3827 return NULL; 3828 + } 3778 3829 3779 3830 result = (GPU_Target*)SDL_malloc(sizeof(GPU_Target)); 3780 3831 memset(result, 0, sizeof(GPU_Target)); ··· 5010 5061 5011 5062 5012 5063 5013 - 5064 + static void swizzle_for_format(SDL_Color* color, GLenum format, unsigned char pixel[4]) 5065 + { 5066 + switch(format) 5067 + { 5068 + case GL_LUMINANCE: 5069 + color->b = color->g = color->r = pixel[0]; 5070 + GET_ALPHA(*color) = 255; 5071 + break; 5072 + case GL_LUMINANCE_ALPHA: 5073 + color->b = color->g = color->r = pixel[0]; 5074 + GET_ALPHA(*color) = pixel[3]; 5075 + break; 5076 + #ifdef GL_BGR 5077 + case GL_BGR: 5078 + color->b = pixel[0]; 5079 + color->g = pixel[1]; 5080 + color->r = pixel[2]; 5081 + GET_ALPHA(*color) = 255; 5082 + break; 5083 + #endif 5084 + #ifdef GL_BGRA 5085 + case GL_BGRA: 5086 + color->b = pixel[0]; 5087 + color->g = pixel[1]; 5088 + color->r = pixel[2]; 5089 + GET_ALPHA(*color) = pixel[3]; 5090 + break; 5091 + #endif 5092 + #ifdef GL_ABGR 5093 + case GL_ABGR: 5094 + GET_ALPHA(*color) = pixel[0]; 5095 + color->b = pixel[1]; 5096 + color->g = pixel[2]; 5097 + color->r = pixel[3]; 5098 + break; 5099 + #endif 5100 + case GL_ALPHA: 5101 + break; 5102 + #ifndef SDL_GPU_USE_GLES 5103 + case GL_RG: 5104 + color->r = pixel[0]; 5105 + color->g = pixel[1]; 5106 + color->b = 0; 5107 + GET_ALPHA(*color) = 255; 5108 + break; 5109 + #endif 5110 + case GL_RGB: 5111 + color->r = pixel[0]; 5112 + color->g = pixel[1]; 5113 + color->b = pixel[2]; 5114 + GET_ALPHA(*color) = 255; 5115 + break; 5116 + case GL_RGBA: 5117 + color->r = pixel[0]; 5118 + color->g = pixel[1]; 5119 + color->b = pixel[2]; 5120 + GET_ALPHA(*color) = pixel[3]; 5121 + break; 5122 + default: 5123 + break; 5124 + } 5125 + } 5014 5126 5015 5127 static SDL_Color GetPixel(GPU_Renderer* renderer, GPU_Target* target, Sint16 x, Sint16 y) 5016 5128 { ··· 5027 5139 if(bindFramebuffer(renderer, target)) 5028 5140 { 5029 5141 unsigned char pixels[4]; 5030 - glReadPixels(x, y, 1, 1, ((GPU_TARGET_DATA*)target->data)->format, GL_UNSIGNED_BYTE, pixels); 5031 - 5032 - result.r = pixels[0]; 5033 - result.g = pixels[1]; 5034 - result.b = pixels[2]; 5035 - GET_ALPHA(result) = pixels[3]; 5142 + GLenum format = ((GPU_TARGET_DATA*)target->data)->format; 5143 + glReadPixels(x, y, 1, 1, format, GL_UNSIGNED_BYTE, pixels); 5144 + 5145 + swizzle_for_format(&result, format, pixels); 5036 5146 } 5037 5147 5038 5148 return result;
tests/data/test_24bit.bmp

This is a binary file and will not be displayed.

tests/data/test_32bit.bmp

This is a binary file and will not be displayed.

+150 -6
tests/image-formats/main.c
··· 71 71 free(bytes); 72 72 } 73 73 74 + void update_bgr_data(GPU_Image* image) 75 + { 76 + if(image == NULL) 77 + return; 78 + 79 + int bytes_per_row = image->bytes_per_pixel * image->w; 80 + unsigned int num_pixels = image->w * image->h; 81 + unsigned char* bytes = (unsigned char*)malloc(image->bytes_per_pixel * num_pixels); 82 + 83 + // Alternating columns of red and white 84 + int i; 85 + for(i = 0; i < num_pixels; i++) 86 + { 87 + if((i/4)%2 == 0) 88 + { 89 + bytes[i*image->bytes_per_pixel] = 0; 90 + bytes[i*image->bytes_per_pixel+1] = 0; 91 + bytes[i*image->bytes_per_pixel+2] = 255; 92 + } 93 + else 94 + { 95 + bytes[i*image->bytes_per_pixel] = 255; 96 + bytes[i*image->bytes_per_pixel+1] = 255; 97 + bytes[i*image->bytes_per_pixel+2] = 255; 98 + } 99 + } 100 + 101 + GPU_UpdateImageBytes(image, NULL, bytes, bytes_per_row); 102 + free(bytes); 103 + } 104 + 105 + void update_bgra_data(GPU_Image* image) 106 + { 107 + if(image == NULL) 108 + return; 109 + 110 + int bytes_per_row = image->bytes_per_pixel * image->w; 111 + unsigned int num_pixels = image->w * image->h; 112 + unsigned char* bytes = (unsigned char*)malloc(image->bytes_per_pixel * num_pixels); 113 + 114 + // Alternating columns of blue and white 115 + int i; 116 + for(i = 0; i < num_pixels; i++) 117 + { 118 + if((i/4)%2 == 0) 119 + { 120 + bytes[i*image->bytes_per_pixel] = 255; 121 + bytes[i*image->bytes_per_pixel+1] = 0; 122 + bytes[i*image->bytes_per_pixel+2] = 0; 123 + bytes[i*image->bytes_per_pixel+3] = 255; 124 + } 125 + else 126 + { 127 + bytes[i*image->bytes_per_pixel] = 255; 128 + bytes[i*image->bytes_per_pixel+1] = 255; 129 + bytes[i*image->bytes_per_pixel+2] = 255; 130 + bytes[i*image->bytes_per_pixel+3] = 255; 131 + } 132 + } 133 + 134 + GPU_UpdateImageBytes(image, NULL, bytes, bytes_per_row); 135 + free(bytes); 136 + } 137 + 138 + void update_abgr_data(GPU_Image* image) 139 + { 140 + if(image == NULL) 141 + return; 142 + 143 + int bytes_per_row = image->bytes_per_pixel * image->w; 144 + unsigned int num_pixels = image->w * image->h; 145 + unsigned char* bytes = (unsigned char*)malloc(image->bytes_per_pixel * num_pixels); 146 + 147 + // Alternating columns of green and white 148 + int i; 149 + for(i = 0; i < num_pixels; i++) 150 + { 151 + if((i/4)%2 == 0) 152 + { 153 + bytes[i*image->bytes_per_pixel] = 255; 154 + bytes[i*image->bytes_per_pixel+1] = 0; 155 + bytes[i*image->bytes_per_pixel+2] = 255; 156 + bytes[i*image->bytes_per_pixel+3] = 0; 157 + } 158 + else 159 + { 160 + bytes[i*image->bytes_per_pixel] = 255; 161 + bytes[i*image->bytes_per_pixel+1] = 255; 162 + bytes[i*image->bytes_per_pixel+2] = 255; 163 + bytes[i*image->bytes_per_pixel+3] = 255; 164 + } 165 + } 166 + 167 + GPU_UpdateImageBytes(image, NULL, bytes, bytes_per_row); 168 + free(bytes); 169 + } 170 + 171 + void blit_copy(GPU_Image* src, GPU_Image* dst) 172 + { 173 + GPU_Target* target = GPU_GetTarget(dst); 174 + 175 + if(target != NULL) 176 + GPU_Blit(src, NULL, target, target->w/2, target->h/2); 177 + else 178 + GPU_LogError("Failed to load target.\n"); 179 + } 180 + 74 181 int main(int argc, char* argv[]) 75 182 { 76 183 GPU_Target* screen; ··· 96 203 GPU_Image* image_png; 97 204 GPU_Image* image_luminance; 98 205 GPU_Image* image_luminance_alpha; 206 + GPU_Image* image_bgr; 207 + GPU_Image* image_bgra; 208 + GPU_Image* image_abgr; 209 + 210 + SDL_Color corner_color; 99 211 100 212 surface = SDL_LoadBMP("data/test_8bit.bmp"); 101 213 image8 = copy_and_log(surface); ··· 137 249 log_image_details(image_luminance_alpha); 138 250 update_luminance_alpha_data(image_luminance_alpha); 139 251 252 + GPU_Log("BGR\n"); 253 + image_bgr = GPU_CreateImage(200, 200, GPU_FORMAT_BGR); 254 + if(image_bgr == NULL) 255 + return -7; 256 + 257 + log_image_details(image_bgr); 258 + update_bgr_data(image_bgr); 259 + 260 + GPU_Log("BGRA\n"); 261 + image_bgra = GPU_CreateImage(200, 200, GPU_FORMAT_BGRA); 262 + if(image_bgra == NULL) 263 + return -8; 264 + 265 + log_image_details(image_bgra); 266 + update_bgra_data(image_bgra); 267 + corner_color = GPU_GetPixel(GPU_GetTarget(image_bgra), 0, 0); 268 + GPU_Log("BGRA upper corner in RGBA: (%u, %u, %u, %u)\n", corner_color.r, corner_color.g, corner_color.b, corner_color.a); 269 + 270 + GPU_Log("ABGR\n"); 271 + image_abgr = GPU_CreateImage(200, 200, GPU_FORMAT_ABGR); 272 + if(image_abgr == NULL) 273 + return -9; 274 + 275 + log_image_details(image_abgr); 276 + update_abgr_data(image_abgr); 277 + 278 + 279 + GPU_Log(" Ready\n"); 280 + 140 281 startTime = SDL_GetTicks(); 141 282 frameCount = 0; 142 283 ··· 156 297 157 298 GPU_Clear(screen); 158 299 159 - GPU_Blit(image8, NULL, screen, image8->w/2, image8->h/2); 160 - GPU_Blit(image24, NULL, screen, image8->w + image24->w/2, image24->h/2); 161 - GPU_Blit(image32, NULL, screen, image32->w/2, image8->h + image32->h/2); 162 - GPU_Blit(image_png, NULL, screen, image8->w + image_png->w/2, image24->h + image_png->h/2); 300 + //GPU_Blit(image8, NULL, screen, image8->w/2, image8->h/2); 301 + //GPU_Blit(image24, NULL, screen, image8->w + image24->w/2, image24->h/2); 302 + //GPU_Blit(image32, NULL, screen, image32->w/2, image8->h + image32->h/2); 303 + //GPU_Blit(image_png, NULL, screen, image8->w + image_png->w/2, image24->h + image_png->h/2); 163 304 164 305 165 - GPU_Blit(image_luminance, NULL, screen, image8->w + image24->w + image_luminance->w/2, image_luminance->h/2); 166 - GPU_Blit(image_luminance_alpha, NULL, screen, image8->w + image24->w + image_luminance_alpha->w/2, image_luminance->h + image_luminance_alpha->h/2); 306 + //GPU_Blit(image_luminance, NULL, screen, image8->w + image24->w + image_luminance->w/2, image_luminance->h/2); 307 + //GPU_Blit(image_luminance_alpha, NULL, screen, image8->w + image24->w + image_luminance_alpha->w/2, image_luminance->h + image_luminance_alpha->h/2); 308 + GPU_Blit(image_bgr, NULL, screen, image8->w/2, image8->h/2); 309 + GPU_Blit(image_bgra, NULL, screen, image8->w + image24->w/2, image24->h/2); 310 + GPU_Blit(image_abgr, NULL, screen, image32->w/2, image8->h + image32->h/2); 167 311 168 312 GPU_Flip(screen); 169 313