this repo has no description
0
fork

Configure Feed

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

Fixed image loading color masks (for little endian client - BE needs testing). Fixed bug where GPU_SaveImage() would destroy an image's attached target.

+87 -32
+68 -26
SDL_gpu/OpenGL_common/SDL_gpu_OpenGL.c
··· 619 619 { 620 620 unsigned char* data = (unsigned char*)malloc(image->w * image->h * image->channels); 621 621 622 - GPU_Target* tgt = GPU_LoadTarget(image); 622 + GPU_Target* tgt = image->target; 623 + Uint8 loadedTarget = 0; 624 + if(tgt == NULL) 625 + { 626 + tgt = GPU_LoadTarget(image); 627 + loadedTarget = 1; 628 + } 629 + 623 630 readTexPixels(renderer, tgt, image->w, image->h, ((ImageData_OpenGL*)image->data)->format, data); 624 - GPU_FreeTarget(tgt); 631 + 632 + if(loadedTarget) 633 + GPU_FreeTarget(tgt); 625 634 626 635 return data; 627 636 } ··· 739 748 case GL_RGB: 740 749 if(format->BytesPerPixel != 3) 741 750 return 1; 742 - if(format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) 751 + if(format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000) 743 752 { 744 753 if(surfaceFormatResult != NULL) 745 754 *surfaceFormatResult = GL_RGB; ··· 750 759 case GL_BGR: 751 760 if(format->BytesPerPixel != 3) 752 761 return 1; 753 - if(format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000) 762 + if(format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) 754 763 { 755 764 if(enabled_features & GPU_FEATURE_GL_BGR) 756 765 { ··· 768 777 case GL_RGBA: 769 778 if(format->BytesPerPixel != 4) 770 779 return 1; 771 - if (format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00) 780 + if (format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000) 772 781 { 773 782 if(surfaceFormatResult != NULL) 774 783 *surfaceFormatResult = GL_RGBA; ··· 779 788 case GL_BGRA: 780 789 if(format->BytesPerPixel != 4) 781 790 return 1; 782 - if (format->Rmask == 0x0000FF00 && format->Gmask == 0x00FF0000 && format->Bmask == 0xFF000000) 791 + if (format->Rmask == 0x00FF0000 && format->Gmask == 0x0000FF00 && format->Bmask == 0x000000FF) 783 792 { 784 793 if(surfaceFormatResult != NULL) 785 794 *surfaceFormatResult = GL_BGRA; ··· 791 800 case GL_ABGR: 792 801 if(format->BytesPerPixel != 4) 793 802 return 1; 794 - if (format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000) 803 + if (format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00) 795 804 { 796 805 if(surfaceFormatResult != NULL) 797 806 *surfaceFormatResult = GL_ABGR; ··· 817 826 return 1; 818 827 819 828 // Looks like RGB? Easy! 820 - if(format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) 829 + else if(format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000) 821 830 { 822 831 if(surfaceFormatResult != NULL) 823 832 *surfaceFormatResult = GL_RGB; 824 833 return 0; 825 834 } 826 835 // Looks like BGR? 827 - else if(format->Rmask == 0x0000FF && format->Gmask == 0x00FF00 && format->Bmask == 0xFF0000) 836 + if(format->Rmask == 0xFF0000 && format->Gmask == 0x00FF00 && format->Bmask == 0x0000FF) 828 837 { 829 838 #ifdef GL_BGR 830 839 if(enabled_features & GPU_FEATURE_GL_BGR) ··· 849 858 return 1; 850 859 851 860 // Looks like RGBA? Easy! 852 - if(format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00) 861 + else if(format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000) 853 862 { 854 863 if(surfaceFormatResult != NULL) 855 864 *surfaceFormatResult = GL_RGBA; 856 865 return 0; 857 866 } 858 867 // Looks like ABGR? 859 - else if(format->Rmask == 0x000000FF && format->Gmask == 0x0000FF00 && format->Bmask == 0x00FF0000) 868 + if(format->Rmask == 0xFF000000 && format->Gmask == 0x00FF0000 && format->Bmask == 0x0000FF00) 860 869 { 861 870 #ifdef GL_ABGR 862 871 if(enabled_features & GPU_FEATURE_GL_ABGR) ··· 868 877 #endif 869 878 } 870 879 // Looks like BGRA? 871 - else if(format->Rmask == 0x0000FF00 && format->Gmask == 0x00FF0000 && format->Bmask == 0xFF000000) 880 + else if(format->Rmask == 0x00FF0000 && format->Gmask == 0x0000FF00 && format->Bmask == 0x000000FF) 872 881 { 873 882 #ifdef GL_BGRA 874 883 if(enabled_features & GPU_FEATURE_GL_BGRA) ··· 893 902 { 894 903 // Yes, I need to do the whole thing myself... :( 895 904 int channels; 896 - Uint32 Rmask, Gmask, Bmask, Amask, mask; 905 + Uint32 Rmask, Gmask, Bmask, Amask = 0, mask; 897 906 898 907 switch(glFormat) 899 908 { 900 909 case GL_RGB: 901 910 channels = 3; 902 - #if SDL_BYTEORDER == SDL_BIG_ENDIAN 903 - Rmask = 0xFF0000; 904 - Gmask = 0x00FF00; 905 - Bmask = 0x0000FF; 906 - #else 907 911 Rmask = 0x0000FF; 908 912 Gmask = 0x00FF00; 909 913 Bmask = 0xFF0000; 910 - #endif 911 914 break; 912 915 #ifdef GL_BGR 913 916 case GL_BGR: 914 917 channels = 3; 915 - #if SDL_BYTEORDER == SDL_BIG_ENDIAN 916 - Bmask = 0xFF0000; 917 - Gmask = 0x00FF00; 918 - Rmask = 0x0000FF; 919 - #else 920 918 Bmask = 0x0000FF; 921 919 Gmask = 0x00FF00; 922 920 Rmask = 0xFF0000; 923 - #endif 924 921 break; 925 922 #endif 926 923 case GL_RGBA: ··· 951 948 default: 952 949 return NULL; 953 950 } 951 + 952 + //GPU_LogError("AllocFormat(): %d, Masks: %X %X %X %X\n", glFormat, Rmask, Gmask, Bmask, Amask); 954 953 955 954 SDL_PixelFormat* result = (SDL_PixelFormat*)malloc(sizeof(SDL_PixelFormat)); 956 955 memset(result, 0, sizeof(SDL_PixelFormat)); ··· 1133 1132 // (newSurface->pitch / newSurface->format->BytesPerPixel)); 1134 1133 if(!need_power_of_two_upload) 1135 1134 { 1135 + //GPU_LogError("InitImageWithSurface(), Copy? %d, internal: %d, original: %d\n", (newSurface != surface), internal_format, original_format); 1136 1136 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, newSurface->w, newSurface->h, 0, 1137 1137 original_format, GL_UNSIGNED_BYTE, newSurface->pixels); 1138 1138 } ··· 1157 1157 return 1; 1158 1158 } 1159 1159 1160 + 1161 + static inline Uint32 getPixel(SDL_Surface *Surface, int x, int y) 1162 + { 1163 + Uint8* bits; 1164 + Uint32 bpp; 1165 + 1166 + if(x < 0 || x >= Surface->w) 1167 + return 0; // Best I could do for errors 1168 + 1169 + bpp = Surface->format->BytesPerPixel; 1170 + bits = ((Uint8*)Surface->pixels) + y*Surface->pitch + x*bpp; 1171 + 1172 + switch (bpp) 1173 + { 1174 + case 1: 1175 + return *((Uint8*)Surface->pixels + y * Surface->pitch + x); 1176 + break; 1177 + case 2: 1178 + return *((Uint16*)Surface->pixels + y * Surface->pitch/2 + x); 1179 + break; 1180 + case 3: 1181 + // Endian-correct, but slower 1182 + { 1183 + Uint8 r, g, b; 1184 + r = *((bits)+Surface->format->Rshift/8); 1185 + g = *((bits)+Surface->format->Gshift/8); 1186 + b = *((bits)+Surface->format->Bshift/8); 1187 + return SDL_MapRGB(Surface->format, r, g, b); 1188 + } 1189 + break; 1190 + case 4: 1191 + return *((Uint32*)Surface->pixels + y * Surface->pitch/4 + x); 1192 + break; 1193 + } 1194 + 1195 + return 0; // FIXME: Handle errors better 1196 + } 1197 + 1160 1198 // From SDL_CreateTextureFromSurface 1161 1199 static GPU_Image* CopyImageFromSurface(GPU_Renderer* renderer, SDL_Surface* surface) 1162 1200 { ··· 1191 1229 { 1192 1230 channels = 3; 1193 1231 } 1194 - 1232 + 1233 + //GPU_LogError("Format... Channels: %d, BPP: %d, Masks: %X %X %X %X\n", channels, fmt->BytesPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask); 1234 + 1235 + //Uint32 pix = getPixel(surface, 128, 128); 1236 + //GPU_LogError("Middle pixel: %X\n", pix); 1195 1237 image = CreateUninitializedImage(renderer, surface->w, surface->h, channels); 1196 1238 if(image == NULL) 1197 1239 return NULL;
+11 -4
SDL_gpu/SDL_gpu.c
··· 325 325 326 326 if(channels == 3) 327 327 { 328 + // These are reversed from what SDL_image uses... That is bad. :( Needs testing. 329 + #if SDL_BYTEORDER == SDL_BIG_ENDIAN 328 330 Rmask = 0xff0000; 329 331 Gmask = 0x00ff00; 330 332 Bmask = 0x0000ff; 333 + #else 334 + Rmask = 0x0000ff; 335 + Gmask = 0x00ff00; 336 + Bmask = 0xff0000; 337 + #endif 331 338 } 332 339 else 333 340 { 334 - Rmask = 0xff000000; 335 - Gmask = 0x00ff0000; 336 - Bmask = 0x0000ff00; 337 - Amask = 0x000000ff; 341 + Rmask = 0x000000ff; 342 + Gmask = 0x0000ff00; 343 + Bmask = 0x00ff0000; 344 + Amask = 0xff000000; 338 345 } 339 346 340 347 SDL_Surface* result = SDL_CreateRGBSurfaceFrom(data, width, height, channels*8, width*channels, Rmask, Gmask, Bmask, Amask);
+8 -2
demos/create/main.c
··· 2 2 #include "SDL_gpu.h" 3 3 #include <math.h> 4 4 5 + #define IMAGE_FILE "data/test.bmp" 6 + 5 7 void printRenderers(void) 6 8 { 7 9 const char* renderers[GPU_GetNumRegisteredRenderers()]; ··· 28 30 29 31 printf("Using renderer: %s\n", GPU_GetCurrentRendererID()); 30 32 31 - GPU_Image* image = GPU_LoadImage("data/test.bmp"); 33 + GPU_LogError("Loading image\n"); 34 + GPU_Image* image = GPU_LoadImage(IMAGE_FILE); 32 35 if(image == NULL) 33 36 { 34 37 GPU_LogError("Failed to load image.\n"); 35 38 return -1; 36 39 } 37 40 41 + GPU_LogError("Loading image1\n"); 38 42 GPU_Image* image1 = GPU_CreateImage(200, 200, 4); 39 43 if(image1 == NULL) 40 44 { ··· 45 49 GPU_ClearRGBA(image1_tgt, 0, 0, 255, 255); 46 50 GPU_FreeTarget(image1_tgt); 47 51 52 + GPU_LogError("Loading image2\n"); 48 53 GPU_Image* image2 = GPU_CopyImage(image); 49 54 if(image2 == NULL) 50 55 { ··· 52 57 return -1; 53 58 } 54 59 55 - SDL_Surface* surface = SDL_LoadBMP("data/test.bmp"); 60 + SDL_Surface* surface = SDL_LoadBMP(IMAGE_FILE); 61 + GPU_LogError("Loading image3\n"); 56 62 GPU_Image* image3 = GPU_CopyImageFromSurface(surface); 57 63 SDL_FreeSurface(surface); 58 64 if(image == NULL)
demos/data/test.bmp

This is a binary file and will not be displayed.