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

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

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