OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 #include "ui/gfx/buffer_format_util.h" | 5 #include "ui/gfx/buffer_format_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/numerics/safe_math.h" | 9 #include "base/numerics/safe_math.h" |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 case BufferFormat::DXT1: | 46 case BufferFormat::DXT1: |
47 case BufferFormat::ETC1: | 47 case BufferFormat::ETC1: |
48 DCHECK_EQ(0u, plane); | 48 DCHECK_EQ(0u, plane); |
49 DCHECK_EQ(0u, width % 2); | 49 DCHECK_EQ(0u, width % 2); |
50 *size_in_bytes = width / 2; | 50 *size_in_bytes = width / 2; |
51 return true; | 51 return true; |
52 case BufferFormat::R_8: | 52 case BufferFormat::R_8: |
53 checked_size += 3; | 53 checked_size += 3; |
54 if (!checked_size.IsValid()) | 54 if (!checked_size.IsValid()) |
55 return false; | 55 return false; |
56 *size_in_bytes = checked_size.ValueOrDie() & ~0x3; | 56 *size_in_bytes = (checked_size & ~0x3).ValueOrDie(); |
57 return true; | 57 return true; |
58 case BufferFormat::RG_88: | 58 case BufferFormat::RG_88: |
59 case BufferFormat::BGR_565: | 59 case BufferFormat::BGR_565: |
60 case BufferFormat::RGBA_4444: | 60 case BufferFormat::RGBA_4444: |
61 case BufferFormat::UYVY_422: | 61 case BufferFormat::UYVY_422: |
62 checked_size *= 2; | 62 checked_size *= 2; |
63 checked_size += 3; | 63 checked_size += 3; |
64 if (!checked_size.IsValid()) | 64 if (!checked_size.IsValid()) |
65 return false; | 65 return false; |
66 *size_in_bytes = checked_size.ValueOrDie() & ~0x3; | 66 *size_in_bytes = (checked_size & ~0x3).ValueOrDie(); |
67 return true; | 67 return true; |
68 case BufferFormat::BGRX_8888: | 68 case BufferFormat::BGRX_8888: |
69 case BufferFormat::RGBX_8888: | 69 case BufferFormat::RGBX_8888: |
70 case BufferFormat::RGBA_8888: | 70 case BufferFormat::RGBA_8888: |
71 case BufferFormat::BGRA_8888: | 71 case BufferFormat::BGRA_8888: |
72 checked_size *= 4; | 72 checked_size *= 4; |
73 if (!checked_size.IsValid()) | 73 if (!checked_size.IsValid()) |
74 return false; | 74 return false; |
75 *size_in_bytes = checked_size.ValueOrDie(); | 75 *size_in_bytes = (checked_size & ~0x3).ValueOrDie(); |
76 return true; | 76 return true; |
77 case BufferFormat::YVU_420: | 77 case BufferFormat::YVU_420: |
78 DCHECK_EQ(0u, width % 2); | 78 DCHECK_EQ(0u, width % 2); |
79 *size_in_bytes = width / SubsamplingFactorForBufferFormat(format, plane); | 79 *size_in_bytes = width / SubsamplingFactorForBufferFormat(format, plane); |
80 return true; | 80 return true; |
81 case BufferFormat::YUV_420_BIPLANAR: | 81 case BufferFormat::YUV_420_BIPLANAR: |
82 DCHECK_EQ(width % 2, 0u); | 82 DCHECK_EQ(width % 2, 0u); |
83 *size_in_bytes = width; | 83 *size_in_bytes = width; |
84 return true; | 84 return true; |
85 } | 85 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes)); | 219 DCHECK_LT(plane, arraysize(offset_in_2x2_sub_sampling_sizes)); |
220 return offset_in_2x2_sub_sampling_sizes[plane] * | 220 return offset_in_2x2_sub_sampling_sizes[plane] * |
221 (size.width() / 2 + size.height() / 2); | 221 (size.width() / 2 + size.height() / 2); |
222 } | 222 } |
223 } | 223 } |
224 NOTREACHED(); | 224 NOTREACHED(); |
225 return 0; | 225 return 0; |
226 } | 226 } |
227 | 227 |
228 } // namespace gfx | 228 } // namespace gfx |
OLD | NEW |