void VJSImage::_save(XBOX::VJSParms_callStaticFunction& ioParms, VJSPictureContainer* inPict) { VPictureCodecFactoryRef fact; const VPictureCodec* encoder = nil; bool ok = false; VPicture* pic = inPict->GetPict(); if (pic != nil) { VFile* file = ioParms.RetainFileParam(1); if (file != nil) { VString mimetype; ioParms.GetStringParam(2, mimetype); if (mimetype.IsEmpty()) { VString extension; file->GetExtension(extension); if (extension.IsEmpty()) extension = L"pic"; encoder = fact->RetainEncoderForExtension(extension); } else encoder = fact->RetainEncoderByIdentifier(mimetype); if (encoder != nil) { VError err = VE_OK; if (file->Exists()) err = file->Delete(); if (err == VE_OK) { VValueBag *pictureSettings = nil; VValueBag *bagMetas = (VValueBag*)inPict->RetainMetaBag(); if (bagMetas != nil) { pictureSettings = new VValueBag(); ImageEncoding::stWriter settingsWriter(pictureSettings); VValueBag *bagRetained = settingsWriter.CreateOrRetainMetadatas( bagMetas); if (bagRetained) bagRetained->Release(); } err=encoder->Encode(*pic, pictureSettings, *file); QuickReleaseRefCountable(bagMetas); QuickReleaseRefCountable(pictureSettings); if (err == VE_OK) ok = true; } encoder->Release(); } file->Release(); } else vThrowError(VE_JVSC_WRONG_PARAMETER_TYPE_FILE, "1"); } ioParms.ReturnBool(ok); }
void VJSImage::_setPath(XBOX::VJSParms_callStaticFunction& ioParms, VJSPictureContainer* inPict) { VPicture* pic = inPict->GetPict(); VString path; if (pic != nil) { if (ioParms.CountParams() == 0 || ioParms.IsNullParam(1)) { pic->SetOutsidePath(""); // empty string means no outside } else if (ioParms.IsBooleanParam(1)) { pic->SetOutsidePath("*"); } else if (ioParms.IsStringParam(1)) { ioParms.GetStringParam(1, path); pic->SetOutsidePath(path); if (!path.IsEmpty()) pic->ReloadFromOutsidePath(); } else { VFile* file = ioParms.RetainFileParam(1); if (file != nil) { file->GetPath(path, FPS_POSIX); pic->SetOutsidePath(path); if (file->Exists()) pic->ReloadFromOutsidePath(); } else pic->SetOutsidePath(""); QuickReleaseRefCountable(file); } //inPict->SetModif(); } }