Changeset 725
- Timestamp:
- Mar 6, 2011, 10:46:24 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r699 r725 21 21 liblol_a_CPPFLAGS = @LOL_CFLAGS@ 22 22 23 EXTRA_DIST = image.mm 24 -
trunk/src/image.cpp
r723 r725 16 16 #include <cstdio> 17 17 18 #if defined USE_SDL 18 #if defined __APPLE__ && defined __MACH__ 19 # 20 #elif defined USE_SDL 19 21 # include <SDL.h> 20 22 # include <SDL_image.h> … … 46 48 Image::format_t format; 47 49 48 #if defined USE_SDL 50 #if defined __APPLE__ && defined __MACH__ 51 uint8_t *pixels; 52 #elif defined USE_SDL 49 53 SDL_Surface *img; 50 54 #elif defined ANDROID_NDK … … 53 57 jint *pixels; 54 58 #else 55 uint8_t * dummy;59 uint8_t *pixels; 56 60 #endif 57 61 }; … … 64 68 : data(new ImageData()) 65 69 { 66 #if defined USE_SDL 70 #if defined __APPLE__ && defined __MACH__ 71 NSString *path = [[NSBundle mainBundle] pathForResource:@"ascii" ofType:@"png"]; 72 NSData *pngdata = [[NSData alloc] initWithContentsOfFile:path]; 73 UIImage *image = [[UIImage alloc] initWithData:pngdata]; 74 if (!image) 75 { 76 #if !LOL_RELEASE 77 fprintf(stderr, "ERROR: could not load %s\n", path); 78 #endif 79 exit(1); 80 } 81 82 int w = CGImageGetWidth(image.CGImage); 83 int h = CGImageGetHeight(image.CGImage); 84 data->size = vec2i(w, h); 85 data->format = FORMAT_RGBA; 86 87 CGColorSpaceRef cspace = CGColorSpaceCreateDeviceRGB(); 88 data->pixels = (uint8_t *)malloc(w * h * 4); 89 CGContextRef ctx = 90 CGBitmapContextCreate(data->pixels, w, h, 8, 4 * w, cspace, 91 kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); 92 CGColorSpaceRelease(cspace); 93 CGContextClearRect(ctx, CGRectMake(0, 0, w, h)); 94 CGContextTranslateCTM(ctx, 0, h - h); 95 CGContextDrawImage(ctx, CGRectMake(0, 0, w, h), image.CGImage); 96 CGContextRelease(ctx); 97 [image release]; 98 [pngdata release]; 99 #elif defined USE_SDL 67 100 for (char const *name = path; *name; name++) 68 101 if ((data->img = IMG_Load(name))) … … 114 147 data->size = 256; 115 148 data->format = FORMAT_RGBA; 116 data-> dummy = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*data->dummy));117 uint8_t *parser = data-> dummy;149 data->pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*data->pixels)); 150 uint8_t *parser = data->pixels; 118 151 for (int j = 0; j < 256; j++) 119 152 for (int i = 0; i < 256; i++) … … 139 172 void * Image::GetData() const 140 173 { 141 #if defined USE_SDL 174 #if defined __APPLE__ && defined __MACH__ 175 return data->pixels; 176 #elif defined USE_SDL 142 177 return data->img->pixels; 143 178 #elif defined ANDROID_NDK 144 179 return data->pixels; 145 180 #else 146 return data-> dummy;181 return data->pixels; 147 182 #endif 148 183 } … … 150 185 Image::~Image() 151 186 { 152 #if defined USE_SDL 187 #if defined __APPLE__ && defined __MACH__ 188 free(data->pixels); 189 #elif defined USE_SDL 153 190 SDL_FreeSurface(data->img); 154 191 #elif defined ANDROID_NDK … … 164 201 g_env->DeleteGlobalRef(data->bmp); 165 202 #else 166 free(data-> dummy);203 free(data->pixels); 167 204 #endif 168 205 delete data;
Note: See TracChangeset
for help on using the changeset viewer.