Changeset 248998 in webkit


Ignore:
Timestamp:
Aug 22, 2019 2:12:33 AM (5 years ago)
Author:
Fujii Hironori
Message:

Remove the dead code of ScalableImageDecoder for scaling
https://bugs.webkit.org/show_bug.cgi?id=200498

Reviewed by Daniel Bates.

No ports are using the down scaling feature of
ScalableImageDecoder now. Removed it.

No behavior change.

  • platform/image-decoders/ScalableImageDecoder.cpp:

(WebCore::ScalableImageDecoder::prepareScaleDataIfNecessary): Deleted.
(WebCore::ScalableImageDecoder::upperBoundScaledX): Deleted.
(WebCore::ScalableImageDecoder::lowerBoundScaledX): Deleted.
(WebCore::ScalableImageDecoder::upperBoundScaledY): Deleted.
(WebCore::ScalableImageDecoder::lowerBoundScaledY): Deleted.
(WebCore::ScalableImageDecoder::scaledY): Deleted.

  • platform/image-decoders/ScalableImageDecoder.h:

(WebCore::ScalableImageDecoder::scaledSize): Deleted.

  • platform/image-decoders/gif/GIFImageDecoder.cpp:

(WebCore::GIFImageDecoder::setSize):
(WebCore::GIFImageDecoder::findFirstRequiredFrameToDecode):
(WebCore::GIFImageDecoder::haveDecodedRow):
(WebCore::GIFImageDecoder::frameComplete):
(WebCore::GIFImageDecoder::initFrameBuffer):

  • platform/image-decoders/jpeg/JPEGImageDecoder.cpp:

(WebCore::JPEGImageDecoder::outputScanlines):
(WebCore::JPEGImageDecoder::setSize): Deleted.

  • platform/image-decoders/jpeg/JPEGImageDecoder.h:
  • platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp:

(WebCore::JPEG2000ImageDecoder::decode):

  • platform/image-decoders/png/PNGImageDecoder.cpp:

(WebCore::PNGImageDecoder::rowAvailable):
(WebCore::PNGImageDecoder::initFrameBuffer):
(WebCore::PNGImageDecoder::frameComplete):
(WebCore::PNGImageDecoder::setSize): Deleted.

  • platform/image-decoders/png/PNGImageDecoder.h:
Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248997 r248998  
     12019-08-22  Fujii Hironori  <Hironori.Fujii@sony.com>
     2
     3        Remove the dead code of ScalableImageDecoder for scaling
     4        https://bugs.webkit.org/show_bug.cgi?id=200498
     5
     6        Reviewed by Daniel Bates.
     7
     8        No ports are using the down scaling feature of
     9        ScalableImageDecoder now. Removed it.
     10
     11        No behavior change.
     12
     13        * platform/image-decoders/ScalableImageDecoder.cpp:
     14        (WebCore::ScalableImageDecoder::prepareScaleDataIfNecessary): Deleted.
     15        (WebCore::ScalableImageDecoder::upperBoundScaledX): Deleted.
     16        (WebCore::ScalableImageDecoder::lowerBoundScaledX): Deleted.
     17        (WebCore::ScalableImageDecoder::upperBoundScaledY): Deleted.
     18        (WebCore::ScalableImageDecoder::lowerBoundScaledY): Deleted.
     19        (WebCore::ScalableImageDecoder::scaledY): Deleted.
     20        * platform/image-decoders/ScalableImageDecoder.h:
     21        (WebCore::ScalableImageDecoder::scaledSize): Deleted.
     22        * platform/image-decoders/gif/GIFImageDecoder.cpp:
     23        (WebCore::GIFImageDecoder::setSize):
     24        (WebCore::GIFImageDecoder::findFirstRequiredFrameToDecode):
     25        (WebCore::GIFImageDecoder::haveDecodedRow):
     26        (WebCore::GIFImageDecoder::frameComplete):
     27        (WebCore::GIFImageDecoder::initFrameBuffer):
     28        * platform/image-decoders/jpeg/JPEGImageDecoder.cpp:
     29        (WebCore::JPEGImageDecoder::outputScanlines):
     30        (WebCore::JPEGImageDecoder::setSize): Deleted.
     31        * platform/image-decoders/jpeg/JPEGImageDecoder.h:
     32        * platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp:
     33        (WebCore::JPEG2000ImageDecoder::decode):
     34        * platform/image-decoders/png/PNGImageDecoder.cpp:
     35        (WebCore::PNGImageDecoder::rowAvailable):
     36        (WebCore::PNGImageDecoder::initFrameBuffer):
     37        (WebCore::PNGImageDecoder::frameComplete):
     38        (WebCore::PNGImageDecoder::setSize): Deleted.
     39        * platform/image-decoders/png/PNGImageDecoder.h:
     40
    1412019-08-21  Jer Noble  <jer.noble@apple.com>
    242
  • trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.cpp

    r247014 r248998  
    154154}
    155155
    156 namespace {
    157 
    158 enum MatchType {
    159     Exact,
    160     UpperBound,
    161     LowerBound
    162 };
    163 
    164 inline void fillScaledValues(Vector<int>& scaledValues, double scaleRate, int length)
    165 {
    166     double inflateRate = 1. / scaleRate;
    167     scaledValues.reserveCapacity(static_cast<int>(length * scaleRate + 0.5));
    168     for (int scaledIndex = 0; ; ++scaledIndex) {
    169         int index = static_cast<int>(scaledIndex * inflateRate + 0.5);
    170         if (index >= length)
    171             break;
    172         scaledValues.append(index);
    173     }
    174 }
    175 
    176 template <MatchType type> int getScaledValue(const Vector<int>& scaledValues, int valueToMatch, int searchStart)
    177 {
    178     if (scaledValues.isEmpty())
    179         return valueToMatch;
    180 
    181     const int* dataStart = scaledValues.data();
    182     const int* dataEnd = dataStart + scaledValues.size();
    183     const int* matched = std::lower_bound(dataStart + searchStart, dataEnd, valueToMatch);
    184     switch (type) {
    185     case Exact:
    186         return matched != dataEnd && *matched == valueToMatch ? matched - dataStart : -1;
    187     case LowerBound:
    188         return matched != dataEnd && *matched == valueToMatch ? matched - dataStart : matched - dataStart - 1;
    189     case UpperBound:
    190     default:
    191         return matched != dataEnd ? matched - dataStart : -1;
    192     }
    193 }
    194 
    195 }
    196 
    197156bool ScalableImageDecoder::frameIsCompleteAtIndex(size_t index) const
    198157{
     
    265224}
    266225
    267 void ScalableImageDecoder::prepareScaleDataIfNecessary()
    268 {
    269     m_scaled = false;
    270     m_scaledColumns.clear();
    271     m_scaledRows.clear();
    272 
    273     int width = size().width();
    274     int height = size().height();
    275     int numPixels = height * width;
    276     if (m_maxNumPixels <= 0 || numPixels <= m_maxNumPixels)
    277         return;
    278 
    279     m_scaled = true;
    280     double scale = sqrt(m_maxNumPixels / (double)numPixels);
    281     fillScaledValues(m_scaledColumns, scale, width);
    282     fillScaledValues(m_scaledRows, scale, height);
    283 }
    284 
    285 int ScalableImageDecoder::upperBoundScaledX(int origX, int searchStart)
    286 {
    287     return getScaledValue<UpperBound>(m_scaledColumns, origX, searchStart);
    288 }
    289 
    290 int ScalableImageDecoder::lowerBoundScaledX(int origX, int searchStart)
    291 {
    292     return getScaledValue<LowerBound>(m_scaledColumns, origX, searchStart);
    293 }
    294 
    295 int ScalableImageDecoder::upperBoundScaledY(int origY, int searchStart)
    296 {
    297     return getScaledValue<UpperBound>(m_scaledRows, origY, searchStart);
    298 }
    299 
    300 int ScalableImageDecoder::lowerBoundScaledY(int origY, int searchStart)
    301 {
    302     return getScaledValue<LowerBound>(m_scaledRows, origY, searchStart);
    303 }
    304 
    305 int ScalableImageDecoder::scaledY(int origY, int searchStart)
    306 {
    307     return getScaledValue<Exact>(m_scaledRows, origY, searchStart);
    308 }
    309 
    310226#if USE(DIRECT2D)
    311227void ScalableImageDecoder::setTargetContext(ID2D1RenderTarget*)
  • trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h

    r247014 r248998  
    9999    IntSize size() const override { return isSizeAvailable() ? m_size : IntSize(); }
    100100
    101     IntSize scaledSize()
    102     {
    103         return m_scaled ? IntSize(m_scaledColumns.size(), m_scaledRows.size()) : size();
    104     }
    105 
    106101    // This will only differ from size() for ICO (where each frame is a
    107102    // different icon) or other formats where different frames are different
     
    198193
    199194protected:
    200     void prepareScaleDataIfNecessary();
    201     int upperBoundScaledX(int origX, int searchStart = 0);
    202     int lowerBoundScaledX(int origX, int searchStart = 0);
    203     int upperBoundScaledY(int origY, int searchStart = 0);
    204     int lowerBoundScaledY(int origY, int searchStart = 0);
    205     int scaledY(int origY, int searchStart = 0);
    206 
    207195    RefPtr<SharedBuffer> m_data; // The encoded data.
    208196    Vector<ScalableImageDecoderFrame, 1> m_frameBufferCache;
    209197    mutable Lock m_mutex;
    210     bool m_scaled { false };
    211     Vector<int> m_scaledColumns;
    212     Vector<int> m_scaledRows;
    213198    bool m_premultiplyAlpha;
    214199    bool m_ignoreGammaAndColorProfile;
     
    225210    EncodedDataStatus m_encodedDataStatus { EncodedDataStatus::TypeAvailable };
    226211    bool m_decodingSizeFromSetData { false };
    227 
    228     // FIXME: Evaluate the need for decoded data scaling. m_scaled,
    229     // m_scaledColumns and m_scaledRows are member variables that are
    230     // affected by this value, and are not used at all since the value
    231     // is negavite (see prepareScaleDataIfNecessary()).
    232     static const int m_maxNumPixels { -1 };
    233212};
    234213
  • trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp

    r248846 r248998  
    5454        return true;
    5555
    56     if (!ScalableImageDecoder::setSize(size))
    57         return false;
    58 
    59     prepareScaleDataIfNecessary();
    60     return true;
     56    return ScalableImageDecoder::setSize(size);
    6157}
    6258
     
    127123            ASSERT(frameContext);
    128124            IntRect frameRect(frameContext->xOffset, frameContext->yOffset, frameContext->width, frameContext->height);
    129             // We would need to scale frameRect and check whether it fills the whole scaledSize(). But
    130             // can check whether the original frameRect fills size() instead. If the frame fills the
    131             // whole area then it can be decoded without dependencies.
    132125            if (frameRect.contains({ { }, size() }))
    133126                return i;
     
    217210    // we must ensure we don't run off the end of either the source data or the
    218211    // row's X-coordinates.
    219     int xBegin = upperBoundScaledX(frameContext->xOffset);
    220     int yBegin = upperBoundScaledY(frameContext->yOffset + rowNumber);
    221     int xEnd = lowerBoundScaledX(std::min(static_cast<int>(frameContext->xOffset + width), size().width()) - 1, xBegin + 1) + 1;
    222     int yEnd = lowerBoundScaledY(std::min(static_cast<int>(frameContext->yOffset + rowNumber + repeatCount), size().height()) - 1, yBegin + 1) + 1;
    223     if (rowBuffer.isEmpty() || (xBegin < 0) || (yBegin < 0) || (xEnd <= xBegin) || (yEnd <= yBegin))
     212    int xBegin = frameContext->xOffset;
     213    int yBegin = frameContext->yOffset + rowNumber;
     214    int xEnd = std::min(static_cast<int>(frameContext->xOffset + width), size().width());
     215    int yEnd = std::min(static_cast<int>(frameContext->yOffset + rowNumber + repeatCount), size().height());
     216    if (rowBuffer.isEmpty() || xEnd <= xBegin || yEnd <= yBegin)
    224217        return true;
    225218
     
    245238    // Write one row's worth of data into the frame. 
    246239    for (int x = xBegin; x < xEnd; ++x) {
    247         const unsigned char sourceValue = rowBuffer[(m_scaled ? m_scaledColumns[x] : x) - frameContext->xOffset];
     240        const unsigned char sourceValue = rowBuffer[x - frameContext->xOffset];
    248241        if ((!frameContext->isTransparent || (sourceValue != frameContext->tpixel)) && (sourceValue < colorMapSize)) {
    249242            const size_t colorIndex = static_cast<size_t>(sourceValue) * 3;
     
    288281        // The whole frame was non-transparent, so it's possible that the entire
    289282        // resulting buffer was non-transparent, and we can setHasAlpha(false).
    290         if (rect.contains(IntRect(IntPoint(), scaledSize())))
     283        if (rect.contains(IntRect(IntPoint(), size())))
    291284            buffer.setHasAlpha(false);
    292285        else if (frameIndex) {
     
    375368    if (!frameIndex) {
    376369        // This is the first frame, so we're not relying on any previous data.
    377         if (!buffer->initialize(scaledSize(), m_premultiplyAlpha))
     370        if (!buffer->initialize(size(), m_premultiplyAlpha))
    378371            return setFailed();
    379372    } else {
     
    403396            // affecting pixels in the image outside of the frame.
    404397            IntRect prevRect = prevBuffer->backingStore()->frameRect();
    405             const IntSize& bufferSize = scaledSize();
    406             if (!frameIndex || prevRect.contains(IntRect(IntPoint(), scaledSize()))) {
     398            const IntSize& bufferSize = size();
     399            if (!frameIndex || prevRect.contains(IntRect(IntPoint(), size()))) {
    407400                // Clearing the first frame, or a frame the size of the whole
    408401                // image, results in a completely empty image.
     
    425418        frameRect.setHeight(size().height() - frameContext->yOffset);
    426419
    427     int left = upperBoundScaledX(frameRect.x());
    428     int right = lowerBoundScaledX(frameRect.maxX(), left);
    429     int top = upperBoundScaledY(frameRect.y());
    430     int bottom = lowerBoundScaledY(frameRect.maxY(), top);
    431     buffer->backingStore()->setFrameRect(IntRect(left, top, right - left, bottom - top));
     420    buffer->backingStore()->setFrameRect(frameRect);
    432421
    433422    // Update our status to be partially complete.
  • trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

    r248846 r248998  
    503503JPEGImageDecoder::~JPEGImageDecoder() = default;
    504504
    505 bool JPEGImageDecoder::setSize(const IntSize& size)
    506 {
    507     if (!ScalableImageDecoder::setSize(size))
    508         return false;
    509 
    510     prepareScaleDataIfNecessary();
    511     return true;
    512 }
    513 
    514505ScalableImageDecoderFrame* JPEGImageDecoder::frameBufferAtIndex(size_t index)
    515506{
     
    557548}
    558549
    559 template <J_COLOR_SPACE colorSpace, bool isScaled>
     550template <J_COLOR_SPACE colorSpace>
    560551bool JPEGImageDecoder::outputScanlines(ScalableImageDecoderFrame& buffer)
    561552{
    562553    JSAMPARRAY samples = m_reader->samples();
    563554    jpeg_decompress_struct* info = m_reader->info();
    564     int width = isScaled ? m_scaledColumns.size() : info->output_width;
     555    int width = info->output_width;
    565556
    566557    while (info->output_scanline < info->output_height) {
     
    572563            return false;
    573564
    574         int destY = scaledY(sourceY);
    575         if (destY < 0)
    576             continue;
    577 
    578         auto* currentAddress = buffer.backingStore()->pixelAt(0, destY);
     565        auto* currentAddress = buffer.backingStore()->pixelAt(0, sourceY);
    579566        for (int x = 0; x < width; ++x) {
    580             setPixel<colorSpace>(buffer, currentAddress, samples, isScaled ? m_scaledColumns[x] : x);
     567            setPixel<colorSpace>(buffer, currentAddress, samples, x);
    581568            ++currentAddress;
    582569        }
    583570    }
    584571    return true;
    585 }
    586 
    587 template <J_COLOR_SPACE colorSpace>
    588 bool JPEGImageDecoder::outputScanlines(ScalableImageDecoderFrame& buffer)
    589 {
    590     return m_scaled ? outputScanlines<colorSpace, true>(buffer) : outputScanlines<colorSpace, false>(buffer);
    591572}
    592573
     
    599580    auto& buffer = m_frameBufferCache[0];
    600581    if (buffer.isInvalid()) {
    601         if (!buffer.initialize(scaledSize(), m_premultiplyAlpha))
     582        if (!buffer.initialize(size(), m_premultiplyAlpha))
    602583            return setFailed();
    603584        buffer.setDecodingStatus(DecodingStatus::Partial);
     
    610591
    611592#if defined(TURBO_JPEG_RGB_SWIZZLE)
    612     if (!m_scaled && turboSwizzled(info->out_color_space)) {
     593    if (turboSwizzled(info->out_color_space)) {
    613594        while (info->output_scanline < info->output_height) {
    614595            unsigned char* row = reinterpret_cast<unsigned char*>(buffer.backingStore()->pixelAt(0, info->output_scanline));
     
    621602
    622603    switch (info->out_color_space) {
    623     // The code inside outputScanlines<int, bool> will be executed
     604    // The code inside outputScanlines<int> will be executed
    624605    // for each pixel, so we want to avoid any extra comparisons there.
    625606    // That is why we use template and template specializations here so
  • trunk/Source/WebCore/platform/image-decoders/jpeg/JPEGImageDecoder.h

    r233122 r248998  
    5353        // ScalableImageDecoder
    5454        String filenameExtension() const override { return "jpg"_s; }
    55         bool setSize(const IntSize&) override;
    5655        ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) override;
    5756        // CAUTION: setFailed() deletes |m_reader|.  Be careful to avoid
     
    5958        // JPEGImageReader!
    6059        bool setFailed() override;
    61 
    62         bool willDownSample()
    63         {
    64             ASSERT(ScalableImageDecoder::encodedDataStatus() >= EncodedDataStatus::SizeAvailable);
    65             return m_scaled;
    66         }
    6760
    6861        bool outputScanlines();
  • trunk/Source/WebCore/platform/image-decoders/jpeg2000/JPEG2000ImageDecoder.cpp

    r240428 r248998  
    480480
    481481    auto& buffer = m_frameBufferCache[0];
    482     if (!buffer.initialize(scaledSize(), m_premultiplyAlpha)) {
     482    if (!buffer.initialize(size(), m_premultiplyAlpha)) {
    483483        setFailed();
    484484        return;
  • trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.cpp

    r248846 r248998  
    249249#endif
    250250
    251 bool PNGImageDecoder::setSize(const IntSize& size)
    252 {
    253     if (!ScalableImageDecoder::setSize(size))
    254         return false;
    255 
    256     prepareScaleDataIfNecessary();
    257     return true;
    258 }
    259 
    260251ScalableImageDecoderFrame* PNGImageDecoder::frameBufferAtIndex(size_t index)
    261252{
     
    436427    if (buffer.isInvalid()) {
    437428        png_structp png = m_reader->pngPtr();
    438         if (!buffer.initialize(scaledSize(), m_premultiplyAlpha)) {
     429        if (!buffer.initialize(size(), m_premultiplyAlpha)) {
    439430            longjmp(JMPBUF(png), 1);
    440431            return;
     
    478469    if (!rowBuffer)
    479470        return;
    480     int y = !m_scaled ? rowIndex : scaledY(rowIndex);
    481     if (y < 0 || y >= scaledSize().height())
     471    if (rowIndex >= size().height())
    482472        return;
    483473
     
    517507
    518508    // Write the decoded row pixels to the frame buffer.
    519     auto* address = buffer.backingStore()->pixelAt(0, y);
    520     int width = scaledSize().width();
     509    auto* address = buffer.backingStore()->pixelAt(0, rowIndex);
     510    int width = size().width();
    521511    unsigned char nonTrivialAlphaMask = 0;
    522512
     
    778768        // affecting pixels in the image outside of the frame.
    779769        IntRect prevRect = prevBuffer->backingStore()->frameRect();
    780         if (!frameIndex || prevRect.contains(IntRect(IntPoint(), scaledSize()))) {
     770        if (!frameIndex || prevRect.contains(IntRect(IntPoint(), size()))) {
    781771            // Clearing the first frame, or a frame the size of the whole
    782772            // image, results in a completely empty image.
     
    802792        frameRect.setHeight(size().height() - m_yOffset);
    803793
    804     int left = upperBoundScaledX(frameRect.x());
    805     int right = lowerBoundScaledX(frameRect.maxX(), left);
    806     int top = upperBoundScaledY(frameRect.y());
    807     int bottom = lowerBoundScaledY(frameRect.maxY(), top);
    808     buffer.backingStore()->setFrameRect(IntRect(left, top, right - left, bottom - top));
     794    buffer.backingStore()->setFrameRect(frameRect);
    809795}
    810796
     
    827813            m_blend = 0;
    828814
    829         ASSERT(!m_scaled);
    830815        png_bytep row = interlaceBuffer;
    831816        for (int y = rect.y(); y < rect.maxY(); ++y, row += colorChannels * size().width()) {
     
    844829        if (!nonTrivialAlpha) {
    845830            IntRect rect = buffer.backingStore()->frameRect();
    846             if (rect.contains(IntRect(IntPoint(), scaledSize())))
     831            if (rect.contains(IntRect(IntPoint(), size())))
    847832                buffer.setHasAlpha(false);
    848833            else {
  • trunk/Source/WebCore/platform/image-decoders/png/PNGImageDecoder.h

    r233122 r248998  
    5151        RepetitionCount repetitionCount() const override;
    5252#endif
    53         bool setSize(const IntSize&) override;
    5453        ScalableImageDecoderFrame* frameBufferAtIndex(size_t index) override;
    5554        // CAUTION: setFailed() deletes |m_reader|.  Be careful to avoid
Note: See TracChangeset for help on using the changeset viewer.