Skip to content

Commit

Permalink
Remove SK_PDF_BASE85_BINARY and SK_PDF_LESS_COMPRESSION
Browse files Browse the repository at this point in the history
If people want to debug pdfs, using something like `qpdf --qdf` is
the preferred way to do it instead of this (potentially) bitrotting
code.

Change-Id: I9e5bb0de8c8e608043c1c3467c1e78c14e0c266a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/928452
Commit-Queue: Kaylee Lubick <kjlubick@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Kaylee Lubick <kjlubick@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
  • Loading branch information
kjlubick authored and SkCQ committed Dec 11, 2024
1 parent b2f13d9 commit 830bc24
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 89 deletions.
4 changes: 1 addition & 3 deletions experimental/tools/pdf-comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ def checkout_worktree(checkoutable):
return directory

def build_skia(directory, executable):
args = ('--args=is_debug=false'
' extra_cflags=["-DSK_PDF_LESS_COMPRESSION",'
' "-DSK_PDF_BASE85_BINARY"] ')
args = ('--args=is_debug=false')
if test_exe('ccache'):
args += ' cc_wrapper="ccache"'
args += EXTRA_GN_ARGS
Expand Down
22 changes: 0 additions & 22 deletions src/pdf/SkPDFBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,11 @@ void emit_image_stream(SkPDFDocument* doc,
pdfDict.insertRef("SMask", sMask);
}
pdfDict.insertInt("BitsPerComponent", 8);
#ifdef SK_PDF_BASE85_BINARY
auto filters = SkPDFMakeArray();
filters->appendName("ASCII85Decode");
switch (format) {
case SkPDFStreamFormat::DCT: filters->appendName("DCTDecode"); break;
case SkPDFStreamFormat::Flate: filters->appendName("FlateDecode"); break;
case SkPDFStreamFormat::Uncompressed: break;
}
pdfDict.insertObject("Filter", std::move(filters));
#else
switch (format) {
case SkPDFStreamFormat::DCT: pdfDict.insertName("Filter", "DCTDecode"); break;
case SkPDFStreamFormat::Flate: pdfDict.insertName("Filter", "FlateDecode"); break;
case SkPDFStreamFormat::Uncompressed: break;
}
#endif
if (format == SkPDFStreamFormat::DCT) {
pdfDict.insertInt("ColorTransform", 0);
}
Expand Down Expand Up @@ -175,9 +164,6 @@ void do_deflated_alpha(const SkPixmap& pm, SkPDFDocument* doc, SkPDFIndirectRefe
deflateWStream->finalize();
}

#ifdef SK_PDF_BASE85_BINARY
SkPDFUtils::Base85Encode(buffer.detachAsStream(), &buffer);
#endif
int length = SkToInt(buffer.bytesWritten());
emit_image_stream(doc, ref, [&buffer](SkWStream* stream) { buffer.writeToAndReset(stream); },
pm.info().dimensions(), SkPDFUnion::Name("DeviceGray"),
Expand Down Expand Up @@ -288,9 +274,6 @@ void do_deflated_image(const SkPixmap& pm,
}
}

#ifdef SK_PDF_BASE85_BINARY
SkPDFUtils::Base85Encode(buffer.detachAsStream(), &buffer);
#endif
int length = SkToInt(buffer.bytesWritten());
emit_image_stream(doc, ref, [&buffer](SkWStream* stream) { buffer.writeToAndReset(stream); },
pm.info().dimensions(), std::move(colorSpace), sMask, length, format);
Expand Down Expand Up @@ -321,11 +304,6 @@ bool do_jpeg(sk_sp<SkData> data, SkColorSpace* imageColorSpace, SkPDFDocument* d
|| kTopLeft_SkEncodedOrigin != exifOrientation) {
return false;
}
#ifdef SK_PDF_BASE85_BINARY
SkDynamicMemoryWStream buffer;
SkPDFUtils::Base85Encode(SkMemoryStream::MakeDirect(data->data(), data->size()), &buffer);
data = buffer.detachAsData();
#endif

int channels = yuv ? 3 : 1;
SkPDFUnion colorSpace = yuv ? SkPDFUnion::Name("DeviceRGB") : SkPDFUnion::Name("DeviceGray");
Expand Down
12 changes: 0 additions & 12 deletions src/pdf/SkPDFTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,25 +561,13 @@ static void serialize_stream(SkPDFDict* origDict,
SkDeflateWStream deflateWStream(&compressedData,SkToInt(doc->metadata().fCompressionLevel));
SkStreamCopy(&deflateWStream, stream);
deflateWStream.finalize();
#ifdef SK_PDF_BASE85_BINARY
{
SkPDFUtils::Base85Encode(compressedData.detachAsStream(), &compressedData);
tmp = compressedData.detachAsStream();
stream = tmp.get();
auto filters = SkPDFMakeArray();
filters->appendName("ASCII85Decode");
filters->appendName("FlateDecode");
dict.insertObject("Filter", std::move(filters));
}
#else
if (stream->getLength() > compressedData.bytesWritten() + kMinimumSavings) {
tmp = compressedData.detachAsStream();
stream = tmp.get();
dict.insertName("Filter", "FlateDecode");
} else {
SkAssertResult(stream->rewind());
}
#endif

}
dict.insertInt("Length", stream->getLength());
Expand Down
8 changes: 1 addition & 7 deletions src/pdf/SkPDFTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ static inline std::unique_ptr<SkPDFDict> SkPDFMakeDict(const char* type = nullpt
enum class SkPDFSteamCompressionEnabled : bool {
No = false,
Yes = true,
Default =
#ifdef SK_PDF_LESS_COMPRESSION
No,
#else
Yes,
#endif
};

// Exposed for unit testing.
Expand All @@ -205,5 +199,5 @@ SkPDFIndirectReference SkPDFStreamOut(
std::unique_ptr<SkPDFDict> dict,
std::unique_ptr<SkStreamAsset> stream,
SkPDFDocument* doc,
SkPDFSteamCompressionEnabled compress = SkPDFSteamCompressionEnabled::Default);
SkPDFSteamCompressionEnabled compress = SkPDFSteamCompressionEnabled::Yes);
#endif
37 changes: 0 additions & 37 deletions src/pdf/SkPDFUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,43 +359,6 @@ bool SkPDFUtils::ToBitmap(const SkImage* img, SkBitmap* dst) {
return false;
}

#ifdef SK_PDF_BASE85_BINARY
void SkPDFUtils::Base85Encode(std::unique_ptr<SkStreamAsset> stream, SkDynamicMemoryWStream* dst) {
SkASSERT(dst);
SkASSERT(stream);
dst->writeText("\n");
int column = 0;
while (true) {
uint8_t src[4] = {0, 0, 0, 0};
size_t count = stream->read(src, 4);
SkASSERT(count < 5);
if (0 == count) {
dst->writeText("~>\n");
return;
}
uint32_t v = ((uint32_t)src[0] << 24) | ((uint32_t)src[1] << 16) |
((uint32_t)src[2] << 8) | src[3];
if (v == 0 && count == 4) {
dst->writeText("z");
column += 1;
} else {
char buffer[5];
for (int n = 4; n > 0; --n) {
buffer[n] = (v % 85) + '!';
v /= 85;
}
buffer[0] = v + '!';
dst->write(buffer, count + 1);
column += count + 1;
}
if (column > 74) {
dst->writeText("\n");
column = 0;
}
}
}
#endif // SK_PDF_BASE85_BINARY

void SkPDFUtils::AppendTransform(const SkMatrix& matrix, SkWStream* content) {
SkScalar values[6];
if (!matrix.asAffine(values)) {
Expand Down
4 changes: 0 additions & 4 deletions src/pdf/SkPDFUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ void PopulateTilingPatternDict(SkPDFDict* pattern,

bool ToBitmap(const SkImage* img, SkBitmap* dst);

#ifdef SK_PDF_BASE85_BINARY
void Base85Encode(std::unique_ptr<SkStreamAsset> src, SkDynamicMemoryWStream* dst);
#endif // SK_PDF_BASE85_BINARY

void AppendTransform(const SkMatrix&, SkWStream*);

// Takes SkTime::GetNSecs() [now] and puts it into the provided struct.
Expand Down
4 changes: 0 additions & 4 deletions tests/PDFJpegEmbedTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ DEF_TEST(SkPDF_JpegEmbedTest, r) {
sk_sp<SkData> pdfData = pdf.detachAsData();
SkASSERT(pdfData);

#ifndef SK_PDF_BASE85_BINARY
REPORTER_ASSERT(r, is_subset_of(mandrillData.get(), pdfData.get()));
#endif

// This JPEG uses a nonstandard colorspace - it can not be
// embedded into the PDF directly.
REPORTER_ASSERT(r, !is_subset_of(cmykData.get(), pdfData.get()));
Expand Down

0 comments on commit 830bc24

Please sign in to comment.