57ae6cfe01
This reverts commit c73a1ecbed
.
Reason for revert: ANGLE and CommandBuffer failures
Original change's description:
> Support decoding images to multiple formats, depending on usage
>
> Our codec generator will now preserve any asked-for color space, and
> convert the encoded data to that representation. Cacherator now
> allows decoding an image to both legacy (nullptr color space), and
> color-correct formats. In color-correct mode, we choose the best
> decoded format, based on the original properties, and our backend's
> capabilities. Preference is given to the native format, when it's
> already texturable (sRGB 8888 or F16 linear). Otherwise, we prefer
> linear F16, and fall back to sRGB when that's not an option.
>
> BUG=skia:5907
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4438
>
> Change-Id: I847c243dcfb72d8c0f1f6fc73c09547adea933f0
> Reviewed-on: https://skia-review.googlesource.com/4438
> Reviewed-by: Matt Sarett <msarett@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
>
TBR=mtklein@google.com,bsalomon@google.com,msarett@google.com,brianosman@google.com,reed@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: I1818f937464573d601f64e5a1f1eb43f5a778f4e
Reviewed-on: https://skia-review.googlesource.com/4832
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
59 lines
1.8 KiB
C++
59 lines
1.8 KiB
C++
/*
|
|
* Copyright 2014 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Resources.h"
|
|
#include "SkBitmap.h"
|
|
#include "SkCommandLineFlags.h"
|
|
#include "SkData.h"
|
|
#include "SkImage.h"
|
|
#include "SkImageGenerator.h"
|
|
#include "SkOSFile.h"
|
|
#include "SkOSPath.h"
|
|
#include "SkStream.h"
|
|
#include "SkTypeface.h"
|
|
|
|
DEFINE_string2(resourcePath, i, "resources", "Directory with test resources: images, fonts, etc.");
|
|
|
|
SkString GetResourcePath(const char* resource) {
|
|
return SkOSPath::Join(FLAGS_resourcePath[0], resource);
|
|
}
|
|
|
|
void SetResourcePath(const char* resource) {
|
|
FLAGS_resourcePath.set(0, resource);
|
|
}
|
|
|
|
bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) {
|
|
SkString resourcePath = GetResourcePath(resource);
|
|
sk_sp<SkData> resourceData(SkData::MakeFromFileName(resourcePath.c_str()));
|
|
std::unique_ptr<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(resourceData.get()));
|
|
return gen && gen->tryGenerateBitmap(dst);
|
|
}
|
|
|
|
sk_sp<SkImage> GetResourceAsImage(const char* resource) {
|
|
SkString path = GetResourcePath(resource);
|
|
sk_sp<SkData> resourceData(SkData::MakeFromFileName(path.c_str()));
|
|
return SkImage::MakeFromEncoded(resourceData);
|
|
}
|
|
|
|
SkStreamAsset* GetResourceAsStream(const char* resource) {
|
|
SkString resourcePath = GetResourcePath(resource);
|
|
std::unique_ptr<SkFILEStream> stream(new SkFILEStream(resourcePath.c_str()));
|
|
if (!stream->isValid()) {
|
|
SkDebugf("Resource %s not found.\n", resource);
|
|
return nullptr;
|
|
}
|
|
return stream.release();
|
|
}
|
|
|
|
sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) {
|
|
std::unique_ptr<SkStreamAsset> stream(GetResourceAsStream(resource));
|
|
if (!stream) {
|
|
return nullptr;
|
|
}
|
|
return SkTypeface::MakeFromStream(stream.release());
|
|
}
|