00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "mxf.h"
00016
00017 void *lock(SDL_Surface *surf, Uint8 type) {
00018 if(SDL_MUSTLOCK(surf)) {
00019 if(SDL_LockSurface(surf) < 0)
00020 return 0;
00021 }
00022
00023 type = surf->format->BitsPerPixel;
00024
00025 switch(surf->format->BitsPerPixel) {
00026 case 1:
00027 case 8:
00028 return (Uint8*)surf->pixels;
00029 break;
00030 case 16:
00031 case 2:
00032 return (Uint16*)surf->pixels;
00033 break;
00034 case 24:
00035 case 3:
00036 return (Uint32*)surf->pixels;
00037 break;
00038 case 32:
00039 case 4:
00040 return (Uint32*)surf->pixels;
00041 break;
00042 default:
00043 break;
00044 }
00045
00046 return 0;
00047
00048 }
00049
00050
00051
00052 void unlock(SDL_Surface *surf) {
00053 if(SDL_MUSTLOCK(surf)) {
00054 SDL_UnlockSurface(surf);
00055 }
00056 }
00057
00058 void setpixel(void *buff, Uint32 x, Uint32 y, Uint32 color, Uint8 type, Uint16 pitch) {
00059 static Uint8 *ubuff8 = 0;
00060
00061 switch(type) {
00062 case 1:
00063 case 8:
00064 {
00065 Uint8 *buf = (Uint8*)buff;
00066 buf += (y * pitch) + x;
00067 *buf = (Uint8) color;
00068
00069 }
00070 break;
00071 case 2:
00072 case 16:
00073 {
00074 static Uint16 *ubuff16 = 0;
00075 ubuff8 = (Uint8*) buff;
00076 ubuff8 += (y * pitch) + (x*2);
00077
00078 ubuff16 = (Uint16*) ubuff8;
00079 *ubuff16 = (Uint16) color;
00080 }
00081 break;
00082 case 3:
00083 case 24:
00084 {
00085 static char c1 = 0,c2 = 0,c3 = 0;
00086
00087 ubuff8 = (Uint8*) buff;
00088 ubuff8 += (y * pitch) + (x*3);
00089 if(SDL_BYTEORDER == SDL_LIL_ENDIAN) {
00090 c1 = (color & 0xFF0000) >> 16;
00091 c2 = (color & 0x00FF00) >> 8;
00092 c3 = (color & 0x0000FF);
00093 } else {
00094 c3 = (color & 0xFF0000) >> 16;
00095 c2 = (color & 0x00FF00) >> 8;
00096 c1 = (color & 0x0000FF);
00097 }
00098 ubuff8[0] = c3;
00099 ubuff8[1] = c2;
00100 ubuff8[2] = c1;
00101 }
00102 break;
00103 case 4:
00104 case 32:
00105 {
00106 static Uint32 *ubuff32 = 0;
00107 ubuff8 = (Uint8*) buff;
00108 ubuff8 += (y*pitch) + (x*4);
00109 ubuff32 = (Uint32*)ubuff8;
00110 *ubuff32 = color;
00111 }
00112 break;
00113 }
00114
00115 }
00116
00117 Uint32 getpixel(SDL_Surface *surf, int x, int y, Uint8 type, Uint16 pitch, SDL_Color *col) {
00118 static Uint8 *bitz = 0;
00119 Uint32 bpp = (Uint32) type;
00120 bitz = ((Uint8 *)surf->pixels)+y*pitch+x*(bpp/8);
00121 switch(type) {
00122 case 8:
00123 case 1:
00124 return *((Uint8 *)surf->pixels + y * pitch + x);
00125 break;
00126 case 16:
00127 case 2:
00128 return *((Uint16 *)surf->pixels + y * pitch/2 + x);
00129 break;
00130 case 3:
00131 case 24:
00132 {
00133 Uint8 r, g, b;
00134 r = *((bitz)+surf->format->Rshift/8);
00135 g = *((bitz)+surf->format->Gshift/8);
00136 b = *((bitz)+surf->format->Bshift/8);
00137 col->r = r;
00138 col->g = g;
00139 col->b = b;
00140 return SDL_MapRGB(surf->format,r,g,b);
00141
00142 }
00143 case 32:
00144 case 4:
00145 Uint32 value = *((Uint32 *)surf->pixels + y * pitch/4 + x);
00146 SDL_GetRGB(value, surf->format, &col->r, &col->g, &col->b);
00147 return value;
00148
00149 break;
00150 }
00151
00152 return 0;
00153 }
00154
00155