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

Side by Side Diff: core/src/fxge/dib/fx_dib_composite.cpp

Issue 1145843005: Revert "Remove FX_Alloc() null checks now that it can't return NULL." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 7 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
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 "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #include "../../../include/fxcodec/fx_codec.h" 8 #include "../../../include/fxcodec/fx_codec.h"
9 #include "dib_int.h" 9 #include "dib_int.h"
10 const FX_BYTE g_GammaRamp[256] = { 10 const FX_BYTE g_GammaRamp[256] = {
(...skipping 3583 matching lines...) Expand 10 before | Expand all | Expand 10 after
3594 { 3594 {
3595 ICodec_IccModule* pIccModule = (ICodec_IccModule*)icc_module; 3595 ICodec_IccModule* pIccModule = (ICodec_IccModule*)icc_module;
3596 FX_BOOL isSrcCmyk = src_format & 0x0400 ? TRUE : FALSE; 3596 FX_BOOL isSrcCmyk = src_format & 0x0400 ? TRUE : FALSE;
3597 FX_BOOL isDstCmyk = dest_format & 0x0400 ? TRUE : FALSE; 3597 FX_BOOL isDstCmyk = dest_format & 0x0400 ? TRUE : FALSE;
3598 pDestPalette = NULL; 3598 pDestPalette = NULL;
3599 if (pIccTransform) { 3599 if (pIccTransform) {
3600 if (pSrcPalette) { 3600 if (pSrcPalette) {
3601 if ((dest_format & 0xff) == 8) { 3601 if ((dest_format & 0xff) == 8) {
3602 int pal_count = 1 << (src_format & 0xff); 3602 int pal_count = 1 << (src_format & 0xff);
3603 FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count); 3603 FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count);
3604 if (!gray_pal) {
3605 return;
3606 }
3604 pDestPalette = (FX_DWORD*)gray_pal; 3607 pDestPalette = (FX_DWORD*)gray_pal;
3605 for (int i = 0; i < pal_count; i ++) { 3608 for (int i = 0; i < pal_count; i ++) {
3606 FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i]) : FXARGB_TODIB(pSrcPalette[i]); 3609 FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i]) : FXARGB_TODIB(pSrcPalette[i]);
3607 pIccModule->TranslateScanline(pIccTransform, gray_pal, (FX_L PCBYTE)&color, 1); 3610 pIccModule->TranslateScanline(pIccTransform, gray_pal, (FX_L PCBYTE)&color, 1);
3608 gray_pal ++; 3611 gray_pal ++;
3609 } 3612 }
3610 } else { 3613 } else {
3611 int palsize = 1 << (src_format & 0xff); 3614 int palsize = 1 << (src_format & 0xff);
3612 pDestPalette = FX_Alloc(FX_DWORD, palsize); 3615 pDestPalette = FX_Alloc(FX_DWORD, palsize);
3616 if (!pDestPalette) {
3617 return;
3618 }
3613 for (int i = 0; i < palsize; i ++) { 3619 for (int i = 0; i < palsize; i ++) {
3614 FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i]) : FXARGB_TODIB(pSrcPalette[i]); 3620 FX_DWORD color = isSrcCmyk ? FXCMYK_TODIB(pSrcPalette[i]) : FXARGB_TODIB(pSrcPalette[i]);
3615 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&col or, (FX_LPCBYTE)&color, 1); 3621 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&col or, (FX_LPCBYTE)&color, 1);
3616 pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(color) : FXARGB_T ODIB(color); 3622 pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(color) : FXARGB_T ODIB(color);
3617 } 3623 }
3618 } 3624 }
3619 } else { 3625 } else {
3620 int pal_count = 1 << (src_format & 0xff); 3626 int pal_count = 1 << (src_format & 0xff);
3621 FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count); 3627 FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count);
3628 if (!gray_pal) {
3629 return;
3630 }
3622 if (pal_count == 2) { 3631 if (pal_count == 2) {
3623 gray_pal[0] = 0; 3632 gray_pal[0] = 0;
3624 gray_pal[1] = 255; 3633 gray_pal[1] = 255;
3625 } else { 3634 } else {
3626 for (int i = 0; i < pal_count; i++) { 3635 for (int i = 0; i < pal_count; i++) {
3627 gray_pal[i] = i; 3636 gray_pal[i] = i;
3628 } 3637 }
3629 } 3638 }
3630 if ((dest_format & 0xff) == 8) { 3639 if ((dest_format & 0xff) == 8) {
3631 pIccModule->TranslateScanline(pIccTransform, gray_pal, gray_pal, pal_count); 3640 pIccModule->TranslateScanline(pIccTransform, gray_pal, gray_pal, pal_count);
3632 pDestPalette = (FX_DWORD*)gray_pal; 3641 pDestPalette = (FX_DWORD*)gray_pal;
3633 } else { 3642 } else {
3634 pDestPalette = FX_Alloc(FX_DWORD, pal_count); 3643 pDestPalette = FX_Alloc(FX_DWORD, pal_count);
3644 if (!pDestPalette) {
3645 FX_Free(gray_pal);
3646 return;
3647 }
3635 for (int i = 0; i < pal_count; i ++) { 3648 for (int i = 0; i < pal_count; i ++) {
3636 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&pDe stPalette[i], &gray_pal[i], 1); 3649 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&pDe stPalette[i], &gray_pal[i], 1);
3637 pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(pDestPalette[i]) : FXARGB_TODIB(pDestPalette[i]); 3650 pDestPalette[i] = isDstCmyk ? FXCMYK_TODIB(pDestPalette[i]) : FXARGB_TODIB(pDestPalette[i]);
3638 } 3651 }
3639 FX_Free(gray_pal); 3652 FX_Free(gray_pal);
3640 } 3653 }
3641 } 3654 }
3642 } else { 3655 } else {
3643 if (pSrcPalette) { 3656 if (pSrcPalette) {
3644 if ((dest_format & 0xff) == 8) { 3657 if ((dest_format & 0xff) == 8) {
3645 int pal_count = 1 << (src_format & 0xff); 3658 int pal_count = 1 << (src_format & 0xff);
3646 FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count); 3659 FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count);
3660 if (!gray_pal) {
3661 return;
3662 }
3647 pDestPalette = (FX_DWORD*)gray_pal; 3663 pDestPalette = (FX_DWORD*)gray_pal;
3648 if (isSrcCmyk) { 3664 if (isSrcCmyk) {
3649 for (int i = 0; i < pal_count; i ++) { 3665 for (int i = 0; i < pal_count; i ++) {
3650 FX_CMYK cmyk = pSrcPalette[i]; 3666 FX_CMYK cmyk = pSrcPalette[i];
3651 FX_BYTE r, g, b; 3667 FX_BYTE r, g, b;
3652 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValu e(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), 3668 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValu e(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk),
3653 r, g, b); 3669 r, g, b);
3654 *gray_pal ++ = FXRGB2GRAY(r, g, b); 3670 *gray_pal ++ = FXRGB2GRAY(r, g, b);
3655 } 3671 }
3656 } else 3672 } else
3657 for (int i = 0; i < pal_count; i ++) { 3673 for (int i = 0; i < pal_count; i ++) {
3658 FX_ARGB argb = pSrcPalette[i]; 3674 FX_ARGB argb = pSrcPalette[i];
3659 *gray_pal ++ = FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb) , FXARGB_B(argb)); 3675 *gray_pal ++ = FXRGB2GRAY(FXARGB_R(argb), FXARGB_G(argb) , FXARGB_B(argb));
3660 } 3676 }
3661 } else { 3677 } else {
3662 int palsize = 1 << (src_format & 0xff); 3678 int palsize = 1 << (src_format & 0xff);
3663 pDestPalette = FX_Alloc(FX_DWORD, palsize); 3679 pDestPalette = FX_Alloc(FX_DWORD, palsize);
3680 if (!pDestPalette) {
3681 return;
3682 }
3664 if (isDstCmyk == isSrcCmyk) { 3683 if (isDstCmyk == isSrcCmyk) {
3665 FXSYS_memcpy32(pDestPalette, pSrcPalette, palsize * sizeof(F X_DWORD)); 3684 FXSYS_memcpy32(pDestPalette, pSrcPalette, palsize * sizeof(F X_DWORD));
3666 } else { 3685 } else {
3667 for (int i = 0; i < palsize; i ++) { 3686 for (int i = 0; i < palsize; i ++) {
3668 FX_CMYK cmyk = pSrcPalette[i]; 3687 FX_CMYK cmyk = pSrcPalette[i];
3669 FX_BYTE r, g, b; 3688 FX_BYTE r, g, b;
3670 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValu e(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk), 3689 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(cmyk), FXSYS_GetMValu e(cmyk), FXSYS_GetYValue(cmyk), FXSYS_GetKValue(cmyk),
3671 r, g, b); 3690 r, g, b);
3672 pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b); 3691 pDestPalette[i] = FXARGB_MAKE(0xff, r, g, b);
3673 } 3692 }
3674 } 3693 }
3675 } 3694 }
3676 } else { 3695 } else {
3677 if ((dest_format & 0xff) == 8) { 3696 if ((dest_format & 0xff) == 8) {
3678 int pal_count = 1 << (src_format & 0xff); 3697 int pal_count = 1 << (src_format & 0xff);
3679 FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count); 3698 FX_LPBYTE gray_pal = FX_Alloc(FX_BYTE, pal_count);
3699 if (!gray_pal) {
3700 return;
3701 }
3680 if (pal_count == 2) { 3702 if (pal_count == 2) {
3681 gray_pal[0] = 0; 3703 gray_pal[0] = 0;
3682 gray_pal[1] = 255; 3704 gray_pal[1] = 255;
3683 } else { 3705 } else {
3684 for (int i = 0; i < pal_count; i++) { 3706 for (int i = 0; i < pal_count; i++) {
3685 gray_pal[i] = i; 3707 gray_pal[i] = i;
3686 } 3708 }
3687 } 3709 }
3688 pDestPalette = (FX_DWORD*)gray_pal; 3710 pDestPalette = (FX_DWORD*)gray_pal;
3689 } else { 3711 } else {
3690 int palsize = 1 << (src_format & 0xff); 3712 int palsize = 1 << (src_format & 0xff);
3691 pDestPalette = FX_Alloc(FX_DWORD, palsize); 3713 pDestPalette = FX_Alloc(FX_DWORD, palsize);
3714 if (!pDestPalette) {
3715 return;
3716 }
3692 if (palsize == 2) { 3717 if (palsize == 2) {
3693 pDestPalette[0] = isSrcCmyk ? 255 : 0xff000000; 3718 pDestPalette[0] = isSrcCmyk ? 255 : 0xff000000;
3694 pDestPalette[1] = isSrcCmyk ? 0 : 0xffffffff; 3719 pDestPalette[1] = isSrcCmyk ? 0 : 0xffffffff;
3695 } else { 3720 } else {
3696 for (int i = 0; i < palsize; i++) { 3721 for (int i = 0; i < palsize; i++) {
3697 pDestPalette[i] = isSrcCmyk ? FX_CCOLOR(i) : (i * 0x1010 1); 3722 pDestPalette[i] = isSrcCmyk ? FX_CCOLOR(i) : (i * 0x1010 1);
3698 } 3723 }
3699 } 3724 }
3700 if (isSrcCmyk != isDstCmyk) { 3725 if (isSrcCmyk != isDstCmyk) {
3701 for (int i = 0; i < palsize; i ++) { 3726 for (int i = 0; i < palsize; i ++) {
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
4431 } 4456 }
4432 FX_BOOL CFX_BitmapComposer::SetInfo(int width, int height, FXDIB_Format src_form at, FX_DWORD* pSrcPalette) 4457 FX_BOOL CFX_BitmapComposer::SetInfo(int width, int height, FXDIB_Format src_form at, FX_DWORD* pSrcPalette)
4433 { 4458 {
4434 m_SrcFormat = src_format; 4459 m_SrcFormat = src_format;
4435 if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, pSrcPalett e, m_MaskColor, FXDIB_BLEND_NORMAL, 4460 if (!m_Compositor.Init(m_pBitmap->GetFormat(), src_format, width, pSrcPalett e, m_MaskColor, FXDIB_BLEND_NORMAL,
4436 m_pClipMask != NULL || (m_BitmapAlpha < 255), m_bRgbB yteOrder, m_AlphaFlag, m_pIccTransform)) { 4461 m_pClipMask != NULL || (m_BitmapAlpha < 255), m_bRgbB yteOrder, m_AlphaFlag, m_pIccTransform)) {
4437 return FALSE; 4462 return FALSE;
4438 } 4463 }
4439 if (m_bVertical) { 4464 if (m_bVertical) {
4440 m_pScanlineV = FX_Alloc(FX_BYTE, m_pBitmap->GetBPP() / 8 * width + 4); 4465 m_pScanlineV = FX_Alloc(FX_BYTE, m_pBitmap->GetBPP() / 8 * width + 4);
4466 if (!m_pScanlineV) {
4467 return FALSE;
4468 }
4441 m_pClipScanV = FX_Alloc(FX_BYTE, m_pBitmap->GetHeight()); 4469 m_pClipScanV = FX_Alloc(FX_BYTE, m_pBitmap->GetHeight());
4470 if (!m_pClipScanV) {
4471 return FALSE;
4472 }
4442 if (m_pBitmap->m_pAlphaMask) { 4473 if (m_pBitmap->m_pAlphaMask) {
4443 m_pScanlineAlphaV = FX_Alloc(FX_BYTE, width + 4); 4474 m_pScanlineAlphaV = FX_Alloc(FX_BYTE, width + 4);
4475 if (!m_pScanlineAlphaV) {
4476 return FALSE;
4477 }
4444 } 4478 }
4445 } 4479 }
4446 if (m_BitmapAlpha < 255) { 4480 if (m_BitmapAlpha < 255) {
4447 m_pAddClipScan = FX_Alloc(FX_BYTE, m_bVertical ? m_pBitmap->GetHeight() : m_pBitmap->GetWidth()); 4481 m_pAddClipScan = FX_Alloc(FX_BYTE, m_bVertical ? m_pBitmap->GetHeight() : m_pBitmap->GetWidth());
4482 if (!m_pAddClipScan) {
4483 return FALSE;
4484 }
4448 } 4485 }
4449 return TRUE; 4486 return TRUE;
4450 } 4487 }
4451 void CFX_BitmapComposer::DoCompose(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int dest_width, FX_LPCBYTE clip_scan, 4488 void CFX_BitmapComposer::DoCompose(FX_LPBYTE dest_scan, FX_LPCBYTE src_scan, int dest_width, FX_LPCBYTE clip_scan,
4452 FX_LPCBYTE src_extra_alpha, FX_LPBYTE dst_ext ra_alpha) 4489 FX_LPCBYTE src_extra_alpha, FX_LPBYTE dst_ext ra_alpha)
4453 { 4490 {
4454 if (m_BitmapAlpha < 255) { 4491 if (m_BitmapAlpha < 255) {
4455 if (clip_scan) { 4492 if (clip_scan) {
4456 for (int i = 0; i < dest_width; i ++) { 4493 for (int i = 0; i < dest_width; i ++) {
4457 m_pAddClipScan[i] = clip_scan[i] * m_BitmapAlpha / 255; 4494 m_pAddClipScan[i] = clip_scan[i] * m_BitmapAlpha / 255;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4547 } 4584 }
4548 src_alpha_scan = m_pScanlineAlphaV; 4585 src_alpha_scan = m_pScanlineAlphaV;
4549 dest_alpha_scan = dest_alpha_buf; 4586 dest_alpha_scan = dest_alpha_buf;
4550 if (dest_alpha_scan) { 4587 if (dest_alpha_scan) {
4551 for (i = 0; i < m_DestHeight; i ++) { 4588 for (i = 0; i < m_DestHeight; i ++) {
4552 *dest_alpha_scan = *src_alpha_scan++; 4589 *dest_alpha_scan = *src_alpha_scan++;
4553 dest_alpha_scan += y_alpha_step; 4590 dest_alpha_scan += y_alpha_step;
4554 } 4591 }
4555 } 4592 }
4556 } 4593 }
OLDNEW
« no previous file with comments | « core/src/fxge/agg/agg23/fx_agg_rasterizer_scanline_aa.cpp ('k') | core/src/fxge/dib/fx_dib_convert.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698