#include "testing/image_diff/image_diff_png.h"
#include <stdlib.h>
#include <string.h>
#include <string>
#include "core/fxcrt/check_op.h"
#include "core/fxcrt/fx_memcpy_wrappers.h"
#include "core/fxcrt/notreached.h"
#ifdef USE_SYSTEM_ZLIB
#include <zlib.h>
#else
#include "third_party/zlib/zlib.h"
#endif
#ifdef USE_SYSTEM_LIBPNG
#include <png.h>
#else
#include "third_party/libpng/png.h"
#endif
namespace image_diff_png {
namespace {
enum ColorFormat { … };
struct Comment { … };
void ConvertBetweenBGRAandRGBA(const uint8_t* input,
int pixel_width,
uint8_t* output,
bool* is_opaque) { … }
void ConvertBGRtoRGB(const uint8_t* bgr,
int pixel_width,
uint8_t* rgb,
bool* is_opaque) { … }
void ConvertRGBAtoRGB(const uint8_t* rgba,
int pixel_width,
uint8_t* rgb,
bool* is_opaque) { … }
constexpr double kDefaultGamma = …;
constexpr double kMaxGamma = …;
constexpr double kInverseGamma = …;
class PngDecoderState { … };
void ConvertRGBtoRGBA(const uint8_t* rgb,
int pixel_width,
uint8_t* rgba,
bool* is_opaque) { … }
void ConvertRGBtoBGRA(const uint8_t* rgb,
int pixel_width,
uint8_t* bgra,
bool* is_opaque) { … }
void DecodeInfoCallback(png_struct* png_ptr, png_info* info_ptr) { … }
void DecodeRowCallback(png_struct* png_ptr,
png_byte* new_row,
png_uint_32 row_num,
int pass) { … }
void DecodeEndCallback(png_struct* png_ptr, png_info* info) { … }
class PngReadStructDestroyer { … };
bool BuildPNGStruct(pdfium::span<const uint8_t> input,
png_struct** png_ptr,
png_info** info_ptr) { … }
std::vector<uint8_t> Decode(pdfium::span<const uint8_t> input,
ColorFormat format,
int* w,
int* h) { … }
struct PngEncoderState { … };
void EncoderWriteCallback(png_structp png, png_bytep data, png_size_t size) { … }
void FakeFlushCallback(png_structp png) { … }
void ConvertBGRAtoRGB(const uint8_t* bgra,
int pixel_width,
uint8_t* rgb,
bool* is_opaque) { … }
#ifdef PNG_TEXT_SUPPORTED
inline char* strdup(const char* str) { … }
class CommentWriter { … };
#endif
FormatConverter;
bool DoLibpngWrite(png_struct* png_ptr,
png_info* info_ptr,
PngEncoderState* state,
int width,
int height,
int row_byte_width,
pdfium::span<const uint8_t> input,
int compression_level,
int png_output_color_type,
int output_color_components,
FormatConverter converter,
const std::vector<Comment>& comments) { … }
std::vector<uint8_t> EncodeWithCompressionLevel(
pdfium::span<const uint8_t> input,
ColorFormat format,
const int width,
const int height,
int row_byte_width,
bool discard_transparency,
const std::vector<Comment>& comments,
int compression_level) { … }
std::vector<uint8_t> Encode(pdfium::span<const uint8_t> input,
ColorFormat format,
const int width,
const int height,
int row_byte_width,
bool discard_transparency,
const std::vector<Comment>& comments) { … }
}
std::vector<uint8_t> DecodePNG(pdfium::span<const uint8_t> input,
bool reverse_byte_order,
int* width,
int* height) { … }
std::vector<uint8_t> EncodeBGRPNG(pdfium::span<const uint8_t> input,
int width,
int height,
int row_byte_width) { … }
std::vector<uint8_t> EncodeRGBAPNG(pdfium::span<const uint8_t> input,
int width,
int height,
int row_byte_width) { … }
std::vector<uint8_t> EncodeBGRAPNG(pdfium::span<const uint8_t> input,
int width,
int height,
int row_byte_width,
bool discard_transparency) { … }
std::vector<uint8_t> EncodeGrayPNG(pdfium::span<const uint8_t> input,
int width,
int height,
int row_byte_width) { … }
}