Changeset 725 for trunk


Ignore:
Timestamp:
Mar 6, 2011, 10:46:24 PM (11 years ago)
Author:
sam
Message:

ios: texture loading test.

Location:
trunk/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r699 r725  
    2121liblol_a_CPPFLAGS = @LOL_CFLAGS@
    2222
     23EXTRA_DIST = image.mm
     24
  • trunk/src/image.cpp

    r723 r725  
    1616#include <cstdio>
    1717
    18 #if defined USE_SDL
     18#if defined __APPLE__ && defined __MACH__
     19#
     20#elif defined USE_SDL
    1921#   include <SDL.h>
    2022#   include <SDL_image.h>
     
    4648    Image::format_t format;
    4749
    48 #if defined USE_SDL
     50#if defined __APPLE__ && defined __MACH__
     51    uint8_t *pixels;
     52#elif defined USE_SDL
    4953    SDL_Surface *img;
    5054#elif defined ANDROID_NDK
     
    5357    jint *pixels;
    5458#else
    55     uint8_t *dummy;
     59    uint8_t *pixels;
    5660#endif
    5761};
     
    6468  : data(new ImageData())
    6569{
    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
    67100    for (char const *name = path; *name; name++)
    68101        if ((data->img = IMG_Load(name)))
     
    114147    data->size = 256;
    115148    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;
    118151    for (int j = 0; j < 256; j++)
    119152        for (int i = 0; i < 256; i++)
     
    139172void * Image::GetData() const
    140173{
    141 #if defined USE_SDL
     174#if defined __APPLE__ && defined __MACH__
     175    return data->pixels;
     176#elif defined USE_SDL
    142177    return data->img->pixels;
    143178#elif defined ANDROID_NDK
    144179    return data->pixels;
    145180#else
    146     return data->dummy;
     181    return data->pixels;
    147182#endif
    148183}
     
    150185Image::~Image()
    151186{
    152 #if defined USE_SDL
     187#if defined __APPLE__ && defined __MACH__
     188    free(data->pixels);
     189#elif defined USE_SDL
    153190    SDL_FreeSurface(data->img);
    154191#elif defined ANDROID_NDK
     
    164201    g_env->DeleteGlobalRef(data->bmp);
    165202#else
    166     free(data->dummy);
     203    free(data->pixels);
    167204#endif
    168205    delete data;
Note: See TracChangeset for help on using the changeset viewer.