Chromium Code Reviews| 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 | 9 |
| 10 #include "../../../include/fxcodec/fx_codec.h" | 10 #include "../../../include/fxcodec/fx_codec.h" |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 && (img->comps[1].dy == 1) | 344 && (img->comps[1].dy == 1) |
| 345 && (img->comps[2].dy == 1)) { | 345 && (img->comps[2].dy == 1)) { |
| 346 sycc444_to_rgb(img); | 346 sycc444_to_rgb(img); |
| 347 } else { | 347 } else { |
| 348 return; | 348 return; |
| 349 } | 349 } |
| 350 img->color_space = OPJ_CLRSPC_SRGB; | 350 img->color_space = OPJ_CLRSPC_SRGB; |
| 351 } | 351 } |
| 352 void color_apply_icc_profile(opj_image_t *image) | 352 void color_apply_icc_profile(opj_image_t *image) |
| 353 { | 353 { |
| 354 cmsHPROFILE in_prof, out_prof; | 354 cmsHPROFILE out_prof; |
| 355 cmsHTRANSFORM transform; | 355 cmsUInt32Number in_type, out_type; |
|
Tom Sepez
2015/05/08 16:03:00
nit: one per line.
Lei Zhang
2015/05/08 18:02:05
Done. I took care of the ints below as well.
| |
| 356 cmsColorSpaceSignature in_space, out_space; | |
| 357 cmsUInt32Number intent, in_type, out_type, nr_samples; | |
| 358 int *r, *g, *b; | 356 int *r, *g, *b; |
| 359 int prec, i, max, max_w, max_h; | 357 int prec, i, max, max_w, max_h; |
| 360 OPJ_COLOR_SPACE oldspace; | 358 cmsHPROFILE in_prof = |
| 361 in_prof = | |
| 362 cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); | 359 cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); |
| 363 if(in_prof == NULL) { | 360 if(in_prof == NULL) { |
| 364 return; | 361 return; |
| 365 } | 362 } |
| 366 in_space = cmsGetPCS(in_prof); | 363 cmsColorSpaceSignature out_space = cmsGetColorSpace(in_prof); |
| 367 out_space = cmsGetColorSpace(in_prof); | 364 cmsUInt32Number intent = cmsGetHeaderRenderingIntent(in_prof); |
| 368 intent = cmsGetHeaderRenderingIntent(in_prof); | |
| 369 max_w = (int)image->comps[0].w; | 365 max_w = (int)image->comps[0].w; |
| 370 max_h = (int)image->comps[0].h; | 366 max_h = (int)image->comps[0].h; |
| 371 prec = (int)image->comps[0].prec; | 367 prec = (int)image->comps[0].prec; |
| 372 oldspace = image->color_space; | 368 OPJ_COLOR_SPACE oldspace = image->color_space; |
| 373 if(out_space == cmsSigRgbData) { | 369 if(out_space == cmsSigRgbData) { |
| 374 if( prec <= 8 ) { | 370 if( prec <= 8 ) { |
| 375 in_type = TYPE_RGB_8; | 371 in_type = TYPE_RGB_8; |
| 376 out_type = TYPE_RGB_8; | 372 out_type = TYPE_RGB_8; |
| 377 } else { | 373 } else { |
| 378 in_type = TYPE_RGB_16; | 374 in_type = TYPE_RGB_16; |
| 379 out_type = TYPE_RGB_16; | 375 out_type = TYPE_RGB_16; |
| 380 } | 376 } |
| 381 out_prof = cmsCreate_sRGBProfile(); | 377 out_prof = cmsCreate_sRGBProfile(); |
| 382 image->color_space = OPJ_CLRSPC_SRGB; | 378 image->color_space = OPJ_CLRSPC_SRGB; |
| 383 } else if(out_space == cmsSigGrayData) { | 379 } else if(out_space == cmsSigGrayData) { |
| 384 if( prec <= 8 ) { | 380 if( prec <= 8 ) { |
| 385 in_type = TYPE_GRAY_8; | 381 in_type = TYPE_GRAY_8; |
| 386 out_type = TYPE_RGB_8; | 382 out_type = TYPE_RGB_8; |
| 387 } else { | 383 } else { |
| 388 in_type = TYPE_GRAY_16; | 384 in_type = TYPE_GRAY_16; |
| 389 out_type = TYPE_RGB_16; | 385 out_type = TYPE_RGB_16; |
| 390 } | 386 } |
| 391 out_prof = cmsCreate_sRGBProfile(); | 387 out_prof = cmsCreate_sRGBProfile(); |
| 392 image->color_space = OPJ_CLRSPC_SRGB; | 388 image->color_space = OPJ_CLRSPC_SRGB; |
| 393 } else if(out_space == cmsSigYCbCrData) { | 389 } else if(out_space == cmsSigYCbCrData) { |
| 394 in_type = TYPE_YCbCr_16; | 390 in_type = TYPE_YCbCr_16; |
| 395 out_type = TYPE_RGB_16; | 391 out_type = TYPE_RGB_16; |
| 396 out_prof = cmsCreate_sRGBProfile(); | 392 out_prof = cmsCreate_sRGBProfile(); |
| 397 image->color_space = OPJ_CLRSPC_SRGB; | 393 image->color_space = OPJ_CLRSPC_SRGB; |
| 398 } else { | 394 } else { |
| 399 return; | 395 return; |
| 400 } | 396 } |
| 401 transform = cmsCreateTransform(in_prof, in_type, | 397 cmsHTRANSFORM transform = |
| 402 out_prof, out_type, intent, 0); | 398 cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0); |
| 403 cmsCloseProfile(in_prof); | 399 cmsCloseProfile(in_prof); |
| 404 cmsCloseProfile(out_prof); | 400 cmsCloseProfile(out_prof); |
| 405 if(transform == NULL) { | 401 if(transform == NULL) { |
| 406 image->color_space = oldspace; | 402 image->color_space = oldspace; |
| 407 return; | 403 return; |
| 408 } | 404 } |
| 409 if(image->numcomps > 2) { | 405 if(image->numcomps > 2) { |
| 410 if( prec <= 8 ) { | 406 if( prec <= 8 ) { |
| 411 unsigned char *inbuf, *outbuf, *in, *out; | 407 unsigned char *inbuf, *outbuf, *in, *out; |
| 412 max = max_w * max_h; | 408 max = max_w * max_h; |
| 413 nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsi gned char); | 409 cmsUInt32Number nr_samples = max * 3 * sizeof(unsigned char); |
| 414 in = inbuf = FX_Alloc(unsigned char, nr_samples); | 410 in = inbuf = FX_Alloc(unsigned char, nr_samples); |
| 415 out = outbuf = FX_Alloc(unsigned char, nr_samples); | 411 out = outbuf = FX_Alloc(unsigned char, nr_samples); |
| 416 r = image->comps[0].data; | 412 r = image->comps[0].data; |
| 417 g = image->comps[1].data; | 413 g = image->comps[1].data; |
| 418 b = image->comps[2].data; | 414 b = image->comps[2].data; |
| 419 for(i = 0; i < max; ++i) { | 415 for(i = 0; i < max; ++i) { |
| 420 *in++ = (unsigned char) * r++; | 416 *in++ = (unsigned char) * r++; |
| 421 *in++ = (unsigned char) * g++; | 417 *in++ = (unsigned char) * g++; |
| 422 *in++ = (unsigned char) * b++; | 418 *in++ = (unsigned char) * b++; |
| 423 } | 419 } |
| 424 cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); | 420 cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); |
| 425 r = image->comps[0].data; | 421 r = image->comps[0].data; |
| 426 g = image->comps[1].data; | 422 g = image->comps[1].data; |
| 427 b = image->comps[2].data; | 423 b = image->comps[2].data; |
| 428 for(i = 0; i < max; ++i) { | 424 for(i = 0; i < max; ++i) { |
| 429 *r++ = (int) * out++; | 425 *r++ = (int) * out++; |
| 430 *g++ = (int) * out++; | 426 *g++ = (int) * out++; |
| 431 *b++ = (int) * out++; | 427 *b++ = (int) * out++; |
| 432 } | 428 } |
| 433 FX_Free(inbuf); | 429 FX_Free(inbuf); |
| 434 FX_Free(outbuf); | 430 FX_Free(outbuf); |
| 435 } else { | 431 } else { |
| 436 unsigned short *inbuf, *outbuf, *in, *out; | 432 unsigned short *inbuf, *outbuf, *in, *out; |
| 437 max = max_w * max_h; | 433 max = max_w * max_h; |
| 438 nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsi gned short); | 434 cmsUInt32Number nr_samples = max * 3 * sizeof(unsigned short); |
| 439 in = inbuf = FX_Alloc(unsigned short, nr_samples); | 435 in = inbuf = FX_Alloc(unsigned short, nr_samples); |
| 440 out = outbuf = FX_Alloc(unsigned short, nr_samples); | 436 out = outbuf = FX_Alloc(unsigned short, nr_samples); |
| 441 r = image->comps[0].data; | 437 r = image->comps[0].data; |
| 442 g = image->comps[1].data; | 438 g = image->comps[1].data; |
| 443 b = image->comps[2].data; | 439 b = image->comps[2].data; |
| 444 for(i = 0; i < max; ++i) { | 440 for(i = 0; i < max; ++i) { |
| 445 *in++ = (unsigned short) * r++; | 441 *in++ = (unsigned short) * r++; |
| 446 *in++ = (unsigned short) * g++; | 442 *in++ = (unsigned short) * g++; |
| 447 *in++ = (unsigned short) * b++; | 443 *in++ = (unsigned short) * b++; |
| 448 } | 444 } |
| 449 cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); | 445 cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); |
| 450 r = image->comps[0].data; | 446 r = image->comps[0].data; |
| 451 g = image->comps[1].data; | 447 g = image->comps[1].data; |
| 452 b = image->comps[2].data; | 448 b = image->comps[2].data; |
| 453 for(i = 0; i < max; ++i) { | 449 for(i = 0; i < max; ++i) { |
| 454 *r++ = (int) * out++; | 450 *r++ = (int) * out++; |
| 455 *g++ = (int) * out++; | 451 *g++ = (int) * out++; |
| 456 *b++ = (int) * out++; | 452 *b++ = (int) * out++; |
| 457 } | 453 } |
| 458 FX_Free(inbuf); | 454 FX_Free(inbuf); |
| 459 FX_Free(outbuf); | 455 FX_Free(outbuf); |
| 460 } | 456 } |
| 461 } else { | 457 } else { |
| 462 unsigned char *in, *inbuf, *out, *outbuf; | 458 unsigned char *in, *inbuf, *out, *outbuf; |
| 463 max = max_w * max_h; | 459 max = max_w * max_h; |
| 464 nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char); | 460 cmsUInt32Number nr_samples = |
| 461 (cmsUInt32Number)max * 3 * sizeof(unsigned char); | |
| 465 in = inbuf = FX_Alloc(unsigned char, nr_samples); | 462 in = inbuf = FX_Alloc(unsigned char, nr_samples); |
| 466 out = outbuf = FX_Alloc(unsigned char, nr_samples); | 463 out = outbuf = FX_Alloc(unsigned char, nr_samples); |
| 467 image->comps = (opj_image_comp_t*) | 464 image->comps = (opj_image_comp_t*) |
| 468 realloc(image->comps, (image->numcomps + 2) * sizeof(opj_ image_comp_t)); | 465 realloc(image->comps, (image->numcomps + 2) * sizeof(opj_ image_comp_t)); |
| 469 if(image->numcomps == 2) { | 466 if(image->numcomps == 2) { |
| 470 image->comps[3] = image->comps[1]; | 467 image->comps[3] = image->comps[1]; |
| 471 } | 468 } |
| 472 image->comps[1] = image->comps[0]; | 469 image->comps[1] = image->comps[0]; |
| 473 image->comps[2] = image->comps[0]; | 470 image->comps[2] = image->comps[0]; |
| 474 image->comps[1].data = FX_Alloc(int, (size_t)max); | 471 image->comps[1].data = FX_Alloc(int, (size_t)max); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 501 numcomps = image->numcomps; | 498 numcomps = image->numcomps; |
| 502 if(numcomps < 3) { | 499 if(numcomps < 3) { |
| 503 return; | 500 return; |
| 504 } | 501 } |
| 505 row = (int*)image->icc_profile_buf; | 502 row = (int*)image->icc_profile_buf; |
| 506 enumcs = row[0]; | 503 enumcs = row[0]; |
| 507 if(enumcs == 14) { | 504 if(enumcs == 14) { |
| 508 int *L, *a, *b, *red, *green, *blue, *src0, *src1, *src2; | 505 int *L, *a, *b, *red, *green, *blue, *src0, *src1, *src2; |
| 509 double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2; | 506 double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2; |
| 510 double minL, maxL, mina, maxa, minb, maxb; | 507 double minL, maxL, mina, maxa, minb, maxb; |
| 511 unsigned int default_type, il; | 508 unsigned int default_type; |
| 512 unsigned int i, max, illu; | 509 unsigned int i, max; |
| 513 cmsHPROFILE in, out; | 510 cmsHPROFILE in, out; |
| 514 cmsHTRANSFORM transform; | 511 cmsHTRANSFORM transform; |
| 515 cmsUInt16Number RGB[3]; | 512 cmsUInt16Number RGB[3]; |
| 516 cmsCIELab Lab; | 513 cmsCIELab Lab; |
| 517 illu = 0; | |
| 518 il = 0; | |
| 519 in = cmsCreateLab4Profile(NULL); | 514 in = cmsCreateLab4Profile(NULL); |
| 520 out = cmsCreate_sRGBProfile(); | 515 out = cmsCreate_sRGBProfile(); |
| 521 transform = | 516 transform = |
| 522 cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, | 517 cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, |
| 523 INTENT_PERCEPTUAL, 0); | 518 INTENT_PERCEPTUAL, 0); |
| 524 cmsCloseProfile(in); | 519 cmsCloseProfile(in); |
| 525 cmsCloseProfile(out); | 520 cmsCloseProfile(out); |
| 526 if(transform == NULL) { | 521 if(transform == NULL) { |
| 527 return; | 522 return; |
| 528 } | 523 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 return TRUE; | 694 return TRUE; |
| 700 } | 695 } |
| 701 void CJPX_Decoder::GetInfo(FX_DWORD& width, FX_DWORD& height, FX_DWORD& codestre am_nComps, FX_DWORD& output_nComps) | 696 void CJPX_Decoder::GetInfo(FX_DWORD& width, FX_DWORD& height, FX_DWORD& codestre am_nComps, FX_DWORD& output_nComps) |
| 702 { | 697 { |
| 703 width = (FX_DWORD)image->x1; | 698 width = (FX_DWORD)image->x1; |
| 704 height = (FX_DWORD)image->y1; | 699 height = (FX_DWORD)image->y1; |
| 705 output_nComps = codestream_nComps = (FX_DWORD)image->numcomps; | 700 output_nComps = codestream_nComps = (FX_DWORD)image->numcomps; |
| 706 } | 701 } |
| 707 FX_BOOL CJPX_Decoder::Decode(FX_LPBYTE dest_buf, int pitch, FX_BOOL bTranslateCo lor, FX_LPBYTE offsets) | 702 FX_BOOL CJPX_Decoder::Decode(FX_LPBYTE dest_buf, int pitch, FX_BOOL bTranslateCo lor, FX_LPBYTE offsets) |
| 708 { | 703 { |
| 709 FX_BYTE** channel_bufs; | |
| 710 int* adjust_comps; | |
| 711 int i, wid, hei, row, col, channel, src; | 704 int i, wid, hei, row, col, channel, src; |
| 712 FX_BOOL flag; | |
| 713 FX_LPBYTE pChannel, pScanline, pPixel; | 705 FX_LPBYTE pChannel, pScanline, pPixel; |
| 714 | 706 |
| 715 if(image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { | 707 if(image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { |
| 716 return FALSE; | 708 return FALSE; |
| 717 } | 709 } |
| 718 if(pitch < (int)(image->comps[0].w * 8 * image->numcomps + 31) >> 5 << 2) { | 710 if(pitch < (int)(image->comps[0].w * 8 * image->numcomps + 31) >> 5 << 2) { |
| 719 return FALSE; | 711 return FALSE; |
| 720 } | 712 } |
| 721 FXSYS_memset8(dest_buf, 0xff, image->y1 * pitch); | 713 FXSYS_memset8(dest_buf, 0xff, image->y1 * pitch); |
| 722 channel_bufs = FX_Alloc(FX_BYTE*, image->numcomps); | 714 FX_BYTE** channel_bufs = FX_Alloc(FX_BYTE*, image->numcomps); |
| 723 if (channel_bufs == NULL) { | 715 if (channel_bufs == NULL) { |
| 724 return FALSE; | 716 return FALSE; |
| 725 } | 717 } |
| 726 adjust_comps = FX_Alloc(int, image->numcomps); | 718 FX_BOOL result = FALSE; |
| 719 int* adjust_comps = FX_Alloc(int, image->numcomps); | |
| 727 if (adjust_comps == NULL) { | 720 if (adjust_comps == NULL) { |
| 728 FX_Free(channel_bufs); | 721 goto done; |
| 729 return FALSE; | |
| 730 } | 722 } |
| 731 flag = TRUE; | |
| 732 for (i = 0; i < (int)image->numcomps; i ++) { | 723 for (i = 0; i < (int)image->numcomps; i ++) { |
| 733 channel_bufs[i] = dest_buf + offsets[i]; | 724 channel_bufs[i] = dest_buf + offsets[i]; |
| 734 adjust_comps[i] = image->comps[i].prec - 8; | 725 adjust_comps[i] = image->comps[i].prec - 8; |
| 735 if(i > 0) { | 726 if(i > 0) { |
| 736 if(image->comps[i].dx != image->comps[i - 1].dx | 727 if(image->comps[i].dx != image->comps[i - 1].dx |
| 737 || image->comps[i].dy != image->comps[i - 1].dy | 728 || image->comps[i].dy != image->comps[i - 1].dy |
| 738 || image->comps[i].prec != image->comps[i - 1].prec) { | 729 || image->comps[i].prec != image->comps[i - 1].prec) { |
| 739 flag = FALSE; | 730 goto done; |
| 740 goto failed; | |
| 741 } | 731 } |
| 742 } | 732 } |
| 743 } | 733 } |
| 744 wid = image->comps[0].w; | 734 wid = image->comps[0].w; |
| 745 hei = image->comps[0].h; | 735 hei = image->comps[0].h; |
| 746 for (channel = 0; channel < (int)image->numcomps; channel++) { | 736 for (channel = 0; channel < (int)image->numcomps; channel++) { |
| 747 pChannel = channel_bufs[channel]; | 737 pChannel = channel_bufs[channel]; |
| 748 if(adjust_comps[channel] < 0) { | 738 if(adjust_comps[channel] < 0) { |
| 749 for(row = 0; row < hei; row++) { | 739 for(row = 0; row < hei; row++) { |
| 750 pScanline = pChannel + row * pitch; | 740 pScanline = pChannel + row * pitch; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 777 tmpPixel = 255; | 767 tmpPixel = 255; |
| 778 } else if (tmpPixel < 0) { | 768 } else if (tmpPixel < 0) { |
| 779 tmpPixel = 0; | 769 tmpPixel = 0; |
| 780 } | 770 } |
| 781 *pPixel = (FX_BYTE)tmpPixel; | 771 *pPixel = (FX_BYTE)tmpPixel; |
| 782 } | 772 } |
| 783 } | 773 } |
| 784 } | 774 } |
| 785 } | 775 } |
| 786 } | 776 } |
| 777 result = TRUE; | |
| 787 | 778 |
| 779 done: | |
| 788 FX_Free(channel_bufs); | 780 FX_Free(channel_bufs); |
| 789 FX_Free(adjust_comps); | 781 FX_Free(adjust_comps); |
| 790 return TRUE; | 782 return result; |
| 791 failed: | |
| 792 FX_Free(channel_bufs); | |
| 793 FX_Free(adjust_comps); | |
| 794 return FALSE; | |
| 795 } | 783 } |
| 796 void initialize_transition_table(); | 784 void initialize_transition_table(); |
| 797 void initialize_significance_luts(); | 785 void initialize_significance_luts(); |
| 798 void initialize_sign_lut(); | 786 void initialize_sign_lut(); |
| 799 CCodec_JpxModule::CCodec_JpxModule() | 787 CCodec_JpxModule::CCodec_JpxModule() |
| 800 { | 788 { |
| 801 } | 789 } |
| 802 void* CCodec_JpxModule::CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size , FX _BOOL useColorSpace) | 790 void* CCodec_JpxModule::CreateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size , FX _BOOL useColorSpace) |
| 803 { | 791 { |
| 804 CJPX_Decoder* pDecoder = new CJPX_Decoder; | 792 CJPX_Decoder* pDecoder = new CJPX_Decoder; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 818 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_B OOL bTranslateColor, FX_LPBYTE offsets) | 806 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_B OOL bTranslateColor, FX_LPBYTE offsets) |
| 819 { | 807 { |
| 820 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 808 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
| 821 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); | 809 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); |
| 822 } | 810 } |
| 823 void CCodec_JpxModule::DestroyDecoder(void* ctx) | 811 void CCodec_JpxModule::DestroyDecoder(void* ctx) |
| 824 { | 812 { |
| 825 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 813 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
| 826 delete pDecoder; | 814 delete pDecoder; |
| 827 } | 815 } |
| OLD | NEW |