| 204 | } |
| 205 | |
| 206 | void PiuImage_create(xsMachine* the) |
| 207 | { |
| 208 | PiuImage* self; |
| 209 | void* archive = NULL; |
| 210 | xsStringValue path; |
| 211 | uint8_t* data; |
| 212 | size_t dataSize; |
| 213 | xsIntegerValue frameCount; |
| 214 | ColorCellHeader cch; |
| 215 | xsVars(4); |
| 216 | xsSetHostChunk(xsThis, NULL, sizeof(PiuImageRecord)); |
| 217 | self = PIU(Image, xsThis); |
| 218 | (*self)->the = the; |
| 219 | (*self)->reference = xsToReference(xsThis); |
| 220 | xsSetHostHooks(xsThis, (xsHostHooks*)&PiuImageHooks); |
| 221 | (*self)->dispatch = (PiuDispatch)&PiuImageDispatchRecord; |
| 222 | (*self)->recordSize = PiuRecordSize(sizeof(PiuImageRecord)); |
| 223 | (*self)->flags = piuVisible; |
| 224 | PiuContentDictionary(the, self); |
| 225 | PiuImageDictionary(the, self); |
| 226 | if ((*self)->archive) { |
| 227 | xsResult = xsReference((*self)->archive); |
| 228 | archive = xsGetHostData(xsResult); |
| 229 | } |
| 230 | path = PiuToString((*self)->path); |
| 231 | data = (uint8_t *)fxGetResource(the, archive, path, &dataSize); |
| 232 | if (!data) |
| 233 | xsURIError("image not found: %s", path); |
| 234 | cch = (ColorCellHeader)data; |
| 235 | if (('c' != c_read8(&cch->id_c)) || ('s' != c_read8(&cch->id_s))) |
| 236 | xsUnknownError("invalid image data"); |
| 237 | (*self)->frameFormat = c_read8(&cch->bitmapFormat); |
| 238 | if (0 != c_read8(&cch->reserved)) |
| 239 | xsUnknownError("invalid image reserved"); |
| 240 | (*self)->data = data; |
| 241 | (*self)->dataSize = (uint32_t)dataSize; |
| 242 | #if (90 == kPocoRotation) || (270 == kPocoRotation) |
| 243 | (*self)->dataWidth = c_read16(&cch->height); |
| 244 | (*self)->dataHeight = c_read16(&cch->width); |
| 245 | #else |
| 246 | (*self)->dataWidth = c_read16(&cch->width); |
| 247 | (*self)->dataHeight = c_read16(&cch->height); |
| 248 | #endif |
| 249 | (*self)->frameIndex = 0; |
| 250 | (*self)->frameOffset = sizeof(ColorCellHeaderRecord); |
| 251 | (*self)->frameSize = c_read16(data + sizeof(ColorCellHeaderRecord)); |
| 252 | #ifdef piuGPU |
| 253 | (*self)->frameID = ++gFrameID; |
| 254 | (*self)->frameChanged = 0; |
| 255 | if ((*self)->frameFormat == kCommodettoBitmapRGB565LE) |
| 256 | (*self)->frameFormat |= kCommodettoBitmapPacked; |
| 257 | #else |
| 258 | if ((*self)->frameFormat != kCommodettoBitmapRGB565LE) |
| 259 | xsUnknownError("invalid image pixel format"); |
| 260 | #endif |
| 261 | frameCount = (*self)->frameCount = c_read16(&cch->frameCount); |
| 262 | if (frameCount > 1) { |
| 263 | uint16_t fps_numerator = c_read16(&cch->fps_numerator); |
nothing calls this directly
no test coverage detected