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 "core/fxge/include/fx_dib.h" | 7 #include "core/fxge/include/fx_dib.h" |
8 | 8 |
9 #include <limits.h> | |
9 #include <algorithm> | 10 #include <algorithm> |
10 #include <limits.h> | |
11 | 11 |
12 #include "core/fxcodec/include/fx_codec.h" | 12 #include "core/fxcodec/include/fx_codec.h" |
13 #include "core/fxge/dib/dib_int.h" | 13 #include "core/fxge/dib/dib_int.h" |
14 #include "core/fxge/include/fx_ge.h" | 14 #include "core/fxge/include/fx_ge.h" |
15 | 15 |
16 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { | 16 void CmykDecode(uint32_t cmyk, int& c, int& m, int& y, int& k) { |
17 c = FXSYS_GetCValue(cmyk); | 17 c = FXSYS_GetCValue(cmyk); |
18 m = FXSYS_GetMValue(cmyk); | 18 m = FXSYS_GetMValue(cmyk); |
19 y = FXSYS_GetYValue(cmyk); | 19 y = FXSYS_GetYValue(cmyk); |
20 k = FXSYS_GetKValue(cmyk); | 20 k = FXSYS_GetKValue(cmyk); |
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1452 *dest_scan = *src_scan; | 1452 *dest_scan = *src_scan; |
1453 dest_scan--; | 1453 dest_scan--; |
1454 src_scan++; | 1454 src_scan++; |
1455 } | 1455 } |
1456 } | 1456 } |
1457 } | 1457 } |
1458 return pFlipped; | 1458 return pFlipped; |
1459 } | 1459 } |
1460 | 1460 |
1461 CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) { | 1461 CFX_DIBExtractor::CFX_DIBExtractor(const CFX_DIBSource* pSrc) { |
1462 m_pBitmap = nullptr; | |
1463 if (pSrc->GetBuffer()) { | 1462 if (pSrc->GetBuffer()) { |
1464 m_pBitmap = new CFX_DIBitmap; | 1463 m_pBitmap.reset(new CFX_DIBitmap); |
1465 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), | 1464 if (!m_pBitmap->Create(pSrc->GetWidth(), pSrc->GetHeight(), |
1466 pSrc->GetFormat(), pSrc->GetBuffer())) { | 1465 pSrc->GetFormat(), pSrc->GetBuffer())) { |
1467 delete m_pBitmap; | 1466 m_pBitmap.reset(); |
1468 m_pBitmap = nullptr; | |
1469 return; | 1467 return; |
1470 } | 1468 } |
1471 m_pBitmap->CopyPalette(pSrc->GetPalette()); | 1469 m_pBitmap->CopyPalette(pSrc->GetPalette()); |
1472 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); | 1470 m_pBitmap->CopyAlphaMask(pSrc->m_pAlphaMask); |
1473 } else { | 1471 } else { |
1474 m_pBitmap = pSrc->Clone(); | 1472 m_pBitmap.reset(pSrc->Clone()); |
1475 } | 1473 } |
1476 } | 1474 } |
1477 | 1475 |
1478 CFX_DIBExtractor::~CFX_DIBExtractor() { | 1476 CFX_DIBExtractor::~CFX_DIBExtractor() {} |
1479 delete m_pBitmap; | |
1480 } | |
1481 | 1477 |
1482 CFX_FilteredDIB::CFX_FilteredDIB() { | 1478 CFX_FilteredDIB::CFX_FilteredDIB() : m_pSrc(nullptr) {} |
1483 m_pScanline = nullptr; | |
1484 m_pSrc = nullptr; | |
1485 } | |
1486 | 1479 |
1487 CFX_FilteredDIB::~CFX_FilteredDIB() { | 1480 CFX_FilteredDIB::~CFX_FilteredDIB() { |
1488 if (m_bAutoDropSrc) { | 1481 if (m_bAutoDropSrc) { |
1489 delete m_pSrc; | 1482 delete m_pSrc; |
1490 } | 1483 } |
1491 FX_Free(m_pScanline); | |
1492 } | 1484 } |
1493 | 1485 |
1494 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) { | 1486 void CFX_FilteredDIB::LoadSrc(const CFX_DIBSource* pSrc, FX_BOOL bAutoDropSrc) { |
1495 m_pSrc = pSrc; | 1487 m_pSrc = pSrc; |
1496 m_bAutoDropSrc = bAutoDropSrc; | 1488 m_bAutoDropSrc = bAutoDropSrc; |
1497 m_Width = pSrc->GetWidth(); | 1489 m_Width = pSrc->GetWidth(); |
1498 m_Height = pSrc->GetHeight(); | 1490 m_Height = pSrc->GetHeight(); |
1499 FXDIB_Format format = GetDestFormat(); | 1491 FXDIB_Format format = GetDestFormat(); |
1500 m_bpp = (uint8_t)format; | 1492 m_bpp = (uint8_t)format; |
1501 m_AlphaFlag = (uint8_t)(format >> 8); | 1493 m_AlphaFlag = (uint8_t)(format >> 8); |
1502 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; | 1494 m_Pitch = (m_Width * (format & 0xff) + 31) / 32 * 4; |
1503 m_pPalette.reset(GetDestPalette()); | 1495 m_pPalette.reset(GetDestPalette()); |
1504 m_pScanline = FX_Alloc(uint8_t, m_Pitch); | 1496 m_pScanline.resize(m_Pitch); |
1505 } | 1497 } |
1506 | 1498 |
1507 const uint8_t* CFX_FilteredDIB::GetScanline(int line) const { | 1499 const uint8_t* CFX_FilteredDIB::GetScanline(int line) const { |
1508 TranslateScanline(m_pScanline, m_pSrc->GetScanline(line)); | 1500 TranslateScanline(&m_pScanline, m_pSrc->GetScanline(line)); |
1509 return m_pScanline; | 1501 return &m_pScanline[0]; |
Lei Zhang
2016/07/20 23:09:19
Can we return m_pScanline.data() ?
Wei Li
2016/07/21 16:47:07
Done.
| |
1510 } | 1502 } |
1511 | 1503 |
1512 void CFX_FilteredDIB::DownSampleScanline(int line, | 1504 void CFX_FilteredDIB::DownSampleScanline(int line, |
1513 uint8_t* dest_scan, | 1505 uint8_t* dest_scan, |
1514 int dest_bpp, | 1506 int dest_bpp, |
1515 int dest_width, | 1507 int dest_width, |
1516 FX_BOOL bFlipX, | 1508 FX_BOOL bFlipX, |
1517 int clip_left, | 1509 int clip_left, |
1518 int clip_width) const { | 1510 int clip_width) const { |
1519 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, | 1511 m_pSrc->DownSampleScanline(line, dest_scan, dest_bpp, dest_width, bFlipX, |
1520 clip_left, clip_width); | 1512 clip_left, clip_width); |
1521 TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp); | 1513 TranslateDownSamples(dest_scan, dest_scan, clip_width, dest_bpp); |
1522 } | 1514 } |
1523 | 1515 |
1524 CFX_ImageRenderer::CFX_ImageRenderer() { | 1516 CFX_ImageRenderer::CFX_ImageRenderer() { |
1525 m_Status = 0; | 1517 m_Status = 0; |
1526 m_pTransformer = nullptr; | |
1527 m_bRgbByteOrder = FALSE; | 1518 m_bRgbByteOrder = FALSE; |
1528 m_BlendType = FXDIB_BLEND_NORMAL; | 1519 m_BlendType = FXDIB_BLEND_NORMAL; |
1529 } | 1520 } |
1530 | 1521 |
1531 CFX_ImageRenderer::~CFX_ImageRenderer() { | 1522 CFX_ImageRenderer::~CFX_ImageRenderer() {} |
1532 delete m_pTransformer; | |
1533 } | |
1534 | 1523 |
1535 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, | 1524 FX_BOOL CFX_ImageRenderer::Start(CFX_DIBitmap* pDevice, |
1536 const CFX_ClipRgn* pClipRgn, | 1525 const CFX_ClipRgn* pClipRgn, |
1537 const CFX_DIBSource* pSource, | 1526 const CFX_DIBSource* pSource, |
1538 int bitmap_alpha, | 1527 int bitmap_alpha, |
1539 uint32_t mask_color, | 1528 uint32_t mask_color, |
1540 const CFX_Matrix* pMatrix, | 1529 const CFX_Matrix* pMatrix, |
1541 uint32_t dib_flags, | 1530 uint32_t dib_flags, |
1542 FX_BOOL bRgbByteOrder, | 1531 FX_BOOL bRgbByteOrder, |
1543 int alpha_flag, | 1532 int alpha_flag, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1580 m_Stretcher.reset(new CFX_ImageStretcher(&m_Composer, pSource, | 1569 m_Stretcher.reset(new CFX_ImageStretcher(&m_Composer, pSource, |
1581 dest_height, dest_width, | 1570 dest_height, dest_width, |
1582 bitmap_clip, dib_flags)); | 1571 bitmap_clip, dib_flags)); |
1583 if (!m_Stretcher->Start()) | 1572 if (!m_Stretcher->Start()) |
1584 return FALSE; | 1573 return FALSE; |
1585 | 1574 |
1586 m_Status = 1; | 1575 m_Status = 1; |
1587 return TRUE; | 1576 return TRUE; |
1588 } | 1577 } |
1589 m_Status = 2; | 1578 m_Status = 2; |
1590 m_pTransformer = | 1579 m_pTransformer.reset( |
1591 new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox); | 1580 new CFX_ImageTransformer(pSource, &m_Matrix, dib_flags, &m_ClipBox)); |
1592 m_pTransformer->Start(); | 1581 m_pTransformer->Start(); |
1593 return TRUE; | 1582 return TRUE; |
1594 } | 1583 } |
1595 | 1584 |
1596 int dest_width = image_rect.Width(); | 1585 int dest_width = image_rect.Width(); |
1597 if (m_Matrix.a < 0) | 1586 if (m_Matrix.a < 0) |
1598 dest_width = -dest_width; | 1587 dest_width = -dest_width; |
1599 | 1588 |
1600 int dest_height = image_rect.Height(); | 1589 int dest_height = image_rect.Height(); |
1601 if (m_Matrix.d > 0) | 1590 if (m_Matrix.d > 0) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1692 uint32_t* pSrcPalette) { | 1681 uint32_t* pSrcPalette) { |
1693 m_pBitmap.reset(new CFX_DIBitmap); | 1682 m_pBitmap.reset(new CFX_DIBitmap); |
1694 if (!m_pBitmap->Create(width, height, src_format)) { | 1683 if (!m_pBitmap->Create(width, height, src_format)) { |
1695 m_pBitmap.reset(); | 1684 m_pBitmap.reset(); |
1696 return FALSE; | 1685 return FALSE; |
1697 } | 1686 } |
1698 if (pSrcPalette) | 1687 if (pSrcPalette) |
1699 m_pBitmap->CopyPalette(pSrcPalette); | 1688 m_pBitmap->CopyPalette(pSrcPalette); |
1700 return TRUE; | 1689 return TRUE; |
1701 } | 1690 } |
OLD | NEW |