From c2ae41abd16aef062fee878160aa18457d2118a7 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Mon, 2 Oct 2017 16:04:37 -0400 Subject: Replace GetWord_LSBFirst with FXWORD_GET_LSBFIRST The existing implementation of a LSB first word method was incorrect, in addition it was implemented to the BMP code, but also used in the GIF code. Thus is should be moved to a common location. Also added in an implementation for FXWORD_GET_MSBFIRST, since the GIF code will need this. BUG=pdfium:914 Change-Id: I0e84813356fbd456b293a190da3c2cde01a6580b Reviewed-on: https://pdfium-review.googlesource.com/15210 Reviewed-by: Tom Sepez Reviewed-by: dsinclair Commit-Queue: Ryan Harrison --- core/fxcodec/lbmp/fx_bmp.cpp | 20 ++++++++------------ core/fxcodec/lbmp/fx_bmp.h | 2 -- 2 files changed, 8 insertions(+), 14 deletions(-) (limited to 'core/fxcodec/lbmp') diff --git a/core/fxcodec/lbmp/fx_bmp.cpp b/core/fxcodec/lbmp/fx_bmp.cpp index e705555522..73be66e256 100644 --- a/core/fxcodec/lbmp/fx_bmp.cpp +++ b/core/fxcodec/lbmp/fx_bmp.cpp @@ -28,10 +28,6 @@ uint8_t HalfRoundUp(uint8_t value) { } // namespace -uint16_t GetWord_LSBFirst(uint8_t* p) { - return p[0] | (p[1] << 8); -} - BMPDecompressor::BMPDecompressor() : context_ptr(nullptr), next_in(nullptr), @@ -88,7 +84,7 @@ int32_t BMPDecompressor::ReadHeader() { } pBmp_header->bfType = - GetWord_LSBFirst(reinterpret_cast(&pBmp_header->bfType)); + FXWORD_GET_LSBFIRST(reinterpret_cast(&pBmp_header->bfType)); pBmp_header->bfOffBits = FXDWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_header->bfOffBits)); data_size = @@ -117,11 +113,11 @@ int32_t BMPDecompressor::ReadHeader() { skip_size = skip_size_org; return 2; } - width = GetWord_LSBFirst( + width = FXWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_core_header->bcWidth)); - height = GetWord_LSBFirst( + height = FXWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_core_header->bcHeight)); - bitCounts = GetWord_LSBFirst( + bitCounts = FXWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_core_header->bcBitCount)); compress_flag = BMP_RGB; imgTB_flag = false; @@ -137,7 +133,7 @@ int32_t BMPDecompressor::ReadHeader() { reinterpret_cast(&pBmp_info_header->biWidth)); int32_t signed_height = FXDWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biHeight)); - bitCounts = GetWord_LSBFirst( + bitCounts = FXWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biBitCount)); compress_flag = FXDWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biCompression)); @@ -163,13 +159,13 @@ int32_t BMPDecompressor::ReadHeader() { reinterpret_cast(&pBmp_info_header->biWidth)); int32_t signed_height = FXDWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biHeight)); - bitCounts = GetWord_LSBFirst( + bitCounts = FXWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biBitCount)); compress_flag = FXDWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biCompression)); color_used = FXDWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biClrUsed)); - biPlanes = GetWord_LSBFirst( + biPlanes = FXWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biPlanes)); dpi_x = FXDWORD_GET_LSBFIRST( reinterpret_cast(&pBmp_info_header->biXPelsPerMeter)); @@ -385,7 +381,7 @@ int32_t BMPDecompressor::DecodeRGB() { green_bits -= 8; red_bits -= 8; for (uint32_t col = 0; col < width; ++col) { - *buf = GetWord_LSBFirst(reinterpret_cast(buf)); + *buf = FXWORD_GET_LSBFIRST(reinterpret_cast(buf)); out_row_buffer[idx++] = static_cast((*buf & mask_blue) << blue_bits); out_row_buffer[idx++] = diff --git a/core/fxcodec/lbmp/fx_bmp.h b/core/fxcodec/lbmp/fx_bmp.h index 1dfbcc1410..9dfa849939 100644 --- a/core/fxcodec/lbmp/fx_bmp.h +++ b/core/fxcodec/lbmp/fx_bmp.h @@ -133,6 +133,4 @@ class CBmpContext : public CCodec_BmpModule::Context { UnownedPtr const m_pDelegate; }; -uint16_t GetWord_LSBFirst(uint8_t* p); - #endif // CORE_FXCODEC_LBMP_FX_BMP_H_ -- cgit v1.2.3