• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/fx_codec.h"
8 
9 #include <utility>
10 
11 #include "core/fxcrt/numerics/safe_conversions.h"
12 #include "core/fxcrt/span_util.h"
13 #include "core/fxge/dib/fx_dib.h"
14 
15 namespace fxcodec {
16 
17 #ifdef PDF_ENABLE_XFA
18 CFX_DIBAttribute::CFX_DIBAttribute() = default;
19 
20 CFX_DIBAttribute::~CFX_DIBAttribute() = default;
21 #endif  // PDF_ENABLE_XFA
22 
ReverseRGB(pdfium::span<uint8_t> pDestBuf,pdfium::span<const uint8_t> pSrcBuf,int pixels)23 void ReverseRGB(pdfium::span<uint8_t> pDestBuf,
24                 pdfium::span<const uint8_t> pSrcBuf,
25                 int pixels) {
26   const size_t count = pdfium::checked_cast<size_t>(pixels);
27   auto dst_span =
28       fxcrt::reinterpret_span<FX_RGB_STRUCT<uint8_t>>(pDestBuf).first(count);
29 
30   const auto src_span =
31       fxcrt::reinterpret_span<const FX_RGB_STRUCT<uint8_t>>(pSrcBuf).first(
32           count);
33 
34   if (dst_span.data() == src_span.data()) {
35     for (auto& pix : dst_span) {
36       std::swap(pix.red, pix.blue);
37     }
38     return;
39   }
40 
41   for (const auto& src_pix : src_span) {
42     auto& dst_pix = dst_span.front();
43     dst_pix.red = src_pix.blue;
44     dst_pix.green = src_pix.green;
45     dst_pix.blue = src_pix.red;
46     dst_span = dst_span.subspan(1);
47   }
48 }
49 
50 }  // namespace fxcodec
51