this repo has no description
0
fork

Configure Feed

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

To fix POT image saving: Reworked SaveImage() so it doesn't duplicate GPU_SaveSurface() and CopySurfaceFromImage(). CopySurfaceFromImage() now uses the image dimensions instead of texture dimensions when a non-virtual image resolution is used. When virtual res is used, the whole texture is saved... This should be fixed, but requires an extra set of dimensions to be stored for POT textures.

+24 -56
+23 -55
src/renderer_GL_common.inl
··· 2410 2410 return data; 2411 2411 } 2412 2412 2413 - // From http://stackoverflow.com/questions/5309471/getting-file-extension-in-c 2414 - static const char *get_filename_ext(const char *filename) 2415 - { 2416 - const char *dot = strrchr(filename, '.'); 2417 - if(!dot || dot == filename) 2418 - return ""; 2419 - return dot + 1; 2420 - } 2421 - 2422 2413 static Uint8 SaveImage(GPU_Renderer* renderer, GPU_Image* image, const char* filename, GPU_FileFormatEnum format) 2423 2414 { 2424 2415 Uint8 result; 2425 - unsigned char* data; 2416 + SDL_Surface* surface; 2426 2417 2427 2418 if(image == NULL || filename == NULL || 2428 2419 image->texture_w < 1 || image->texture_h < 1 || image->bytes_per_pixel < 1 || image->bytes_per_pixel > 4) ··· 2430 2421 return 0; 2431 2422 } 2432 2423 2433 - data = getRawImageData(renderer, image); 2424 + surface = renderer->impl->CopySurfaceFromImage(renderer, image); 2434 2425 2435 - if(data == NULL) 2436 - { 2437 - GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_BACKEND_ERROR, "Could not retrieve texture data."); 2426 + if(surface == NULL) 2438 2427 return 0; 2439 - } 2440 - 2441 - if(format == GPU_FILE_AUTO) 2442 - { 2443 - const char* extension = get_filename_ext(filename); 2444 - if(gpu_strcasecmp(extension, "png") == 0) 2445 - format = GPU_FILE_PNG; 2446 - else if(gpu_strcasecmp(extension, "bmp") == 0) 2447 - format = GPU_FILE_BMP; 2448 - else if(gpu_strcasecmp(extension, "tga") == 0) 2449 - format = GPU_FILE_TGA; 2450 - else 2451 - { 2452 - GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_DATA_ERROR, "Could not detect output file format from file name"); 2453 - SDL_free(data); 2454 - return 0; 2455 - } 2456 - } 2457 - 2458 - switch(format) 2459 - { 2460 - case GPU_FILE_PNG: 2461 - result = (stbi_write_png(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (const unsigned char *const)data, 0) > 0); 2462 - break; 2463 - case GPU_FILE_BMP: 2464 - result = (stbi_write_bmp(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (void*)data) > 0); 2465 - break; 2466 - case GPU_FILE_TGA: 2467 - result = (stbi_write_tga(filename, image->texture_w, image->texture_h, image->bytes_per_pixel, (void*)data) > 0); 2468 - break; 2469 - default: 2470 - GPU_PushErrorCode("GPU_SaveImage", GPU_ERROR_DATA_ERROR, "Unsupported output file format"); 2471 - result = 0; 2472 - break; 2473 - } 2428 + 2429 + result = GPU_SaveSurface(surface, filename, format); 2474 2430 2475 - SDL_free(data); 2431 + SDL_FreeSurface(surface); 2476 2432 return result; 2477 2433 } 2478 2434 ··· 2533 2489 unsigned char* data; 2534 2490 SDL_Surface* result; 2535 2491 SDL_PixelFormat* format; 2492 + int w, h; 2536 2493 2537 2494 if(image == NULL) 2538 2495 { 2539 2496 GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_NULL_ARGUMENT, "image"); 2540 2497 return NULL; 2541 2498 } 2542 - if(image->texture_w < 1 || image->texture_h < 1) 2499 + if(image->w < 1 || image->h < 1) 2543 2500 { 2544 2501 GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Invalid image dimensions (%dx%d)", image->base_w, image->base_h); 2545 2502 return NULL; 2546 2503 } 2547 2504 2505 + // FIXME: Virtual resolutions overwrite the NPOT dimensions when NPOT textures are not supported! 2506 + if(image->using_virtual_resolution) 2507 + { 2508 + w = image->texture_w; 2509 + h = image->texture_h; 2510 + } 2511 + else 2512 + { 2513 + w = image->w; 2514 + h = image->h; 2515 + } 2548 2516 data = getRawImageData(renderer, image); 2549 2517 2550 2518 if(data == NULL) ··· 2555 2523 2556 2524 format = AllocFormat(((GPU_IMAGE_DATA*)image->data)->format); 2557 2525 2558 - result = SDL_CreateRGBSurface(SDL_SWSURFACE, image->texture_w, image->texture_h, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask); 2526 + result = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask); 2559 2527 2560 2528 if(result == NULL) 2561 2529 { 2562 - GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", image->texture_w, image->texture_h); 2530 + GPU_PushErrorCode("GPU_CopySurfaceFromImage", GPU_ERROR_DATA_ERROR, "Failed to create new %dx%d surface", w, h); 2563 2531 SDL_free(data); 2564 2532 return NULL; 2565 2533 } ··· 2567 2535 // Copy row-by-row in case the pitch doesn't match 2568 2536 { 2569 2537 int i; 2570 - int source_pitch = image->texture_w*format->BytesPerPixel; 2571 - for(i = 0; i < image->texture_h; ++i) 2538 + int source_pitch = image->texture_w*format->BytesPerPixel; // Use the actual texture width to pull from the data 2539 + for(i = 0; i < h; ++i) 2572 2540 { 2573 2541 memcpy((Uint8*)result->pixels + i*result->pitch, data + source_pitch*i, source_pitch); 2574 2542 }
+1 -1
tests/save/main.c
··· 3 3 #include <math.h> 4 4 #include "common.h" 5 5 6 - #define IMAGE_FILE "data/test.bmp" 6 + #define IMAGE_FILE "data/happy_52x63.bmp" 7 7 #define SAVE_FILE "save.bmp" 8 8 9 9