| 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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 int i, wid, hei, row, col, channel, src; | 707 int i, wid, hei, row, col, channel, src; |
| 708 FX_LPBYTE pChannel, pScanline, pPixel; | 708 FX_LPBYTE pChannel, pScanline, pPixel; |
| 709 | 709 |
| 710 if(image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { | 710 if(image->comps[0].w != image->x1 || image->comps[0].h != image->y1) { |
| 711 return FALSE; | 711 return FALSE; |
| 712 } | 712 } |
| 713 if(pitch < (int)(image->comps[0].w * 8 * image->numcomps + 31) >> 5 << 2) { | 713 if(pitch < (int)(image->comps[0].w * 8 * image->numcomps + 31) >> 5 << 2) { |
| 714 return FALSE; | 714 return FALSE; |
| 715 } | 715 } |
| 716 FXSYS_memset8(dest_buf, 0xff, image->y1 * pitch); | 716 FXSYS_memset8(dest_buf, 0xff, image->y1 * pitch); |
| 717 FX_BYTE** channel_bufs = FX_Alloc(FX_BYTE*, image->numcomps); | 717 uint8_t** channel_bufs = FX_Alloc(uint8_t*, image->numcomps); |
| 718 FX_BOOL result = FALSE; | 718 FX_BOOL result = FALSE; |
| 719 int* adjust_comps = FX_Alloc(int, image->numcomps); | 719 int* adjust_comps = FX_Alloc(int, image->numcomps); |
| 720 for (i = 0; i < (int)image->numcomps; i ++) { | 720 for (i = 0; i < (int)image->numcomps; i ++) { |
| 721 channel_bufs[i] = dest_buf + offsets[i]; | 721 channel_bufs[i] = dest_buf + offsets[i]; |
| 722 adjust_comps[i] = image->comps[i].prec - 8; | 722 adjust_comps[i] = image->comps[i].prec - 8; |
| 723 if(i > 0) { | 723 if(i > 0) { |
| 724 if(image->comps[i].dx != image->comps[i - 1].dx | 724 if(image->comps[i].dx != image->comps[i - 1].dx |
| 725 || image->comps[i].dy != image->comps[i - 1].dy | 725 || image->comps[i].dy != image->comps[i - 1].dy |
| 726 || image->comps[i].prec != image->comps[i - 1].prec) { | 726 || image->comps[i].prec != image->comps[i - 1].prec) { |
| 727 goto done; | 727 goto done; |
| 728 } | 728 } |
| 729 } | 729 } |
| 730 } | 730 } |
| 731 wid = image->comps[0].w; | 731 wid = image->comps[0].w; |
| 732 hei = image->comps[0].h; | 732 hei = image->comps[0].h; |
| 733 for (channel = 0; channel < (int)image->numcomps; channel++) { | 733 for (channel = 0; channel < (int)image->numcomps; channel++) { |
| 734 pChannel = channel_bufs[channel]; | 734 pChannel = channel_bufs[channel]; |
| 735 if(adjust_comps[channel] < 0) { | 735 if(adjust_comps[channel] < 0) { |
| 736 for(row = 0; row < hei; row++) { | 736 for(row = 0; row < hei; row++) { |
| 737 pScanline = pChannel + row * pitch; | 737 pScanline = pChannel + row * pitch; |
| 738 for (col = 0; col < wid; col++) { | 738 for (col = 0; col < wid; col++) { |
| 739 pPixel = pScanline + col * image->numcomps; | 739 pPixel = pScanline + col * image->numcomps; |
| 740 src = image->comps[channel].data[row * wid + col]; | 740 src = image->comps[channel].data[row * wid + col]; |
| 741 src += image->comps[channel].sgnd ? 1 << (image->comps[chann
el].prec - 1) : 0; | 741 src += image->comps[channel].sgnd ? 1 << (image->comps[chann
el].prec - 1) : 0; |
| 742 if (adjust_comps[channel] > 0) { | 742 if (adjust_comps[channel] > 0) { |
| 743 *pPixel = 0; | 743 *pPixel = 0; |
| 744 } else { | 744 } else { |
| 745 *pPixel = (FX_BYTE)(src << -adjust_comps[channel]); | 745 *pPixel = (uint8_t)(src << -adjust_comps[channel]); |
| 746 } | 746 } |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 } else { | 749 } else { |
| 750 for(row = 0; row < hei; row++) { | 750 for(row = 0; row < hei; row++) { |
| 751 pScanline = pChannel + row * pitch; | 751 pScanline = pChannel + row * pitch; |
| 752 for (col = 0; col < wid; col++) { | 752 for (col = 0; col < wid; col++) { |
| 753 pPixel = pScanline + col * image->numcomps; | 753 pPixel = pScanline + col * image->numcomps; |
| 754 if (!image->comps[channel].data) { | 754 if (!image->comps[channel].data) { |
| 755 continue; | 755 continue; |
| 756 } | 756 } |
| 757 src = image->comps[channel].data[row * wid + col]; | 757 src = image->comps[channel].data[row * wid + col]; |
| 758 src += image->comps[channel].sgnd ? 1 << (image->comps[chann
el].prec - 1) : 0; | 758 src += image->comps[channel].sgnd ? 1 << (image->comps[chann
el].prec - 1) : 0; |
| 759 if (adjust_comps[channel] - 1 < 0) { | 759 if (adjust_comps[channel] - 1 < 0) { |
| 760 *pPixel = (FX_BYTE)((src >> adjust_comps[channel])); | 760 *pPixel = (uint8_t)((src >> adjust_comps[channel])); |
| 761 } else { | 761 } else { |
| 762 int tmpPixel = (src >> adjust_comps[channel]) + ((src >>
(adjust_comps[channel] - 1)) % 2); | 762 int tmpPixel = (src >> adjust_comps[channel]) + ((src >>
(adjust_comps[channel] - 1)) % 2); |
| 763 if (tmpPixel > 255) { | 763 if (tmpPixel > 255) { |
| 764 tmpPixel = 255; | 764 tmpPixel = 255; |
| 765 } else if (tmpPixel < 0) { | 765 } else if (tmpPixel < 0) { |
| 766 tmpPixel = 0; | 766 tmpPixel = 0; |
| 767 } | 767 } |
| 768 *pPixel = (FX_BYTE)tmpPixel; | 768 *pPixel = (uint8_t)tmpPixel; |
| 769 } | 769 } |
| 770 } | 770 } |
| 771 } | 771 } |
| 772 } | 772 } |
| 773 } | 773 } |
| 774 result = TRUE; | 774 result = TRUE; |
| 775 | 775 |
| 776 done: | 776 done: |
| 777 FX_Free(channel_bufs); | 777 FX_Free(channel_bufs); |
| 778 FX_Free(adjust_comps); | 778 FX_Free(adjust_comps); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 803 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_B
OOL bTranslateColor, FX_LPBYTE offsets) | 803 FX_BOOL CCodec_JpxModule::Decode(void* ctx, FX_LPBYTE dest_data, int pitch, FX_B
OOL bTranslateColor, FX_LPBYTE offsets) |
| 804 { | 804 { |
| 805 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 805 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
| 806 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); | 806 return pDecoder->Decode(dest_data, pitch, bTranslateColor, offsets); |
| 807 } | 807 } |
| 808 void CCodec_JpxModule::DestroyDecoder(void* ctx) | 808 void CCodec_JpxModule::DestroyDecoder(void* ctx) |
| 809 { | 809 { |
| 810 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; | 810 CJPX_Decoder* pDecoder = (CJPX_Decoder*)ctx; |
| 811 delete pDecoder; | 811 delete pDecoder; |
| 812 } | 812 } |
| OLD | NEW |