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

Side by Side Diff: core/fxcodec/codec/fx_codec_jpx_opj.cpp

Issue 1800153002: Revert "Fix sycc{420,422}_to_rgb issues." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | no next file » | 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 <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
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 }
218 static void sycc422_to_rgb(opj_image_t* img) { 204 static void sycc422_to_rgb(opj_image_t* img) {
219 if (!sycc422_size_is_valid(img))
220 return;
221
222 int prec = img->comps[0].prec; 205 int prec = img->comps[0].prec;
223 int offset = 1 << (prec - 1); 206 int offset = 1 << (prec - 1);
224 int upb = (1 << prec) - 1; 207 int upb = (1 << prec) - 1;
225 208 OPJ_UINT32 maxw =
226 OPJ_UINT32 maxw = img->comps[0].w; 209 std::min(std::min(img->comps[0].w, img->comps[1].w), img->comps[2].w);
227 OPJ_UINT32 maxh = img->comps[0].h; 210 OPJ_UINT32 maxh =
211 std::min(std::min(img->comps[0].h, img->comps[1].h), img->comps[2].h);
228 FX_SAFE_SIZE_T max_size = maxw; 212 FX_SAFE_SIZE_T max_size = maxw;
229 max_size *= maxh; 213 max_size *= maxh;
230 if (!max_size.IsValid()) 214 if (!max_size.IsValid())
231 return; 215 return;
232 216
233 const int* y = img->comps[0].data; 217 const int* y = img->comps[0].data;
234 const int* cb = img->comps[1].data; 218 const int* cb = img->comps[1].data;
235 const int* cr = img->comps[2].data; 219 const int* cr = img->comps[2].data;
236 int *d0, *d1, *d2, *r, *g, *b; 220 int *d0, *d1, *d2, *r, *g, *b;
237 d0 = r = FX_Alloc(int, max_size.ValueOrDie()); 221 d0 = r = FX_Alloc(int, max_size.ValueOrDie());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 img->comps[2].data = d2; 255 img->comps[2].data = d2;
272 img->comps[1].w = maxw; 256 img->comps[1].w = maxw;
273 img->comps[1].h = maxh; 257 img->comps[1].h = maxh;
274 img->comps[2].w = maxw; 258 img->comps[2].w = maxw;
275 img->comps[2].h = maxh; 259 img->comps[2].h = maxh;
276 img->comps[1].dx = img->comps[0].dx; 260 img->comps[1].dx = img->comps[0].dx;
277 img->comps[2].dx = img->comps[0].dx; 261 img->comps[2].dx = img->comps[0].dx;
278 img->comps[1].dy = img->comps[0].dy; 262 img->comps[1].dy = img->comps[0].dy;
279 img->comps[2].dy = img->comps[0].dy; 263 img->comps[2].dy = img->comps[0].dy;
280 } 264 }
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 }
281 static bool sycc420_must_extend_cbcr(OPJ_UINT32 y, OPJ_UINT32 cbcr) { 271 static bool sycc420_must_extend_cbcr(OPJ_UINT32 y, OPJ_UINT32 cbcr) {
282 return (y & 1) && (cbcr == y / 2); 272 return (y & 1) && (cbcr == y / 2);
283 } 273 }
284 void sycc420_to_rgb(opj_image_t* img) { 274 void sycc420_to_rgb(opj_image_t* img) {
285 if (!sycc420_size_is_valid(img))
286 return;
287
288 OPJ_UINT32 prec = img->comps[0].prec; 275 OPJ_UINT32 prec = img->comps[0].prec;
289 if (!prec) 276 if (!prec)
290 return; 277 return;
291 OPJ_UINT32 offset = 1 << (prec - 1); 278 OPJ_UINT32 offset = 1 << (prec - 1);
292 OPJ_UINT32 upb = (1 << prec) - 1; 279 OPJ_UINT32 upb = (1 << prec) - 1;
293 OPJ_UINT32 yw = img->comps[0].w; 280 OPJ_UINT32 yw = img->comps[0].w;
294 OPJ_UINT32 yh = img->comps[0].h; 281 OPJ_UINT32 yh = img->comps[0].h;
295 OPJ_UINT32 cbw = img->comps[1].w; 282 OPJ_UINT32 cbw = img->comps[1].w;
296 OPJ_UINT32 cbh = img->comps[1].h; 283 OPJ_UINT32 cbh = img->comps[1].h;
297 OPJ_UINT32 crw = img->comps[2].w; 284 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;
298 bool extw = sycc420_must_extend_cbcr(yw, cbw); 290 bool extw = sycc420_must_extend_cbcr(yw, cbw);
299 bool exth = sycc420_must_extend_cbcr(yh, cbh); 291 bool exth = sycc420_must_extend_cbcr(yh, cbh);
300 FX_SAFE_DWORD safeSize = yw; 292 FX_SAFE_DWORD safeSize = yw;
301 safeSize *= yh; 293 safeSize *= yh;
302 if (!safeSize.IsValid()) 294 if (!safeSize.IsValid())
303 return; 295 return;
304 int* r = FX_Alloc(int, safeSize.ValueOrDie()); 296 int* r = FX_Alloc(int, safeSize.ValueOrDie());
305 int* g = FX_Alloc(int, safeSize.ValueOrDie()); 297 int* g = FX_Alloc(int, safeSize.ValueOrDie());
306 int* b = FX_Alloc(int, safeSize.ValueOrDie()); 298 int* b = FX_Alloc(int, safeSize.ValueOrDie());
307 int* d0 = r; 299 int* d0 = r;
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, 878 bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder,
887 uint8_t* dest_data, 879 uint8_t* dest_data,
888 int pitch, 880 int pitch,
889 const std::vector<uint8_t>& offsets) { 881 const std::vector<uint8_t>& offsets) {
890 return pDecoder->Decode(dest_data, pitch, offsets); 882 return pDecoder->Decode(dest_data, pitch, offsets);
891 } 883 }
892 884
893 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { 885 void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) {
894 delete pDecoder; 886 delete pDecoder;
895 } 887 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698