1 // Copyright 2016 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FXCODEC_JPEG_JPEGMODULE_H_ 8 #define CORE_FXCODEC_JPEG_JPEGMODULE_H_ 9 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include <memory> 14 #include <optional> 15 16 #include "build/build_config.h" 17 #include "core/fxcrt/span.h" 18 19 #if BUILDFLAG(IS_WIN) 20 #include "core/fxcrt/compiler_specific.h" 21 #include "core/fxcrt/retain_ptr.h" 22 #endif 23 24 class CFX_DIBBase; 25 26 namespace fxcodec { 27 28 class ScanlineDecoder; 29 30 class JpegModule { 31 public: 32 struct ImageInfo { 33 uint32_t width; 34 uint32_t height; 35 int num_components; 36 int bits_per_components; 37 bool color_transform; 38 }; 39 40 static std::unique_ptr<ScanlineDecoder> CreateDecoder( 41 pdfium::span<const uint8_t> src_span, 42 uint32_t width, 43 uint32_t height, 44 int nComps, 45 bool ColorTransform); 46 47 static std::optional<ImageInfo> LoadInfo( 48 pdfium::span<const uint8_t> src_span); 49 50 #if BUILDFLAG(IS_WIN) 51 UNSAFE_BUFFER_USAGE static bool JpegEncode( 52 const RetainPtr<const CFX_DIBBase>& pSource, 53 uint8_t** dest_buf, 54 size_t* dest_size); 55 #endif // BUILDFLAG(IS_WIN) 56 57 JpegModule() = delete; 58 JpegModule(const JpegModule&) = delete; 59 JpegModule& operator=(const JpegModule&) = delete; 60 }; 61 62 } // namespace fxcodec 63 64 using JpegModule = fxcodec::JpegModule; 65 66 #endif // CORE_FXCODEC_JPEG_JPEGMODULE_H_ 67