Revert^2 "Move some image/9patch code to androidfw"
This reverts commit 917043bc2586743afda5a21386893fa8c787800b.
Reason for revert: Roll forward with fix
Test: Automatic
Bug: 296324826
Change-Id: I42a0b48c02fd497b2174c0c65f300265202f7ab1
diff --git a/tools/aapt2/cmd/Compile.cpp b/tools/aapt2/cmd/Compile.cpp
index 728ba8a..031dd5b 100644
--- a/tools/aapt2/cmd/Compile.cpp
+++ b/tools/aapt2/cmd/Compile.cpp
@@ -25,13 +25,16 @@
#include "android-base/errors.h"
#include "android-base/file.h"
#include "android-base/utf8.h"
+#include "androidfw/BigBufferStream.h"
#include "androidfw/ConfigDescription.h"
+#include "androidfw/FileStream.h"
#include "androidfw/IDiagnostics.h"
+#include "androidfw/Image.h"
+#include "androidfw/Png.h"
#include "androidfw/StringPiece.h"
#include "cmd/Util.h"
#include "compile/IdAssigner.h"
#include "compile/InlineXmlFormatParser.h"
-#include "compile/Png.h"
#include "compile/PseudolocaleGenerator.h"
#include "compile/XmlIdCollector.h"
#include "format/Archive.h"
@@ -39,8 +42,6 @@
#include "format/proto/ProtoSerialize.h"
#include "google/protobuf/io/coded_stream.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
-#include "io/BigBufferStream.h"
-#include "io/FileStream.h"
#include "io/FileSystem.h"
#include "io/StringStream.h"
#include "io/Util.h"
@@ -52,9 +53,9 @@
#include "xml/XmlDom.h"
#include "xml/XmlPullParser.h"
-using ::aapt::io::FileInputStream;
using ::aapt::text::Printer;
using ::android::ConfigDescription;
+using ::android::FileInputStream;
using ::android::StringPiece;
using ::android::base::SystemErrorCodeToString;
using ::google::protobuf::io::CopyingOutputStreamAdaptor;
@@ -241,7 +242,7 @@
}
if (options.generate_text_symbols_path) {
- io::FileOutputStream fout_text(options.generate_text_symbols_path.value());
+ android::FileOutputStream fout_text(options.generate_text_symbols_path.value());
if (fout_text.HadError()) {
context->GetDiagnostics()->Error(android::DiagMessage()
@@ -307,7 +308,7 @@
}
static bool WriteHeaderAndDataToWriter(StringPiece output_path, const ResourceFile& file,
- io::KnownSizeInputStream* in, IArchiveWriter* writer,
+ android::KnownSizeInputStream* in, IArchiveWriter* writer,
android::IDiagnostics* diag) {
TRACE_CALL();
// Start the entry so we can write the header.
@@ -448,7 +449,7 @@
}
if (options.generate_text_symbols_path) {
- io::FileOutputStream fout_text(options.generate_text_symbols_path.value());
+ android::FileOutputStream fout_text(options.generate_text_symbols_path.value());
if (fout_text.HadError()) {
context->GetDiagnostics()->Error(android::DiagMessage()
@@ -498,21 +499,22 @@
}
android::BigBuffer crunched_png_buffer(4096);
- io::BigBufferOutputStream crunched_png_buffer_out(&crunched_png_buffer);
+ android::BigBufferOutputStream crunched_png_buffer_out(&crunched_png_buffer);
// Ensure that we only keep the chunks we care about if we end up
// using the original PNG instead of the crunched one.
const StringPiece content(reinterpret_cast<const char*>(data->data()), data->size());
- PngChunkFilter png_chunk_filter(content);
- std::unique_ptr<Image> image = ReadPng(context, path_data.source, &png_chunk_filter);
+ android::PngChunkFilter png_chunk_filter(content);
+ android::SourcePathDiagnostics source_diag(path_data.source, context->GetDiagnostics());
+ auto image = android::ReadPng(&png_chunk_filter, &source_diag);
if (!image) {
return false;
}
- std::unique_ptr<NinePatch> nine_patch;
+ std::unique_ptr<android::NinePatch> nine_patch;
if (path_data.extension == "9.png") {
std::string err;
- nine_patch = NinePatch::Create(image->rows.get(), image->width, image->height, &err);
+ nine_patch = android::NinePatch::Create(image->rows.get(), image->width, image->height, &err);
if (!nine_patch) {
context->GetDiagnostics()->Error(android::DiagMessage() << err);
return false;
@@ -537,7 +539,8 @@
}
// Write the crunched PNG.
- if (!WritePng(context, image.get(), nine_patch.get(), &crunched_png_buffer_out, {})) {
+ if (!android::WritePng(image.get(), nine_patch.get(), &crunched_png_buffer_out, {},
+ &source_diag, context->IsVerbose())) {
return false;
}
@@ -557,7 +560,7 @@
png_chunk_filter.Rewind();
android::BigBuffer filtered_png_buffer(4096);
- io::BigBufferOutputStream filtered_png_buffer_out(&filtered_png_buffer);
+ android::BigBufferOutputStream filtered_png_buffer_out(&filtered_png_buffer);
io::Copy(&filtered_png_buffer_out, &png_chunk_filter);
buffer.AppendBuffer(std::move(filtered_png_buffer));
}
@@ -567,7 +570,7 @@
// This will help catch exotic cases where the new code may generate larger PNGs.
std::stringstream legacy_stream{std::string(content)};
android::BigBuffer legacy_buffer(4096);
- Png png(context->GetDiagnostics());
+ android::Png png(context->GetDiagnostics());
if (!png.process(path_data.source, &legacy_stream, &legacy_buffer, {})) {
return false;
}
@@ -578,7 +581,7 @@
}
}
- io::BigBufferInputStream buffer_in(&buffer);
+ android::BigBufferInputStream buffer_in(&buffer);
return WriteHeaderAndDataToWriter(output_path, res_file, &buffer_in, writer,
context->GetDiagnostics());
}