Changeset 833
- Timestamp:
- Aug 17, 2011, 7:13:48 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/monsterz/ps3/Makefile
r828 r833 23 23 PPU_LDLIBS += -lcgc -lPSGLcgc 24 24 25 # For the PNG decoder 26 PPU_LDLIBS += -lpngdec_stub 27 25 28 include $(CELL_SDK)/samples/sdk/graphics/psgl/MakeRules 26 29 -
trunk/src/image.cpp
r758 r833 23 23 # include <jni.h> 24 24 # include <android/log.h> 25 #elif defined __CELLOS_LV2__ 26 # include <cell/sysmodule.h> 27 # include <cell/codec/pngdec.h> 25 28 #endif 26 29 … … 57 60 jintArray array; 58 61 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; 59 66 #else 60 67 uint8_t *pixels; … … 70 77 { 71 78 #if defined __APPLE__ && defined __MACH__ 72 73 74 75 76 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]; 77 84 NSString *mypath = [[NSBundle mainBundle] pathForResource:prefix ofType:@"png"]; 78 85 NSData *pngdata = [[NSData alloc] initWithContentsOfFile:mypath]; … … 150 157 } 151 158 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); 152 291 #else 153 292 data->size = 256; … … 184 323 #elif defined ANDROID_NDK 185 324 return data->pixels; 325 #elif defined __CELLOS_LV2__ 326 return data->pixels; 186 327 #else 187 328 return data->pixels; … … 206 347 g_env->CallVoidMethod(g_ctx, mid, data->bmp); 207 348 g_env->DeleteGlobalRef(data->bmp); 349 #elif defined __CELLOS_LV2__ 350 free(data->pixels); 208 351 #else 209 352 free(data->pixels);
Note: See TracChangeset
for help on using the changeset viewer.