Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
jbig2_decoder.cpp
Go to the documentation of this file.
1// Copyright 2014 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#include "core/fxcodec/jbig2/jbig2_decoder.h"
8
9#include "core/fxcodec/jbig2/JBig2_Context.h"
10#include "core/fxcodec/jbig2/JBig2_DocumentContext.h"
11#include "core/fxcrt/fx_2d_size.h"
12#include "core/fxcrt/span_util.h"
13#include "core/fxcrt/stl_util.h"
14
15namespace fxcodec {
16
17namespace {
18
19FXCODEC_STATUS Decode(Jbig2Context* pJbig2Context, bool decode_success) {
20 FXCODEC_STATUS status = pJbig2Context->m_pContext->GetProcessingStatus();
21 if (status != FXCODEC_STATUS::kDecodeFinished) {
22 return status;
23 }
24 pJbig2Context->m_pContext.reset();
25 if (!decode_success) {
27 }
28 uint32_t byte_size = pJbig2Context->m_height * pJbig2Context->m_dest_pitch;
29 pdfium::span<uint8_t> nonraw_span(pJbig2Context->m_dest_buf.first(byte_size));
30 auto dword_span = fxcrt::reinterpret_span<uint32_t>(nonraw_span);
31 for (auto& pix : dword_span) {
32 pix = ~pix;
33 }
35}
36
37} // namespace
38
39Jbig2Context::Jbig2Context() = default;
40
41Jbig2Context::~Jbig2Context() = default;
42
43// static
45 Jbig2Context* pJbig2Context,
46 JBig2_DocumentContext* pJBig2DocumentContext,
47 uint32_t width,
48 uint32_t height,
49 pdfium::span<const uint8_t> src_span,
50 uint64_t src_key,
51 pdfium::span<const uint8_t> global_span,
52 uint64_t global_key,
53 pdfium::span<uint8_t> dest_buf,
54 uint32_t dest_pitch,
55 PauseIndicatorIface* pPause) {
56 pJbig2Context->m_width = width;
57 pJbig2Context->m_height = height;
58 pJbig2Context->m_pSrcSpan = src_span;
59 pJbig2Context->m_nSrcKey = src_key;
60 pJbig2Context->m_pGlobalSpan = global_span;
61 pJbig2Context->m_nGlobalKey = global_key;
62 pJbig2Context->m_dest_buf = dest_buf;
63 pJbig2Context->m_dest_pitch = dest_pitch;
64 fxcrt::Fill(dest_buf.first(Fx2DSizeOrDie(height, dest_pitch)), 0);
65 pJbig2Context->m_pContext =
66 CJBig2_Context::Create(global_span, global_key, src_span, src_key,
67 pJBig2DocumentContext->GetSymbolDictCache());
68 bool succeeded = pJbig2Context->m_pContext->GetFirstPage(
69 dest_buf, width, height, dest_pitch, pPause);
70 return Decode(pJbig2Context, succeeded);
71}
72
73// static
75 PauseIndicatorIface* pPause) {
76 bool succeeded = pJbig2Context->m_pContext->Continue(pPause);
77 return Decode(pJbig2Context, succeeded);
78}
79
80} // namespace fxcodec
static FXCODEC_STATUS ContinueDecode(Jbig2Context *pJbig2Context, PauseIndicatorIface *pPause)
FXCODEC_STATUS