| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef AAPT_PNG_H |
| 18 |
#define AAPT_PNG_H |
| 19 |
|
| 20 |
#include <iostream> |
| 21 |
#include <string> |
| 22 |
|
| 23 |
#include "android-base/macros.h" |
| 24 |
|
| 25 |
#include "Diagnostics.h" |
| 26 |
#include "Source.h" |
| 27 |
#include "compile/Image.h" |
| 28 |
#include "io/Io.h" |
| 29 |
#include "process/IResourceTableConsumer.h" |
| 30 |
#include "util/BigBuffer.h" |
| 31 |
|
| 32 |
namespace aapt { |
| 33 |
|
| 34 |
|
| 35 |
constexpr size_t kPngSignatureSize = 8u; |
| 36 |
|
| 37 |
struct PngOptions { |
| 38 |
int grayscale_tolerance = 0; |
| 39 |
}; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
class Png { |
| 45 |
public: |
| 46 |
explicit Png(IDiagnostics* diag) : mDiag(diag) {} |
| 47 |
|
| 48 |
bool process(const Source& source, std::istream* input, BigBuffer* outBuffer, |
| 49 |
const PngOptions& options); |
| 50 |
|
| 51 |
private: |
| 52 |
DISALLOW_COPY_AND_ASSIGN(Png); |
| 53 |
|
| 54 |
IDiagnostics* mDiag; |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
class PngChunkFilter : public io::InputStream { |
| 61 |
public: |
| 62 |
explicit PngChunkFilter(const android::StringPiece& data); |
| 63 |
virtual ~PngChunkFilter() = default; |
| 64 |
|
| 65 |
bool Next(const void** buffer, size_t* len) override; |
| 66 |
void BackUp(size_t count) override; |
| 67 |
|
| 68 |
bool CanRewind() const override { return true; } |
| 69 |
bool Rewind() override; |
| 70 |
size_t ByteCount() const override { return window_start_; } |
| 71 |
|
| 72 |
bool HadError() const override { |
| 73 |
return !error_msg_.empty(); |
| 74 |
} |
| 75 |
std::string GetError() const override { |
| 76 |
return error_msg_; |
| 77 |
} |
| 78 |
|
| 79 |
private: |
| 80 |
DISALLOW_COPY_AND_ASSIGN(PngChunkFilter); |
| 81 |
|
| 82 |
bool ConsumeWindow(const void** buffer, size_t* len); |
| 83 |
|
| 84 |
android::StringPiece data_; |
| 85 |
size_t window_start_ = 0; |
| 86 |
size_t window_end_ = 0; |
| 87 |
std::string error_msg_; |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
std::unique_ptr<Image> ReadPng(IAaptContext* context, const Source& source, io::InputStream* in); |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
bool WritePng(IAaptContext* context, const Image* image, |
| 100 |
const NinePatch* nine_patch, io::OutputStream* out, |
| 101 |
const PngOptions& options); |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
#endif |