/* * Copyright 2010 The Android Open Source Project * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/
// Different zlib implementations use different T. // We've seen size_t and unsigned. template <typename T> void* skia_alloc_func(void*, T items, T size) { if (!SkTFitsIn<size_t>(size)) { return nullptr;
} const size_t maxItems = SIZE_MAX / size; if (maxItems < items) { return nullptr;
} return sk_calloc_throw(SkToSizeT(items) * SkToSizeT(size));
}
#define SKDEFLATEWSTREAM_INPUT_BUFFER_SIZE 4096 #define SKDEFLATEWSTREAM_OUTPUT_BUFFER_SIZE 4224 // 4096 + 128, usually big // enough to always do a // single loop.
// called by both write() and finalize() staticvoid do_deflate(int flush,
z_stream* zStream,
SkWStream* out, unsignedchar* inBuffer,
size_t inBufferSize) {
zStream->next_in = inBuffer;
zStream->avail_in = SkToInt(inBufferSize); unsignedchar outBuffer[SKDEFLATEWSTREAM_OUTPUT_BUFFER_SIZE];
SkDEBUGCODE(int returnValue;) do {
zStream->next_out = outBuffer;
zStream->avail_out = sizeof(outBuffer);
SkDEBUGCODE(returnValue =) deflate(zStream, flush);
SkASSERT(!zStream->msg);
SkDeflateWStream::SkDeflateWStream(SkWStream* out, int compressionLevel, bool gzip)
: fImpl(std::make_unique<SkDeflateWStream::Impl>()) {
// There has existed at some point at least one zlib implementation which thought it was being // clever by randomizing the compression level. This is actually not entirely incorrect, except // for the no-compression level which should always be deterministically pass-through. // Users should instead consider the zero compression level broken and handle it themselves.
SkASSERT(compressionLevel != 0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.