pdfium/testing/utils/bitmap_saver.cpp
Lei Zhang a1a1e12dc9 Output PNGs as data: URLs in embedder tests
This lets developers see what bots are rendering when embedder tests
have PNG comparison failures, without the need to access to the bots'
file systems. Inspired by Chromium cc/ test utilities.

Add an EncodePng(FPDF_BITMAP) variant to support this.

Change-Id: Ic68eaeea6855aa099e82d5a55e5dd33a8f06e22d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/141274
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
2026-01-21 13:24:53 -08:00

32 lines
948 B
C++

// Copyright 2018 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/utils/bitmap_saver.h"
#include <fstream>
#include <vector>
#include "core/fxcrt/check.h"
#include "testing/utils/png_encode.h"
// static
void BitmapSaver::WriteBitmapToPng(FPDF_BITMAP bitmap,
const std::string& filename) {
std::vector<uint8_t> png = EncodePng(bitmap);
DCHECK(!png.empty());
DCHECK(filename.size() < 256u);
std::ofstream png_file;
png_file.open(filename, std::ios_base::out | std::ios_base::binary);
png_file.write(reinterpret_cast<char*>(&png.front()), png.size());
DCHECK(png_file.good());
png_file.close();
}
// static
void BitmapSaver::WriteBitmapToPng(CFX_DIBitmap* bitmap,
const std::string& filename) {
WriteBitmapToPng(reinterpret_cast<FPDF_BITMAP>(bitmap), filename);
}