Changeset 170675 in webkit


Ignore:
Timestamp:
Jul 1, 2014, 4:26:12 PM (11 years ago)
Author:
[email protected]
Message:

[iOS] Subsampled JPEG images do not draw correctly via the canvas APIs
https://bugs.webkit.org/show_bug.cgi?id=134513
<rdar://problem/12078860>
<rdar://problem/16745393>

Reviewed by Tim Horton.

Source/WebCore:
Subsampled images (e.g. JPEG) were not consistently using
their original dimensions and subsampled dimensions. This caused
things like texImage2D to pack the pixels incorrectly, or drawImage
to squish the rendering.

Renamed m_scale to m_subsamplingScale on FrameData.

Tests: fast/canvas/image-potential-subsample.html

fast/canvas/webgl/tex-image-and-sub-image-2d-with-potentially-subsampled-image.html

  • platform/graphics/BitmapImage.cpp:

(WebCore::BitmapImage::cacheFrame): Rename to m_subsamplingScale.
(WebCore::BitmapImage::frameAtIndex): Ditto.

  • platform/graphics/BitmapImage.h:

(WebCore::FrameData::FrameData): Ditto.

  • platform/graphics/cg/BitmapImageCG.cpp:

(WebCore::FrameData::clear): Ditto.
(WebCore::BitmapImage::BitmapImage): Ditto.
(WebCore::BitmapImage::draw): Use a scaledSrcRect that reflects the subsampled size,
rather than assuming the srcRect accurately reflects how many pixels we have
in the Bitmap.
(WebCore::BitmapImage::copyUnscaledFrameAtIndex):

  • platform/graphics/cg/GraphicsContext3DCG.cpp:

(WebCore::GraphicsContext3D::ImageExtractor::extractImage): Similar fix, although this
time we just ask the image decoder to take into account the subsampled size
when it is "generating" a frame, causing it to use the bitmap data it has already
decoded.

LayoutTests:
Add Canvas2D and WebGL tests that exercise a very large JPEG image.

The WebGL test is mostly copied from the WebGL test suite, so please
excuse the coding style.

  • fast/canvas/image-potential-subsample-expected.txt: Added.
  • fast/canvas/image-potential-subsample.html: Added.
  • fast/canvas/resources/image-8000x8000.jpg: Added.
  • fast/canvas/webgl/resources/tex-image-and-sub-image-2d-with-potentially-subsampled-image.js: Added.

(.init):
(.runOneIteration):
(.runTestOnImage):
(.runTest):
(generateTest):

  • fast/canvas/webgl/tex-image-and-sub-image-2d-with-potentially-subsampled-image-expected.txt: Added.
  • fast/canvas/webgl/tex-image-and-sub-image-2d-with-potentially-subsampled-image.html: Added.
Location:
trunk
Files:
6 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r170661 r170675  
     12014-07-01  Dean Jackson  <[email protected]>
     2
     3        [iOS] Subsampled JPEG images do not draw correctly via the canvas APIs
     4        https://bugs.webkit.org/show_bug.cgi?id=134513
     5        <rdar://problem/12078860>
     6        <rdar://problem/16745393>
     7
     8        Reviewed by Tim Horton.
     9
     10        Add Canvas2D and WebGL tests that exercise a very large JPEG image.
     11
     12        The WebGL test is mostly copied from the WebGL test suite, so please
     13        excuse the coding style.
     14
     15        * fast/canvas/image-potential-subsample-expected.txt: Added.
     16        * fast/canvas/image-potential-subsample.html: Added.
     17        * fast/canvas/resources/image-8000x8000.jpg: Added.
     18        * fast/canvas/webgl/resources/tex-image-and-sub-image-2d-with-potentially-subsampled-image.js: Added.
     19        (.init):
     20        (.runOneIteration):
     21        (.runTestOnImage):
     22        (.runTest):
     23        (generateTest):
     24        * fast/canvas/webgl/tex-image-and-sub-image-2d-with-potentially-subsampled-image-expected.txt: Added.
     25        * fast/canvas/webgl/tex-image-and-sub-image-2d-with-potentially-subsampled-image.html: Added.
     26
    1272014-07-01  Chris Fleizach  <[email protected]>
    228
  • trunk/Source/WebCore/ChangeLog

    r170665 r170675  
     12014-07-01  Dean Jackson  <[email protected]>
     2
     3        [iOS] Subsampled JPEG images do not draw correctly via the canvas APIs
     4        https://bugs.webkit.org/show_bug.cgi?id=134513
     5        <rdar://problem/12078860>
     6        <rdar://problem/16745393>
     7
     8        Reviewed by Tim Horton.
     9
     10        Subsampled images (e.g. JPEG) were not consistently using
     11        their original dimensions and subsampled dimensions. This caused
     12        things like texImage2D to pack the pixels incorrectly, or drawImage
     13        to squish the rendering.
     14
     15        Renamed m_scale to m_subsamplingScale on FrameData.
     16
     17        Tests: fast/canvas/image-potential-subsample.html
     18               fast/canvas/webgl/tex-image-and-sub-image-2d-with-potentially-subsampled-image.html
     19
     20        * platform/graphics/BitmapImage.cpp:
     21        (WebCore::BitmapImage::cacheFrame): Rename to m_subsamplingScale.
     22        (WebCore::BitmapImage::frameAtIndex): Ditto.
     23        * platform/graphics/BitmapImage.h:
     24        (WebCore::FrameData::FrameData): Ditto.
     25        * platform/graphics/cg/BitmapImageCG.cpp:
     26        (WebCore::FrameData::clear): Ditto.
     27        (WebCore::BitmapImage::BitmapImage): Ditto.
     28        (WebCore::BitmapImage::draw): Use a scaledSrcRect that reflects the subsampled size,
     29        rather than assuming the srcRect accurately reflects how many pixels we have
     30        in the Bitmap.
     31        (WebCore::BitmapImage::copyUnscaledFrameAtIndex):
     32        * platform/graphics/cg/GraphicsContext3DCG.cpp:
     33        (WebCore::GraphicsContext3D::ImageExtractor::extractImage): Similar fix, although this
     34        time we just ask the image decoder to take into account the subsampled size
     35        when it is "generating" a frame, causing it to use the bitmap data it has already
     36        decoded.
     37
    1382014-07-01  Joseph Pecoraro  <[email protected]>
    239
  • trunk/Source/WebCore/platform/graphics/BitmapImage.cpp

    r167497 r170675  
    167167#if PLATFORM(IOS)
    168168    m_frames[index].m_frame = m_source.createFrameAtIndex(index, &scaleHint);
    169     m_frames[index].m_scale = scaleHint;
     169    m_frames[index].m_subsamplingScale = scaleHint;
    170170#else
    171171    m_frames[index].m_frame = m_source.createFrameAtIndex(index);
     
    432432    if (index >= m_frames.size() || !m_frames[index].m_frame)
    433433        cacheFrame(index, scaleHint);
    434     else if (std::min(1.0f, scaleHint) > m_frames[index].m_scale) {
     434    else if (std::min(1.0f, scaleHint) > m_frames[index].m_subsamplingScale) {
    435435        // If the image is already cached, but at too small a size, re-decode a larger version.
    436436        int sizeChange = -m_frames[index].m_frameBytes;
  • trunk/Source/WebCore/platform/graphics/BitmapImage.h

    r167356 r170675  
    7272        , m_orientation(DefaultImageOrientation)
    7373#if PLATFORM(IOS)
    74         , m_scale(0)
     74        , m_subsamplingScale(0)
    7575        , m_haveInfo(false)
    7676#endif
     
    9595    ImageOrientation m_orientation;
    9696#if PLATFORM(IOS)
    97     float m_scale;
     97    float m_subsamplingScale;
    9898    bool m_haveInfo;
    9999#endif
  • trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp

    r167375 r170675  
    6262#if PLATFORM(IOS)
    6363    m_frameBytes = 0;
    64     m_scale = 1;
     64    m_subsamplingScale = 1;
    6565    m_haveInfo = false;
    6666#endif
     
    115115
    116116#if PLATFORM(IOS)
    117     m_frames[0].m_scale = 1;
     117    m_frames[0].m_subsamplingScale = 1;
    118118#endif
    119119
     
    200200{
    201201    CGImageRef image;
    202 #if !PLATFORM(IOS)
    203     startAnimation();
    204 
    205     image = frameAtIndex(m_currentFrame);
    206 #else
     202    FloatRect srcRectForCurrentFrame = srcRect;
     203
     204#if PLATFORM(IOS)
     205    if (m_originalSize.width() && m_originalSize.height())
     206        srcRectForCurrentFrame.scale(m_size.width() / static_cast<float>(m_originalSize.width()), m_size.height() / static_cast<float>(m_originalSize.height()));
     207
    207208    startAnimation(DoNotCatchUp);
    208209
     
    213214        imagePossiblyCopied = adoptCF(copyUnscaledFrameAtIndex(m_currentFrame));
    214215    else
    215         imagePossiblyCopied = frameAtIndex(m_currentFrame, std::min<float>(1.0f, std::max(transformedDestinationRect.size.width  / srcRect.width(), transformedDestinationRect.size.height / srcRect.height())));
    216    
     216        imagePossiblyCopied = frameAtIndex(m_currentFrame, std::min<float>(1.0f, std::max(transformedDestinationRect.size.width  / srcRectForCurrentFrame.width(), transformedDestinationRect.size.height / srcRectForCurrentFrame.height())));
     217
    217218    image = imagePossiblyCopied.get();
    218 #endif
     219#else
     220    startAnimation();
     221
     222    image = frameAtIndex(m_currentFrame);
     223#endif
     224
    219225    if (!image) // If it's too early we won't have an image yet.
    220226        return;
     
    227233    float scale = 1;
    228234#if PLATFORM(IOS)
    229     scale = m_frames[m_currentFrame].m_scale;
     235    scale = m_frames[m_currentFrame].m_subsamplingScale;
    230236#endif
    231237    FloatSize selfSize = currentFrameSize();
     
    235241        orientation = frameOrientationAtIndex(m_currentFrame);
    236242
    237     ctxt->drawNativeImage(image, selfSize, styleColorSpace, destRect, srcRect, scale, compositeOp, blendMode, orientation);
     243    ctxt->drawNativeImage(image, selfSize, styleColorSpace, destRect, srcRectForCurrentFrame, scale, compositeOp, blendMode, orientation);
    238244
    239245    if (imageObserver())
     
    250256        cacheFrame(index, 1);
    251257
    252     if (m_frames[index].m_scale == 1 && !m_source.isSubsampled())
     258    if (m_frames[index].m_subsamplingScale == 1 && !m_source.isSubsampled())
    253259        return CGImageRetain(m_frames[index].m_frame);
    254260
  • trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp

    r165676 r170675  
    333333        if (!decoder.frameCount())
    334334            return false;
     335#if PLATFORM(IOS)
     336        float scaleHint = 1;
     337        if (m_image->isBitmapImage()) {
     338            IntSize originalSize = toBitmapImage(m_image)->originalSize();
     339            if (originalSize.width() && originalSize.height())
     340                scaleHint = std::min<float>(1.0f, std::max(m_image->size().width() / originalSize.width(), m_image->size().width() / originalSize.height()));
     341        }
     342        m_decodedImage = adoptCF(decoder.createFrameAtIndex(0, &scaleHint));
     343#else
    335344        m_decodedImage = adoptCF(decoder.createFrameAtIndex(0));
     345#endif
    336346        m_cgImage = m_decodedImage.get();
    337347    } else
Note: See TracChangeset for help on using the changeset viewer.