| OLD | NEW |
| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 ++g; | 194 ++g; |
| 195 ++b; | 195 ++b; |
| 196 } | 196 } |
| 197 FX_Free(img->comps[0].data); | 197 FX_Free(img->comps[0].data); |
| 198 img->comps[0].data = d0; | 198 img->comps[0].data = d0; |
| 199 FX_Free(img->comps[1].data); | 199 FX_Free(img->comps[1].data); |
| 200 img->comps[1].data = d1; | 200 img->comps[1].data = d1; |
| 201 FX_Free(img->comps[2].data); | 201 FX_Free(img->comps[2].data); |
| 202 img->comps[2].data = d2; | 202 img->comps[2].data = d2; |
| 203 } | 203 } |
| 204 static bool sycc420_422_size_is_valid(opj_image_t* img) { |
| 205 return (img && img->comps[0].w != std::numeric_limits<OPJ_UINT32>::max() && |
| 206 (img->comps[0].w + 1) / 2 == img->comps[1].w && |
| 207 img->comps[1].w == img->comps[2].w && |
| 208 img->comps[1].h == img->comps[2].h); |
| 209 } |
| 210 static bool sycc420_size_is_valid(opj_image_t* img) { |
| 211 return (sycc420_422_size_is_valid(img) && |
| 212 img->comps[0].h != std::numeric_limits<OPJ_UINT32>::max() && |
| 213 (img->comps[0].h + 1) / 2 == img->comps[1].h); |
| 214 } |
| 215 static bool sycc422_size_is_valid(opj_image_t* img) { |
| 216 return (sycc420_422_size_is_valid(img) && img->comps[0].h == img->comps[1].h); |
| 217 } |
| 204 static void sycc422_to_rgb(opj_image_t* img) { | 218 static void sycc422_to_rgb(opj_image_t* img) { |
| 219 if (!sycc422_size_is_valid(img)) |
| 220 return; |
| 221 |
| 205 int prec = img->comps[0].prec; | 222 int prec = img->comps[0].prec; |
| 206 int offset = 1 << (prec - 1); | 223 int offset = 1 << (prec - 1); |
| 207 int upb = (1 << prec) - 1; | 224 int upb = (1 << prec) - 1; |
| 208 OPJ_UINT32 maxw = | 225 |
| 209 std::min(std::min(img->comps[0].w, img->comps[1].w), img->comps[2].w); | 226 OPJ_UINT32 maxw = img->comps[0].w; |
| 210 OPJ_UINT32 maxh = | 227 OPJ_UINT32 maxh = img->comps[0].h; |
| 211 std::min(std::min(img->comps[0].h, img->comps[1].h), img->comps[2].h); | |
| 212 FX_SAFE_SIZE_T max_size = maxw; | 228 FX_SAFE_SIZE_T max_size = maxw; |
| 213 max_size *= maxh; | 229 max_size *= maxh; |
| 214 if (!max_size.IsValid()) | 230 if (!max_size.IsValid()) |
| 215 return; | 231 return; |
| 216 | 232 |
| 217 const int* y = img->comps[0].data; | 233 const int* y = img->comps[0].data; |
| 218 const int* cb = img->comps[1].data; | 234 const int* cb = img->comps[1].data; |
| 219 const int* cr = img->comps[2].data; | 235 const int* cr = img->comps[2].data; |
| 220 int *d0, *d1, *d2, *r, *g, *b; | 236 int *d0, *d1, *d2, *r, *g, *b; |
| 221 d0 = r = FX_Alloc(int, max_size.ValueOrDie()); | 237 d0 = r = FX_Alloc(int, max_size.ValueOrDie()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 img->comps[2].data = d2; | 271 img->comps[2].data = d2; |
| 256 img->comps[1].w = maxw; | 272 img->comps[1].w = maxw; |
| 257 img->comps[1].h = maxh; | 273 img->comps[1].h = maxh; |
| 258 img->comps[2].w = maxw; | 274 img->comps[2].w = maxw; |
| 259 img->comps[2].h = maxh; | 275 img->comps[2].h = maxh; |
| 260 img->comps[1].dx = img->comps[0].dx; | 276 img->comps[1].dx = img->comps[0].dx; |
| 261 img->comps[2].dx = img->comps[0].dx; | 277 img->comps[2].dx = img->comps[0].dx; |
| 262 img->comps[1].dy = img->comps[0].dy; | 278 img->comps[1].dy = img->comps[0].dy; |
| 263 img->comps[2].dy = img->comps[0].dy; | 279 img->comps[2].dy = img->comps[0].dy; |
| 264 } | 280 } |
| 265 static bool sycc420_size_is_valid(OPJ_UINT32 y, OPJ_UINT32 cbcr) { | |
| 266 if (!y || !cbcr) | |
| 267 return false; | |
| 268 | |
| 269 return (cbcr == y / 2) || ((y & 1) && (cbcr == y / 2 + 1)); | |
| 270 } | |
| 271 static bool sycc420_must_extend_cbcr(OPJ_UINT32 y, OPJ_UINT32 cbcr) { | 281 static bool sycc420_must_extend_cbcr(OPJ_UINT32 y, OPJ_UINT32 cbcr) { |
| 272 return (y & 1) && (cbcr == y / 2); | 282 return (y & 1) && (cbcr == y / 2); |
| 273 } | 283 } |
| 274 void sycc420_to_rgb(opj_image_t* img) { | 284 void sycc420_to_rgb(opj_image_t* img) { |
| 285 if (!sycc420_size_is_valid(img)) |
| 286 return; |
| 287 |
| 275 OPJ_UINT32 prec = img->comps[0].prec; | 288 OPJ_UINT32 prec = img->comps[0].prec; |
| 276 if (!prec) | 289 if (!prec) |
| 277 return; | 290 return; |
| 278 OPJ_UINT32 offset = 1 << (prec - 1); | 291 OPJ_UINT32 offset = 1 << (prec - 1); |
| 279 OPJ_UINT32 upb = (1 << prec) - 1; | 292 OPJ_UINT32 upb = (1 << prec) - 1; |
| 280 OPJ_UINT32 yw = img->comps[0].w; | 293 OPJ_UINT32 yw = img->comps[0].w; |
| 281 OPJ_UINT32 yh = img->comps[0].h; | 294 OPJ_UINT32 yh = img->comps[0].h; |
| 282 OPJ_UINT32 cbw = img->comps[1].w; | 295 OPJ_UINT32 cbw = img->comps[1].w; |
| 283 OPJ_UINT32 cbh = img->comps[1].h; | 296 OPJ_UINT32 cbh = img->comps[1].h; |
| 284 OPJ_UINT32 crw = img->comps[2].w; | 297 OPJ_UINT32 crw = img->comps[2].w; |
| 285 OPJ_UINT32 crh = img->comps[2].h; | |
| 286 if (cbw != crw || cbh != crh) | |
| 287 return; | |
| 288 if (!sycc420_size_is_valid(yw, cbw) || !sycc420_size_is_valid(yh, cbh)) | |
| 289 return; | |
| 290 bool extw = sycc420_must_extend_cbcr(yw, cbw); | 298 bool extw = sycc420_must_extend_cbcr(yw, cbw); |
| 291 bool exth = sycc420_must_extend_cbcr(yh, cbh); | 299 bool exth = sycc420_must_extend_cbcr(yh, cbh); |
| 292 FX_SAFE_DWORD safeSize = yw; | 300 FX_SAFE_DWORD safeSize = yw; |
| 293 safeSize *= yh; | 301 safeSize *= yh; |
| 294 if (!safeSize.IsValid()) | 302 if (!safeSize.IsValid()) |
| 295 return; | 303 return; |
| 296 int* r = FX_Alloc(int, safeSize.ValueOrDie()); | 304 int* r = FX_Alloc(int, safeSize.ValueOrDie()); |
| 297 int* g = FX_Alloc(int, safeSize.ValueOrDie()); | 305 int* g = FX_Alloc(int, safeSize.ValueOrDie()); |
| 298 int* b = FX_Alloc(int, safeSize.ValueOrDie()); | 306 int* b = FX_Alloc(int, safeSize.ValueOrDie()); |
| 299 int* d0 = r; | 307 int* d0 = r; |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, | 886 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, |
| 879 uint8_t* dest_data, | 887 uint8_t* dest_data, |
| 880 int pitch, | 888 int pitch, |
| 881 const std::vector<uint8_t>& offsets) { | 889 const std::vector<uint8_t>& offsets) { |
| 882 return pDecoder->Decode(dest_data, pitch, offsets); | 890 return pDecoder->Decode(dest_data, pitch, offsets); |
| 883 } | 891 } |
| 884 | 892 |
| 885 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { | 893 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { |
| 886 delete pDecoder; | 894 delete pDecoder; |
| 887 } | 895 } |
| OLD | NEW |