1 // Copyright 2014 PDFium Authors. All rights reserved.
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 #include "core/fxcodec/bmp/bmpmodule.h"
8
9 #include <utility>
10
11 #include "core/fxcodec/bmp/cfx_bmpcontext.h"
12 #include "core/fxcodec/cfx_codec_memory.h"
13 #include "core/fxcodec/fx_codec.h"
14 #include "core/fxge/fx_dib.h"
15 #include "third_party/base/ptr_util.h"
16
17 namespace fxcodec {
18
19 BmpModule::BmpModule() = default;
20
21 BmpModule::~BmpModule() = default;
22
Start(Delegate * pDelegate)23 std::unique_ptr<ModuleIface::Context> BmpModule::Start(Delegate* pDelegate) {
24 return pdfium::MakeUnique<CFX_BmpContext>(this, pDelegate);
25 }
26
ReadHeader(Context * pContext,int32_t * width,int32_t * height,bool * tb_flag,int32_t * components,int32_t * pal_num,const std::vector<uint32_t> ** palette,CFX_DIBAttribute * pAttribute)27 BmpModule::Status BmpModule::ReadHeader(Context* pContext,
28 int32_t* width,
29 int32_t* height,
30 bool* tb_flag,
31 int32_t* components,
32 int32_t* pal_num,
33 const std::vector<uint32_t>** palette,
34 CFX_DIBAttribute* pAttribute) {
35 ASSERT(pAttribute);
36
37 auto* ctx = static_cast<CFX_BmpContext*>(pContext);
38 Status status = ctx->m_Bmp.ReadHeader();
39 if (status != Status::kSuccess)
40 return status;
41
42 *width = ctx->m_Bmp.width();
43 *height = ctx->m_Bmp.height();
44 *tb_flag = ctx->m_Bmp.img_tb_flag();
45 *components = ctx->m_Bmp.components();
46 *pal_num = ctx->m_Bmp.pal_num();
47 *palette = ctx->m_Bmp.palette();
48 pAttribute->m_wDPIUnit = FXCODEC_RESUNIT_METER;
49 pAttribute->m_nXDPI = ctx->m_Bmp.dpi_x();
50 pAttribute->m_nYDPI = ctx->m_Bmp.dpi_y();
51 return Status::kSuccess;
52 }
53
LoadImage(Context * pContext)54 BmpModule::Status BmpModule::LoadImage(Context* pContext) {
55 return static_cast<CFX_BmpContext*>(pContext)->m_Bmp.DecodeImage();
56 }
57
GetAvailInput(Context * pContext) const58 FX_FILESIZE BmpModule::GetAvailInput(Context* pContext) const {
59 return static_cast<CFX_BmpContext*>(pContext)->m_Bmp.GetAvailInput();
60 }
61
Input(Context * pContext,RetainPtr<CFX_CodecMemory> codec_memory,CFX_DIBAttribute *)62 bool BmpModule::Input(Context* pContext,
63 RetainPtr<CFX_CodecMemory> codec_memory,
64 CFX_DIBAttribute*) {
65 auto* ctx = static_cast<CFX_BmpContext*>(pContext);
66 ctx->m_Bmp.SetInputBuffer(std::move(codec_memory));
67 return true;
68 }
69
70 } // namespace fxcodec
71