Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: core/src/fxcodec/lbmp/fx_bmp.cpp

Issue 1577503002: Merge to XFA: Switch most min/max macros to std::min/max. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_png.cpp ('k') | core/src/fxcrt/extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fx_bmp.h" 7 #include "fx_bmp.h"
8
9 #include <algorithm>
10
11 namespace {
12
13 const size_t kBmpCoreHeaderSize = 12;
14 const size_t kBmpInfoHeaderSize = 40;
15
16 } // namespace
17
8 FX_DWORD _GetDWord_LSBFirst(uint8_t* p) { 18 FX_DWORD _GetDWord_LSBFirst(uint8_t* p) {
9 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); 19 return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
10 } 20 }
11 FX_WORD _GetWord_LSBFirst(uint8_t* p) { 21 FX_WORD _GetWord_LSBFirst(uint8_t* p) {
12 return p[0] | (p[1] << 8); 22 return p[0] | (p[1] << 8);
13 } 23 }
14 void _SetDWord_LSBFirst(uint8_t* p, FX_DWORD v) { 24 void _SetDWord_LSBFirst(uint8_t* p, FX_DWORD v) {
15 p[0] = (uint8_t)v; 25 p[0] = (uint8_t)v;
16 p[1] = (uint8_t)(v >> 8); 26 p[1] = (uint8_t)(v >> 8);
17 p[2] = (uint8_t)(v >> 16); 27 p[2] = (uint8_t)(v >> 16);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 _bmp_error(bmp_ptr, "Not A Bmp Image"); 83 _bmp_error(bmp_ptr, "Not A Bmp Image");
74 return 0; 84 return 0;
75 } 85 }
76 if (bmp_ptr->avail_in < sizeof(FX_DWORD)) { 86 if (bmp_ptr->avail_in < sizeof(FX_DWORD)) {
77 bmp_ptr->skip_size = skip_size_org; 87 bmp_ptr->skip_size = skip_size_org;
78 return 2; 88 return 2;
79 } 89 }
80 bmp_ptr->img_ifh_size = 90 bmp_ptr->img_ifh_size =
81 _GetDWord_LSBFirst(bmp_ptr->next_in + bmp_ptr->skip_size); 91 _GetDWord_LSBFirst(bmp_ptr->next_in + bmp_ptr->skip_size);
82 bmp_ptr->pal_type = 0; 92 bmp_ptr->pal_type = 0;
83 ASSERT(sizeof(BmpCoreHeader) == 12); 93 static_assert(sizeof(BmpCoreHeader) == kBmpCoreHeaderSize,
84 ASSERT(sizeof(BmpInfoHeader) == 40); 94 "BmpCoreHeader has wrong size");
95 static_assert(sizeof(BmpInfoHeader) == kBmpInfoHeaderSize,
96 "BmpInfoHeader has wrong size");
85 switch (bmp_ptr->img_ifh_size) { 97 switch (bmp_ptr->img_ifh_size) {
86 case FX_MIN(12, sizeof(BmpCoreHeader)): { 98 case kBmpCoreHeaderSize: {
87 bmp_ptr->pal_type = 1; 99 bmp_ptr->pal_type = 1;
88 BmpCoreHeaderPtr bmp_core_header_ptr = NULL; 100 BmpCoreHeaderPtr bmp_core_header_ptr = NULL;
89 if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_core_header_ptr, 101 if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_core_header_ptr,
90 bmp_ptr->img_ifh_size) == NULL) { 102 bmp_ptr->img_ifh_size) == NULL) {
91 bmp_ptr->skip_size = skip_size_org; 103 bmp_ptr->skip_size = skip_size_org;
92 return 2; 104 return 2;
93 } 105 }
94 bmp_ptr->width = (FX_DWORD)_GetWord_LSBFirst( 106 bmp_ptr->width = (FX_DWORD)_GetWord_LSBFirst(
95 (uint8_t*)&bmp_core_header_ptr->bcWidth); 107 (uint8_t*)&bmp_core_header_ptr->bcWidth);
96 bmp_ptr->height = (FX_DWORD)_GetWord_LSBFirst( 108 bmp_ptr->height = (FX_DWORD)_GetWord_LSBFirst(
97 (uint8_t*)&bmp_core_header_ptr->bcHeight); 109 (uint8_t*)&bmp_core_header_ptr->bcHeight);
98 bmp_ptr->bitCounts = 110 bmp_ptr->bitCounts =
99 _GetWord_LSBFirst((uint8_t*)&bmp_core_header_ptr->bcBitCount); 111 _GetWord_LSBFirst((uint8_t*)&bmp_core_header_ptr->bcBitCount);
100 bmp_ptr->compress_flag = BMP_RGB; 112 bmp_ptr->compress_flag = BMP_RGB;
101 bmp_ptr->imgTB_flag = FALSE; 113 bmp_ptr->imgTB_flag = FALSE;
102 } break; 114 } break;
103 case FX_MIN(40, sizeof(BmpInfoHeader)): { 115 case kBmpInfoHeaderSize: {
104 BmpInfoHeaderPtr bmp_info_header_ptr = NULL; 116 BmpInfoHeaderPtr bmp_info_header_ptr = NULL;
105 if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr, 117 if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr,
106 bmp_ptr->img_ifh_size) == NULL) { 118 bmp_ptr->img_ifh_size) == NULL) {
107 bmp_ptr->skip_size = skip_size_org; 119 bmp_ptr->skip_size = skip_size_org;
108 return 2; 120 return 2;
109 } 121 }
110 bmp_ptr->width = 122 bmp_ptr->width =
111 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biWidth); 123 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biWidth);
112 bmp_ptr->height = 124 bmp_ptr->height =
113 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biHeight); 125 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biHeight);
114 bmp_ptr->bitCounts = 126 bmp_ptr->bitCounts =
115 _GetWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biBitCount); 127 _GetWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biBitCount);
116 bmp_ptr->compress_flag = 128 bmp_ptr->compress_flag =
117 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biCompression); 129 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biCompression);
118 bmp_ptr->color_used = 130 bmp_ptr->color_used =
119 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biClrUsed); 131 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biClrUsed);
120 bmp_ptr->dpi_x = (int32_t)_GetDWord_LSBFirst( 132 bmp_ptr->dpi_x = (int32_t)_GetDWord_LSBFirst(
121 (uint8_t*)&bmp_info_header_ptr->biXPelsPerMeter); 133 (uint8_t*)&bmp_info_header_ptr->biXPelsPerMeter);
122 bmp_ptr->dpi_y = (int32_t)_GetDWord_LSBFirst( 134 bmp_ptr->dpi_y = (int32_t)_GetDWord_LSBFirst(
123 (uint8_t*)&bmp_info_header_ptr->biYPelsPerMeter); 135 (uint8_t*)&bmp_info_header_ptr->biYPelsPerMeter);
124 if (bmp_ptr->height < 0) { 136 if (bmp_ptr->height < 0) {
125 bmp_ptr->height = -bmp_ptr->height; 137 bmp_ptr->height = -bmp_ptr->height;
126 bmp_ptr->imgTB_flag = TRUE; 138 bmp_ptr->imgTB_flag = TRUE;
127 } 139 }
128 } break; 140 } break;
129 default: { 141 default: {
130 if (bmp_ptr->img_ifh_size > FX_MIN(40, sizeof(BmpInfoHeader))) { 142 if (bmp_ptr->img_ifh_size >
143 std::min(kBmpInfoHeaderSize, sizeof(BmpInfoHeader))) {
131 BmpInfoHeaderPtr bmp_info_header_ptr = NULL; 144 BmpInfoHeaderPtr bmp_info_header_ptr = NULL;
132 if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr, 145 if (_bmp_read_data(bmp_ptr, (uint8_t**)&bmp_info_header_ptr,
133 bmp_ptr->img_ifh_size) == NULL) { 146 bmp_ptr->img_ifh_size) == NULL) {
134 bmp_ptr->skip_size = skip_size_org; 147 bmp_ptr->skip_size = skip_size_org;
135 return 2; 148 return 2;
136 } 149 }
137 FX_WORD biPlanes; 150 FX_WORD biPlanes;
138 bmp_ptr->width = 151 bmp_ptr->width =
139 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biWidth); 152 _GetDWord_LSBFirst((uint8_t*)&bmp_info_header_ptr->biWidth);
140 bmp_ptr->height = 153 bmp_ptr->height =
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 break; 966 break;
954 case BMP_RLE4: 967 case BMP_RLE4:
955 _bmp_encode_rle4(bmp_ptr, dst_buf, dst_size); 968 _bmp_encode_rle4(bmp_ptr, dst_buf, dst_size);
956 break; 969 break;
957 default:; 970 default:;
958 } 971 }
959 bmp_ptr->file_header.bfSize = dst_size; 972 bmp_ptr->file_header.bfSize = dst_size;
960 WriteFileHeader(&bmp_ptr->file_header, dst_buf); 973 WriteFileHeader(&bmp_ptr->file_header, dst_buf);
961 return TRUE; 974 return TRUE;
962 } 975 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_png.cpp ('k') | core/src/fxcrt/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698