void setFont(SkPaint* paint) override { if (!fTypeface) { SkString filename = GetResourcePath("/Funkster.ttf"); SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str())); if (!stream->isValid()) { SkDebugf("Could not find Funkster.ttf, please set --resourcePath " "correctly.\n"); return; } fTypeface.reset(SkTypeface::CreateFromStream(stream.detach())); } paint->setTypeface(fTypeface); }
DRAW_TEST_F(CGContext, DrawAnImageWithInterpolationQuality, UIKitMimicTest<>) { auto drawingConfig = DrawingTestConfig::Get(); woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath("png1.9.png")) }; woc::unique_cf<CGImageRef> image{ _CGImageCreateFromPNGFile(testFilename.get()) }; ASSERT_NE(image, nullptr); CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); CGContextSetInterpolationQuality(context, kCGInterpolationLow); CGContextDrawImage(context, bounds, image.get()); }
DEF_TEST(Codec_raw_notseekable, r) { const char* path = "dng_with_preview.dng"; SkString fullPath(GetResourcePath(path)); SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str())); if (!data) { SkDebugf("Missing resource '%s'\n", path); return; } SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(data))); REPORTER_ASSERT(r, codec); test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); }
void ApConfig::CheckResourcePath( const BtChar *name ) { BtChar filename[256]; sprintf( filename, "%s%s%s", GetResourcePath(), name, ApConfig::GetExtension() ); FILE *f = fopen( filename, "rb" ); printf( "Filename %s", filename ); if( f != BtNull ) { fclose(f); } else { BtStrCopy( m_resourcePath, 256, "" ); } }
/** * A test for the SkDecodingImageGenerator::Create and * SkInstallDiscardablePixelRef functions. */ DEF_TEST(ImprovedBitmapFactory, reporter) { SkString resourcePath = GetResourcePath(); SkString path = SkOSPath::SkPathJoin( resourcePath.c_str(), "randPixels.png"); SkAutoTUnref<SkStreamRewindable> stream( SkStream::NewFromFile(path.c_str())); if (sk_exists(path.c_str())) { SkBitmap bm; SkAssertResult(bm.setInfo(SkImageInfo::MakeN32Premul(1, 1))); REPORTER_ASSERT(reporter, NULL != install_pixel_ref(&bm, stream.detach(), 1, true)); SkAutoLockPixels alp(bm); REPORTER_ASSERT(reporter, NULL != bm.getPixels()); } }
void onOnceBeforeDraw() override { SkImageDecoder* codec = nullptr; SkString resourcePath = GetResourcePath("mandrill_512.png"); SkFILEStream stream(resourcePath.c_str()); if (stream.isValid()) { codec = SkImageDecoder::Factory(&stream); } if (codec) { stream.rewind(); codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); delete codec; } else { fBM.allocN32Pixels(1, 1); fBM.eraseARGB(255, 255, 0 , 0); // red == bad } }
lua_State* ensureLua() { if (NULL == fLua) { fLua = SkNEW(SkLua); SkString str = GetResourcePath(LUA_FILENAME); SkData* data = SkData::NewFromFileName(str.c_str()); if (data) { fLua->runCode(data->data(), data->size()); data->unref(); this->setImageFilename(fLua->get()); } else { fLua->runCode(gMissingCode); } } return fLua->get(); }
void URLLoader::initialize(const char *inCACertFilePath) { #ifdef HX_WINDOWS unsigned int flags = CURL_GLOBAL_WIN32; #else unsigned int flags = 0; #endif curl_global_init(flags | CURL_GLOBAL_SSL); sCACertFile = std::string(inCACertFilePath); #ifdef TRY_GET_FILE get_file_callback = sGetFile; #endif /* Set to 1 to print version information for libcurl. */ if (!sCACertFile.empty()) { FILE *f = fopen(sCACertFile.c_str(),"rb"); bool loaded = f; if (f) fclose(f); ELOG("Open cert file: %s %s\n", sCACertFile.c_str(), loaded ? "Yes" : "NO!!" ); #ifdef IPHONE if (!loaded) { sCACertFile = GetResourcePath() + gAssetBase + inCACertFilePath; FILE *f = fopen(sCACertFile.c_str(),"rb"); loaded = f; if (f) fclose(f); ELOG("Open cert file: %s %s\n", sCACertFile.c_str(), loaded ? "Yes" : "NO!!" ); } #endif } #if 0 curl_version_info_data * info = curl_version_info(CURLVERSION_NOW); ELOG("SSL cert: %s\n", inCACertFilePath); ELOG("libcurl version: %s\n", info->version); ELOG("Support for SSL in libcurl: %d\n", (info->features) & CURL_VERSION_SSL); ELOG("Supported libcurl protocols: "); for (int i=0; info->protocols[i] != 0; i++) { ELOG(" protocol %d: %s",i, info->protocols[i]); } #endif }
std::string Shader::LoadFile(std::string n_path) { std::cout << "loading " << n_path << std::endl; // then no file was specified if( n_path == GetResourcePath("") ) return ""; std::fstream tmp_inputFile(n_path,std::ios::in); if( tmp_inputFile.is_open() ) { std::stringstream tmp_buffer; tmp_buffer << tmp_inputFile.rdbuf(); return tmp_buffer.str(); } else throw std::string("file not found: ") + n_path; }
void makeBitmap() { SkImageDecoder* codec = NULL; SkString resourcePath = GetResourcePath(fFilename.c_str()); SkFILEStream stream(resourcePath.c_str()); if (stream.isValid()) { codec = SkImageDecoder::Factory(&stream); } if (codec) { stream.rewind(); codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); SkDELETE(codec); } else { fBM.allocN32Pixels(1, 1); *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad } fSize = fBM.height(); }
DRAW_TEST_F(CGImageDrawing, DrawAnImage, UIKitMimicTest<>) { // Load an Image and draw it into the canvas context auto drawingConfig = DrawingTestConfig::Get(); woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath("jpg1.jpg")) }; woc::unique_cf<CGImageRef> image{ _CGImageCreateFromJPEGFile(testFilename.get()) }; ASSERT_NE(image, nullptr); CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); CGAffineTransform flip = CGAffineTransformMakeScale(1, -1); CGAffineTransform shift = CGAffineTransformTranslate(flip, 0, bounds.size.height * -1); CGContextConcatCTM(context, shift); CGContextDrawImage(context, bounds, image.get()); }
void onDraw(SkCanvas* canvas) override { SkBitmap bm; SkString filename = GetResourcePath("mandrill_128."); filename.append(this->fileExtension()); SkAutoTUnref<SkData> fileData(SkData::NewFromFileName(filename.c_str())); if (nullptr == fileData) { SkDebugf("Could not open the file. Did you forget to set the resourcePath?\n"); return; } if (!SkInstallDiscardablePixelRef(fileData, &bm)) { SkDebugf("Could not install discardable pixel ref.\n"); return; } canvas->drawBitmap(bm, 0, 0); }
int Sprite::Init() { Data* d = m_originalData; if ( d->m_path != "" ) { std::string imagePath = GetResourcePath() + d->m_path; d->m_texture = textureCache->GetTexture( imagePath ); if ( !d->m_texture ) { return 1; } } return super::Init(); }
void UserScript::Delete () { QSettings settings (QCoreApplication::organizationName (), QCoreApplication::applicationName () + "_Poshuku_FatApe"); settings.remove (QString ("storage/%1/%2") .arg (qHash (Namespace ())) .arg (Name ())); settings.remove (QString ("resources/%1/%2") .arg (qHash (Namespace ())) .arg (Name ())); settings.remove (QString ("disabled/%1%2") .arg (qHash (Namespace ())) .arg (Name ())); Q_FOREACH (const QString& resource, Metadata_.values ("resource")) QFile::remove (GetResourcePath (resource.mid (0, resource.indexOf (" ")))); QFile::remove (ScriptPath_); }
// Verify that a webp image can be animated scaled down. This image has a // kRestoreBG frame, so it is an interesting image to test. After decoding that // frame, we have to erase its rectangle. The rectangle has to be adjusted // based on the scaled size. DEF_TEST(AndroidCodec_animated, r) { if (GetResourcePath().isEmpty()) { return; } const char* file = "images/required.webp"; sk_sp<SkData> data(GetResourceAsData(file)); if (!data) { ERRORF(r, "Missing %s", file); return; } auto codec = SkAndroidCodec::MakeFromCodec(SkCodec::MakeFromData(std::move(data))); if (!codec) { ERRORF(r, "Failed to decode %s", file); return; } auto info = codec->getInfo().makeAlphaType(kPremul_SkAlphaType); for (int sampleSize : { 8, 32, 100 }) { auto dimensions = codec->codec()->getScaledDimensions(1.0f / sampleSize); info = info.makeWH(dimensions.width(), dimensions.height()); SkBitmap bm; bm.allocPixels(info); SkCodec::Options options; for (int i = 0; i < codec->codec()->getFrameCount(); ++i) { SkCodec::FrameInfo frameInfo; REPORTER_ASSERT(r, codec->codec()->getFrameInfo(i, &frameInfo)); if (5 == i) { REPORTER_ASSERT(r, frameInfo.fDisposalMethod == SkCodecAnimation::DisposalMethod::kRestoreBGColor); } options.fFrameIndex = i; options.fPriorFrame = i - 1; info = info.makeAlphaType(frameInfo.fAlphaType); const auto result = codec->codec()->getPixels(info, bm.getPixels(), bm.rowBytes(), &options); REPORTER_ASSERT(r, result == SkCodec::kSuccess); } } }
DEF_TEST(StreamPeek, reporter) { // Test a memory stream. const char gAbcs[] = "abcdefghijklmnopqrstuvwxyz"; SkMemoryStream memStream(gAbcs, strlen(gAbcs), false); test_peeking_stream(reporter, &memStream, memStream.getLength()); // Test an arbitrary file stream. file streams do not support peeking. SkFILEStream fileStream(GetResourcePath("baby_tux.webp").c_str()); REPORTER_ASSERT(reporter, fileStream.isValid()); SkAutoMalloc storage(fileStream.getLength()); for (size_t i = 1; i < fileStream.getLength(); i++) { REPORTER_ASSERT(reporter, !fileStream.peek(storage.get(), i)); } // Now test some FrontBufferedStreams for (size_t i = 1; i < memStream.getLength(); i++) { test_peeking_front_buffered_stream(reporter, memStream, i); } }
static void test_unpremul(skiatest::Reporter* reporter) { // This test cannot run if there is no resource path. SkString resourcePath = GetResourcePath(); if (resourcePath.isEmpty()) { SkDebugf("Could not run unpremul test because resourcePath not specified."); return; } SkOSFile::Iter iter(resourcePath.c_str()); SkString basename; if (iter.next(&basename)) { do { SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), basename.c_str()); // SkDebugf("about to decode \"%s\"\n", filename.c_str()); compare_unpremul(reporter, filename); } while (iter.next(&basename)); } else { SkDebugf("Failed to find any files :(\n"); } }
void wxFlushResources (void) { char nameBuffer[512]; wxNode *node = wxResourceCache.First (); while (node) { const char *file = node->GetKeyString(); // If file doesn't exist, create it first. (void)GetResourcePath(nameBuffer, file, true); XrmDatabase database = (XrmDatabase) node->Data (); XrmPutFileDatabase (database, nameBuffer); XrmDestroyDatabase (database); wxNode *next = node->Next (); delete node; node = next; } }
DISABLED_DRAW_TEST_F(CGImageDrawing, DrawIntoRect, UIKitMimicTest<>) { // Draw a portion of an image into a different region. auto drawingConfig = DrawingTestConfig::Get(); woc::unique_cf<CFStringRef> testFilename{ _CFStringCreateWithStdString(drawingConfig->GetResourcePath("png3.9.png")) }; woc::unique_cf<CGImageRef> image{ _CGImageCreateFromPNGFile(testFilename.get()) }; ASSERT_NE(image, nullptr); CGContextRef context = GetDrawingContext(); CGRect bounds = GetDrawingBounds(); CGAffineTransform flip = CGAffineTransformMakeScale(1, -1); CGAffineTransform shift = CGAffineTransformTranslate(flip, 0, bounds.size.height * -1); CGContextConcatCTM(context, shift); _CGContextDrawImageRect(context, image.get(), { 0, 0, bounds.size.width / 4, bounds.size.height / 4 }, { 0, 0, bounds.size.width, bounds.size.height }); }
virtual void onOnceBeforeDraw() override { SkString filename = GetResourcePath("/Funkster.ttf"); SkAutoTDelete<SkFILEStream> stream(new SkFILEStream(filename.c_str())); if (stream->isValid()) { fCBDT_CBLC_Typeface.reset(SkTypeface::CreateFromStream(stream.detach())); emojiFonts[0].typeface = fCBDT_CBLC_Typeface; } else { SkDebugf("Could not find Funkster.ttf, please set --resourcePath correctly.\n"); emojiFonts[0].typeface = NULL; } emojiFonts[0].text = "hamburgerfons"; fSBIX_Typeface.reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal)); emojiFonts[1].typeface = fSBIX_Typeface; emojiFonts[1].text = "\xF0\x9F\x92\xB0" "\xF0\x9F\x8F\xA1" "\xF0\x9F\x8E\x85" // 💰🏡🎅 "\xF0\x9F\x8D\xAA" "\xF0\x9F\x8D\x95" "\xF0\x9F\x9A\x80" // 🍪🍕🚀 "\xF0\x9F\x9A\xBB" "\xF0\x9F\x92\xA9" "\xF0\x9F\x93\xB7" // 🚻💩📷 "\xF0\x9F\x93\xA6" // 📦 "\xF0\x9F\x87\xBA" "\xF0\x9F\x87\xB8" "\xF0\x9F\x87\xA6"; // 🇺🇸🇦 }
bool FSlateD3DTextureManager::LoadTexture( const FSlateBrush& InBrush, uint32& OutWidth, uint32& OutHeight, TArray<uint8>& OutDecodedImage ) { FString ResourcePath = GetResourcePath( InBrush ); uint32 BytesPerPixel = 4; bool bSucceeded = true; TArray<uint8> RawFileData; if( FFileHelper::LoadFileToArray( RawFileData, *ResourcePath ) ) { IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>( FName("ImageWrapper") ); IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper( EImageFormat::PNG ); if ( ImageWrapper.IsValid() && ImageWrapper->SetCompressed( RawFileData.GetData(), RawFileData.Num() ) ) { OutWidth = ImageWrapper->GetWidth(); OutHeight = ImageWrapper->GetHeight(); const TArray<uint8>* RawData = NULL; if (ImageWrapper->GetRaw(ERGBFormat::RGBA, 8, RawData) == false) { UE_LOG(LogSlateD3D, Log, TEXT("Invalid texture format for Slate resource only RGBA and RGB pngs are supported: %s"), *InBrush.GetResourceName().ToString() ); bSucceeded = false; } else { OutDecodedImage = *RawData; } } else { UE_LOG(LogSlateD3D, Log, TEXT("Only pngs are supported in Slate")); bSucceeded = false; } } else { UE_LOG(LogSlateD3D, Log, TEXT("Could not find file for Slate resource: %s"), *InBrush.GetResourceName().ToString() ); bSucceeded = false; } return bSucceeded; }
// Test that even if webp_parse_header fails to peek enough, it will fall back to read() // + rewind() and succeed. DEF_TEST(Codec_webp_peek, r) { const char* path = "baby_tux.webp"; SkString fullPath(GetResourcePath(path)); SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str())); if (!data) { SkDebugf("Missing resource '%s'\n", path); return; } // The limit is less than webp needs to peek or read. SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new LimitedPeekingMemStream(data, 25))); REPORTER_ASSERT(r, codec); test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); // Similarly, a stream which does not peek should still succeed. codec.reset(SkCodec::NewFromStream(new LimitedPeekingMemStream(data, 0))); REPORTER_ASSERT(r, codec); test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); }
DEF_TEST(ImageDecoding_alphaType, reporter) { SkString resourcePath = GetResourcePath(); if (resourcePath.isEmpty()) { SkDebugf("Could not run alphaType test because resourcePath not specified."); return; } SkOSFile::Iter iter(resourcePath.c_str()); SkString basename; if (iter.next(&basename)) { do { SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), basename.c_str()); for (int truth = 0; truth <= 1; ++truth) { test_alphaType(reporter, filename, SkToBool(truth)); } } while (iter.next(&basename)); } else { SkDebugf("Failed to find any files :(\n"); } }
static void generate_fonts(FILE* out) { for (int index = 0; index < gFontsCount; ++index) { FontDesc& fontDesc = gFonts[index]; int fontIndex = written_index(fontDesc); if (fontIndex >= 0) { fontDesc.fFontIndex = fontIndex; continue; } SkTypeface* systemTypeface = SkTypeface::CreateFromName(fontDesc.fFont, fontDesc.fStyle); SkASSERT(systemTypeface); SkString filepath(GetResourcePath(fontDesc.fFile)); SkASSERT(sk_exists(filepath.c_str())); SkTypeface* resourceTypeface = SkTypeface::CreateFromFile(filepath.c_str()); SkASSERT(resourceTypeface); output_font(resourceTypeface, fontDesc.fFont, fontDesc.fStyle, fontDesc.fCharsUsed, out); fontDesc.fFontIndex = gWritten.count(); FontWritten* writ = gWritten.append(); writ->fName = fontDesc.fFont; writ->fStyle = fontDesc.fStyle; } }
SubpixelTranslateView(const char imageFilename[], float horizontalVelocity, float verticalVelocity) : fHorizontalVelocity(horizontalVelocity), fVerticalVelocity(verticalVelocity) { SkString resourcePath = GetResourcePath(imageFilename); SkImageDecoder* codec = NULL; SkFILEStream stream(resourcePath.c_str()); if (stream.isValid()) { codec = SkImageDecoder::Factory(&stream); } if (codec) { stream.rewind(); codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode); delete codec; } else { fBM.allocN32Pixels(1, 1); *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad } fCurPos = SkPoint::Make(0,0); fSize = 200; }
// Never returns NULL ("" means no langpack defined) WDL_FastString* GetLangPack() { // lazy init, works because swtching LangPacks requires REAPER restart if (!g_LangPack) { g_LangPack = new WDL_FastString; #ifdef _SWS_LOCALIZATION char fn[BUFFER_SIZE] = ""; GetPrivateProfileString("REAPER", "langpack", "", fn, sizeof(fn), get_ini_file()); if (*fn && strcmp(fn, "<>")) { g_LangPack->Set(fn); if (!FileExists(fn)) // retry with fn as "short name" { g_LangPack->SetFormatted(BUFFER_SIZE, "%s%cLangPack%c%s", GetResourcePath(), PATH_SLASH_CHAR, PATH_SLASH_CHAR, fn); if (!FileExists(g_LangPack->Get())) // does not exist either.. g_LangPack->Set(""); } } #endif } return g_LangPack; }
void Resource::WriteTreeInfo(ResourceWriter& writer) { // write the resource path as a comment writer.WriteString(" // "); writer.WriteString(GetResourcePath()); writer.WriteString("\n "); if (flags & Directory) { // name offset (in the us_resource_name array) writer.WriteNumber4(static_cast<uint32_t>(nameOffset)); // flags writer.WriteNumber2(flags); // child count writer.WriteNumber4(static_cast<uint32_t>(children.size())); // first child offset (in the us_resource_tree array) writer.WriteNumber4(static_cast<uint32_t>(childOffset)); } else { // name offset writer.WriteNumber4(static_cast<uint32_t>(nameOffset)); // flags writer.WriteNumber2(flags); // padding (not used) writer.WriteNumber4(0); // data offset writer.WriteNumber4(static_cast<uint32_t>(dataOffset)); } writer.WriteChar('\n'); }
// Regression test for decoding a gif image with sampleSize of 4, which was // previously crashing. DEF_TEST(Gif_Sampled, r) { SkAutoTDelete<SkFILEStream> stream( new SkFILEStream(GetResourcePath("test640x479.gif").c_str())); REPORTER_ASSERT(r, stream->isValid()); if (!stream->isValid()) { return; } SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release())); REPORTER_ASSERT(r, codec); if (!codec) { return; } // Construct a color table for the decode if necessary SkAutoTUnref<SkColorTable> colorTable(nullptr); SkPMColor* colorPtr = nullptr; int* colorCountPtr = nullptr; int maxColors = 256; if (kIndex_8_SkColorType == codec->getInfo().colorType()) { SkPMColor colors[256]; colorTable.reset(new SkColorTable(colors, maxColors)); colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); colorCountPtr = &maxColors; } SkAndroidCodec::AndroidOptions options; options.fSampleSize = 4; options.fColorPtr = colorPtr; options.fColorCount = colorCountPtr; SkBitmap bm; bm.allocPixels(codec->getInfo(), nullptr, colorTable.get()); const SkCodec::Result result = codec->getAndroidPixels(codec->getInfo(), bm.getPixels(), bm.rowBytes(), &options); REPORTER_ASSERT(r, result == SkCodec::kSuccess); }
static SkView* MyFactory() { return new UnpremulView(GetResourcePath()); }
static SkStreamAsset* resource(const char path[]) { SkString fullPath = GetResourcePath(path); return SkStream::NewFromFile(fullPath.c_str()); }