Changeset 833


Ignore:
Timestamp:
Aug 17, 2011, 7:13:48 PM (12 years ago)
Author:
sam
Message:

ps3: load textures using the system's PNGDEC module.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/ps3/Makefile

    r828 r833  
    2323PPU_LDLIBS += -lcgc -lPSGLcgc
    2424
     25# For the PNG decoder
     26PPU_LDLIBS += -lpngdec_stub
     27
    2528include $(CELL_SDK)/samples/sdk/graphics/psgl/MakeRules
    2629
  • trunk/src/image.cpp

    r758 r833  
    2323#   include <jni.h>
    2424#   include <android/log.h>
     25#elif defined __CELLOS_LV2__
     26#   include <cell/sysmodule.h>
     27#   include <cell/codec/pngdec.h>
    2528#endif
    2629
     
    5760    jintArray array;
    5861    jint *pixels;
     62#elif defined __CELLOS_LV2__
     63    static void* Malloc(uint32_t size, void* data) { return malloc(size); };
     64    static int32_t Free(void* ptr, void* data) { free(ptr); return 0; };
     65    uint8_t *pixels;
    5966#else
    6067    uint8_t *pixels;
     
    7077{
    7178#if defined __APPLE__ && defined __MACH__
    72         NSString *fullpath = [NSString stringWithUTF8String:path];
    73         NSArray *chunks = [fullpath componentsSeparatedByString: @"/"];
    74         NSString *filename = [chunks objectAtIndex: [chunks count] - 1];
    75         chunks = [filename componentsSeparatedByString: @"."];
    76         NSString *prefix = [chunks objectAtIndex: 0];
     79    NSString *fullpath = [NSString stringWithUTF8String:path];
     80    NSArray *chunks = [fullpath componentsSeparatedByString: @"/"];
     81    NSString *filename = [chunks objectAtIndex: [chunks count] - 1];
     82    chunks = [filename componentsSeparatedByString: @"."];
     83    NSString *prefix = [chunks objectAtIndex: 0];
    7784    NSString *mypath = [[NSBundle mainBundle] pathForResource:prefix ofType:@"png"];
    7885    NSData *pngdata = [[NSData alloc] initWithContentsOfFile:mypath];
     
    150157    }
    151158    data->format = FORMAT_RGBA;
     159#elif defined __CELLOS_LV2__
     160    int32_t err;
     161
     162    /* Initialise decoding library */
     163    CellPngDecMainHandle hmain;
     164
     165    err = cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
     166    if (err != CELL_OK)
     167    {
     168#if !LOL_RELEASE
     169        Log::Error("could not open Fs sysmodule\n");
     170#endif
     171        exit(1);
     172    }
     173
     174    err = cellSysmoduleLoadModule(CELL_SYSMODULE_PNGDEC);
     175    if (err != CELL_OK)
     176    {
     177#if !LOL_RELEASE
     178        Log::Error("could not open PngDec sysmodule\n");
     179#endif
     180        exit(1);
     181    }
     182
     183    CellPngDecThreadInParam in_param;
     184    in_param.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_ENABLE;
     185    in_param.ppuThreadPriority = 1000;
     186    in_param.spuThreadPriority = 200;
     187    in_param.cbCtrlMallocFunc = ImageData::Malloc;
     188    in_param.cbCtrlMallocArg = NULL;
     189    in_param.cbCtrlFreeFunc = ImageData::Free;
     190    in_param.cbCtrlFreeArg = NULL;
     191    CellPngDecThreadOutParam out_param;
     192    err = cellPngDecCreate(&hmain, &in_param, &out_param);
     193    if (err != CELL_OK)
     194    {
     195#if !LOL_RELEASE
     196        Log::Error("could not create PngDec library\n");
     197#endif
     198        exit(1);
     199    }
     200
     201    /* Create decoder */
     202    CellPngDecSubHandle hsub;
     203
     204    char file[1024];
     205    sprintf(file, "/app_home/c:/Users/s.hocevar/lolengine/%s", path);
     206
     207    CellPngDecSrc dec_src;
     208    dec_src.srcSelect = CELL_PNGDEC_FILE;
     209    dec_src.fileName = file;
     210    dec_src.fileOffset = 0;
     211    dec_src.fileSize = 0;
     212    dec_src.streamPtr = NULL;
     213    dec_src.streamSize = 0;
     214    dec_src.spuThreadEnable  = CELL_PNGDEC_SPU_THREAD_ENABLE;
     215    CellPngDecOpnInfo open_info;
     216    err = cellPngDecOpen(hmain, &hsub, &dec_src, &open_info);
     217    if (err != CELL_OK)
     218    {
     219#if !LOL_RELEASE
     220        Log::Error("could not open %s for decoding\n", file);
     221#endif
     222        exit(1);
     223    }
     224
     225    CellPngDecInfo info;
     226    err = cellPngDecReadHeader(hmain, hsub, &info);
     227    if (err != CELL_OK)
     228    {
     229#if !LOL_RELEASE
     230        Log::Error("could not read image header\n");
     231#endif
     232        exit(1);
     233    }
     234
     235    CellPngDecInParam in_dec_param;
     236    in_dec_param.commandPtr = NULL;
     237    in_dec_param.outputMode = CELL_PNGDEC_TOP_TO_BOTTOM;
     238    in_dec_param.outputColorSpace = CELL_PNGDEC_RGBA;
     239    in_dec_param.outputBitDepth = 8;
     240    in_dec_param.outputPackFlag = CELL_PNGDEC_1BYTE_PER_1PIXEL;
     241    in_dec_param.outputAlphaSelect = CELL_PNGDEC_STREAM_ALPHA;
     242    in_dec_param.outputColorAlpha = 0xff;
     243    CellPngDecOutParam out_dec_param;
     244    err = cellPngDecSetParameter(hmain, hsub, &in_dec_param, &out_dec_param);
     245    if (err != CELL_OK)
     246    {
     247#if !LOL_RELEASE
     248        Log::Error("could not configure PngDec decoder\n");
     249#endif
     250        exit(1);
     251    }
     252
     253    /* Decode image */
     254    data->size = vec2i(info.imageWidth, info.imageHeight);
     255    data->format = FORMAT_RGBA;
     256    data->pixels = (uint8_t *)malloc(info.imageWidth * 4 * info.imageHeight);
     257    CellPngDecDataCtrlParam data_ctrl_param;
     258    data_ctrl_param.outputBytesPerLine = info.imageWidth * 4;
     259    CellPngDecDataOutInfo data_out_info;
     260    err = cellPngDecDecodeData(hmain, hsub, data->pixels,
     261                               &data_ctrl_param, &data_out_info);
     262    if (err != CELL_OK)
     263    {
     264#if !LOL_RELEASE
     265        Log::Error("could not run PngDec decoder\n");
     266#endif
     267        exit(1);
     268    }
     269
     270    /* Close decoder */
     271    err = cellPngDecClose(hmain, hsub);
     272    if (err != CELL_OK)
     273    {
     274#if !LOL_RELEASE
     275        Log::Error("could not close PngDec decoder\n");
     276#endif
     277        exit(1);
     278    }
     279
     280    /* Deinitialise library */
     281    err = cellPngDecDestroy(hmain);
     282    if (err != CELL_OK)
     283    {
     284#if !LOL_RELEASE
     285        Log::Error("could not destroy PngDec decoder\n");
     286#endif
     287        exit(1);
     288    }
     289    err = cellSysmoduleUnloadModule(CELL_SYSMODULE_PNGDEC);
     290    err = cellSysmoduleUnloadModule(CELL_SYSMODULE_FS);
    152291#else
    153292    data->size = 256;
     
    184323#elif defined ANDROID_NDK
    185324    return data->pixels;
     325#elif defined __CELLOS_LV2__
     326    return data->pixels;
    186327#else
    187328    return data->pixels;
     
    206347    g_env->CallVoidMethod(g_ctx, mid, data->bmp);
    207348    g_env->DeleteGlobalRef(data->bmp);
     349#elif defined __CELLOS_LV2__
     350    free(data->pixels);
    208351#else
    209352    free(data->pixels);
Note: See TracChangeset for help on using the changeset viewer.