remove read/write rawpixels
Bug: skia: Change-Id: I000b70414119355fef0d45de4ae9ef996b8a5568 Reviewed-on: https://skia-review.googlesource.com/77903 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
This commit is contained in:
parent
8a90c4da1c
commit
efe7c49201
@ -1287,11 +1287,7 @@ private:
|
||||
void freePixels();
|
||||
void updatePixelsFromRef();
|
||||
|
||||
static void WriteRawPixels(SkWriteBuffer*, const SkBitmap&);
|
||||
static bool ReadRawPixels(SkReadBuffer*, SkBitmap*);
|
||||
|
||||
friend class SkReadBuffer; // unflatten, rawpixels
|
||||
friend class SkBinaryWriteBuffer; // rawpixels
|
||||
friend class SkReadBuffer; // unflatten
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -620,99 +620,6 @@ bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint,
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void write_raw_pixels(SkWriteBuffer* buffer, const SkPixmap& pmap) {
|
||||
const SkImageInfo& info = pmap.info();
|
||||
const size_t snugRB = info.width() * info.bytesPerPixel();
|
||||
const char* src = (const char*)pmap.addr();
|
||||
const size_t ramRB = pmap.rowBytes();
|
||||
|
||||
buffer->write32(SkToU32(snugRB));
|
||||
info.flatten(*buffer);
|
||||
|
||||
const size_t size = snugRB * info.height();
|
||||
SkAutoTMalloc<char> storage(size);
|
||||
char* dst = storage.get();
|
||||
for (int y = 0; y < info.height(); ++y) {
|
||||
memcpy(dst, src, snugRB);
|
||||
dst += snugRB;
|
||||
src += ramRB;
|
||||
}
|
||||
buffer->writeByteArray(storage.get(), size);
|
||||
// no colortable
|
||||
buffer->writeBool(false);
|
||||
}
|
||||
|
||||
void SkBitmap::WriteRawPixels(SkWriteBuffer* buffer, const SkBitmap& bitmap) {
|
||||
const SkImageInfo info = bitmap.info();
|
||||
if (0 == info.width() || 0 == info.height() || bitmap.isNull()) {
|
||||
buffer->writeUInt(0); // instead of snugRB, signaling no pixels
|
||||
return;
|
||||
}
|
||||
|
||||
SkPixmap result;
|
||||
if (!bitmap.peekPixels(&result)) {
|
||||
buffer->writeUInt(0); // instead of snugRB, signaling no pixels
|
||||
return;
|
||||
}
|
||||
|
||||
write_raw_pixels(buffer, result);
|
||||
}
|
||||
|
||||
bool SkBitmap::ReadRawPixels(SkReadBuffer* buffer, SkBitmap* bitmap) {
|
||||
if (0 == buffer->readUInt()) {
|
||||
return false; // no pixels
|
||||
}
|
||||
|
||||
SkImageInfo info;
|
||||
info.unflatten(*buffer);
|
||||
|
||||
if (info.width() < 0 || info.height() < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If there was an error reading "info" or if it is bogus,
|
||||
// don't use it to compute minRowBytes().
|
||||
if (!buffer->validate(SkColorTypeValidateAlphaType(info.colorType(),
|
||||
info.alphaType()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// write_raw_pixels() always writes snug buffers with rowBytes == minRowBytes().
|
||||
size_t bytes = info.computeMinByteSize();
|
||||
if (!buffer->validate(bytes != 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sk_sp<SkData> data(SkData::MakeUninitialized(bytes));
|
||||
unsigned char* dst = (unsigned char*)data->writable_data();
|
||||
if (!buffer->readByteArray(dst, bytes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffer->readBool()) {
|
||||
SkColorTable::Skip(*buffer);
|
||||
if (!buffer->isValid()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeWithData(info, info.minRowBytes(),
|
||||
std::move(data));
|
||||
if (!pr) {
|
||||
return false;
|
||||
}
|
||||
bitmap->setInfo(info);
|
||||
bitmap->setPixelRef(std::move(pr), 0, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
enum {
|
||||
SERIALIZE_PIXELTYPE_NONE,
|
||||
SERIALIZE_PIXELTYPE_REF_DATA
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void SkBitmap::validate() const {
|
||||
fInfo.validate();
|
||||
|
@ -242,13 +242,9 @@ sk_sp<SkImage> SkReadBuffer::readImage() {
|
||||
return MakeEmptyImage(width, height);
|
||||
}
|
||||
if (encoded_size == 1) {
|
||||
// We had to encode the image as raw pixels via SkBitmap.
|
||||
(void)this->readUInt(); // Swallow that encoded_size == 1 sentinel.
|
||||
SkBitmap bm;
|
||||
if (SkBitmap::ReadRawPixels(this, &bm)) {
|
||||
return SkImage::MakeFromBitmap(bm);
|
||||
}
|
||||
return MakeEmptyImage(width, height);
|
||||
// legacy check (we stopped writing this for "raw" images Nov-2017)
|
||||
this->validate(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// The SkImage encoded itself.
|
||||
|
@ -151,14 +151,6 @@ void SkBinaryWriteBuffer::writeImage(const SkImage* image) {
|
||||
write_encoded_bitmap(this, encoded.get(), SkIPoint::Make(0, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
SkBitmap bm;
|
||||
if (image->asLegacyBitmap(&bm, SkImage::kRO_LegacyBitmapMode)) {
|
||||
this->writeUInt(1); // signal raw pixels.
|
||||
SkBitmap::WriteRawPixels(this, bm);
|
||||
return;
|
||||
}
|
||||
|
||||
this->writeUInt(0); // signal no pixels (in place of the size of the encoded data)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user