// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifdef UNSAFE_BUFFERS_BUILD // TODO(crbug.com/351564777): Remove this and convert code to safer constructs. #pragma allow_unsafe_buffers #endif // This program converts an image from stdin (e.g. a JPEG, PNG, etc.) to stdout // (in the NIA/NIE format, a trivial image file format). // // The NIA/NIE file format specification is at: // https://github.com/google/wuffs/blob/master/doc/spec/nie-spec.md // // Pass "-1" or "-first-frame-only" as a command line flag to output NIE (a // still image) instead of NIA (an animated image). The output format (NIA or // NIE) depends only on this flag's absence or presence, not on the stdin // image's format. // // There are multiple codec implementations of any given image format. For // example, as of May 2020, Chromium, Skia and Wuffs each have their own BMP // decoder implementation. There is no standard "libbmp" that they all share. // Comparing this program's output (or hashed output) to similar programs in // other repositories can identify image inputs for which these decoders (or // different versions of the same decoder) produce different output (pixels). // // An equivalent program (using the Skia image codecs) is at: // https://skia-review.googlesource.com/c/skia/+/290618 // // An equivalent program (using the Wuffs image codecs) is at: // https://github.com/google/wuffs/blob/master/example/convert-to-nia/convert-to-nia.c #include <iostream> #include "base/command_line.h" #include "base/files/file_util.h" #include "base/task/single_thread_task_executor.h" #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/renderer/platform/image-decoders/image_decoder.h" #include "third_party/blink/renderer/platform/wtf/shared_buffer.h" #include "third_party/skia/include/core/SkColor.h" static inline void set_u32le(uint8_t* ptr, uint32_t val) { … } static inline void set_u64le(uint8_t* ptr, uint64_t val) { … } void write_nix_header(uint32_t magic_u32le, uint32_t width, uint32_t height) { … } bool write_nia_duration(uint64_t total_duration_micros) { … } void write_nie_pixels(uint32_t width, uint32_t height, blink::ImageFrame* frame) { … } void write_nia_padding(uint32_t width, uint32_t height) { … } void write_nia_footer(int repetition_count, size_t frame_count) { … } int main(int argc, char* argv[]) { … }