Changeset 47841 in webkit


Ignore:
Timestamp:
Aug 27, 2009 4:16:32 PM (15 years ago)
Author:
pkasting@chromium.org
Message:

https://bugs.webkit.org/show_bug.cgi?id=28751
Clean up ImageDecoder*.cpp a bit.

Reviewed by Eric Seidel.

  • platform/image-decoders/ImageDecoder.cpp: Put functions in the same order as in the header file. Also, since there's already an anonymous namespace in this file, use it to enclose the local helper functions.

(WebCore::):
(WebCore::ImageDecoder::upperBoundScaledX):
(WebCore::ImageDecoder::lowerBoundScaledX):
(WebCore::ImageDecoder::scaledY):

  • platform/image-decoders/cairo/ImageDecoderCairo.cpp:

(WebCore::RGBA32Buffer::width): Style fix.
(WebCore::RGBA32Buffer::height): Style fix.

  • platform/image-decoders/haiku/ImageDecoderHaiku.cpp:

(WebCore::RGBA32Buffer::copyBitmapData): Ensure m_size is set correctly.
(WebCore::RGBA32Buffer::asNewNativeImage): Remove unneeded temp.
(WebCore::RGBA32Buffer::operator=): Simplify.

  • platform/image-decoders/wx/ImageDecoderWx.cpp:

(WebCore::RGBA32Buffer::asNewNativeImage): Try and collect spaced-out temps under loop comment to show they're all related. Use size_t for iterating over elements of a Vector.
(WebCore::RGBA32Buffer::width): Style fix.
(WebCore::RGBA32Buffer::height): Style fix.

Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r47840 r47841  
     12009-08-27  Peter Kasting  <pkasting@google.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=28751
     6        Clean up ImageDecoder*.cpp a bit.
     7
     8        * platform/image-decoders/ImageDecoder.cpp: Put functions in the same
     9          order as in the header file.  Also, since there's already an anonymous
     10          namespace in this file, use it to enclose the local helper functions.
     11        (WebCore::):
     12        (WebCore::ImageDecoder::upperBoundScaledX):
     13        (WebCore::ImageDecoder::lowerBoundScaledX):
     14        (WebCore::ImageDecoder::scaledY):
     15        * platform/image-decoders/cairo/ImageDecoderCairo.cpp:
     16        (WebCore::RGBA32Buffer::width): Style fix.
     17        (WebCore::RGBA32Buffer::height): Style fix.
     18        * platform/image-decoders/haiku/ImageDecoderHaiku.cpp:
     19        (WebCore::RGBA32Buffer::copyBitmapData): Ensure m_size is set correctly.
     20        (WebCore::RGBA32Buffer::asNewNativeImage): Remove unneeded temp.
     21        (WebCore::RGBA32Buffer::operator=): Simplify.
     22        * platform/image-decoders/wx/ImageDecoderWx.cpp:
     23        (WebCore::RGBA32Buffer::asNewNativeImage): Try and collect spaced-out temps under loop comment to show they're all related.  Use size_t for iterating over elements of a Vector.
     24        (WebCore::RGBA32Buffer::width): Style fix.
     25        (WebCore::RGBA32Buffer::height): Style fix.
     26
    1272009-08-27  Peter Kasting  <pkasting@google.com>
    228
  • trunk/WebCore/platform/image-decoders/ImageDecoder.cpp

    r47836 r47841  
    3939};
    4040
     41inline void fillScaledValues(Vector<int>& scaledValues, double scaleRate, int length)
     42{
     43    double inflateRate = 1. / scaleRate;
     44    scaledValues.reserveCapacity(static_cast<int>(length * scaleRate + 0.5));
     45    for (int scaledIndex = 0;;) {
     46        int index = static_cast<int>(scaledIndex * inflateRate + 0.5);
     47        if (index < length) {
     48            scaledValues.append(index);
     49            ++scaledIndex;
     50        } else
     51            break;
     52    }
    4153}
    4254
    43 template <MatchType type> static int getScaledValue(const Vector<int>& scaledValues, int valueToMatch, int searchStart)
     55template <MatchType type> int getScaledValue(const Vector<int>& scaledValues, int valueToMatch, int searchStart)
    4456{
    4557    const int* dataStart = scaledValues.data();
     
    5769}
    5870
    59 int ImageDecoder::upperBoundScaledX(int origX, int searchStart)
    60 {
    61     return getScaledValue<UpperBound>(m_scaledColumns, origX, searchStart);
    62 }
    63 
    64 int ImageDecoder::lowerBoundScaledX(int origX, int searchStart)
    65 {
    66     return getScaledValue<LowerBound>(m_scaledColumns, origX, searchStart);
    67 }
    68 
    69 int ImageDecoder::scaledY(int origY, int searchStart)
    70 {
    71     return getScaledValue<Exact>(m_scaledRows, origY, searchStart);
    72 }
    73 
    74 static inline void fillScaledValues(Vector<int>& scaledValues, double scaleRate, int length)
    75 {
    76     double inflateRate = 1. / scaleRate;
    77     scaledValues.reserveCapacity(static_cast<int>(length * scaleRate + 0.5));
    78     for (int scaledIndex = 0;;) {
    79         int index = static_cast<int>(scaledIndex * inflateRate + 0.5);
    80         if (index < length) {
    81             scaledValues.append(index);
    82             ++scaledIndex;
    83         } else
    84             break;
    85     }
    8671}
    8772
     
    10287}
    10388
     89int ImageDecoder::upperBoundScaledX(int origX, int searchStart)
     90{
     91    return getScaledValue<UpperBound>(m_scaledColumns, origX, searchStart);
     92}
     93
     94int ImageDecoder::lowerBoundScaledX(int origX, int searchStart)
     95{
     96    return getScaledValue<LowerBound>(m_scaledColumns, origX, searchStart);
     97}
     98
     99int ImageDecoder::scaledY(int origY, int searchStart)
     100{
     101    return getScaledValue<Exact>(m_scaledRows, origY, searchStart);
     102}
     103
    104104#endif // ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
    105105
  • trunk/WebCore/platform/image-decoders/cairo/ImageDecoderCairo.cpp

    r44733 r47841  
    114114}
    115115
    116 int RGBA32Buffer::width() const {
     116int RGBA32Buffer::width() const
     117{
    117118    return m_size.width();
    118119}
    119120
    120 int RGBA32Buffer::height() const {
     121int RGBA32Buffer::height() const
     122{
    121123    return m_size.height();
    122124}
  • trunk/WebCore/platform/image-decoders/haiku/ImageDecoderHaiku.cpp

    r46012 r47841  
    2828
    2929#include <Bitmap.h>
    30 
    3130
    3231namespace WebCore {
     
    6261
    6362    m_bytes = other.m_bytes;
     63    m_size = other.m_size;
    6464    setHasAlpha(other.m_hasAlpha);
    6565}
     
    8080NativeImagePtr RGBA32Buffer::asNewNativeImage() const
    8181{
    82     const void* bytes = m_bytes.data();
    83 
    8482    BBitmap* bmp = new BBitmap(BRect(0, 0, width(), height()), B_RGB32);
    85     bmp->SetBits(bytes, m_size.width() * m_size.height(), 0, B_RGB32);
    86 
     83    bmp->SetBits(m_bytes.data(), m_size.width() * m_size.height(), 0, B_RGB32);
    8784    return bmp;
    8885}
     
    108105        return *this;
    109106
    110     m_bytes = other.m_bytes;
    111     m_size = other.m_size;
    112     setHasAlpha(other.hasAlpha());
     107    copyBitmapData(other);
    113108    setRect(other.rect());
    114109    setStatus(other.status());
  • trunk/WebCore/platform/image-decoders/wx/ImageDecoderWx.cpp

    r44733 r47841  
    8787NativeImagePtr RGBA32Buffer::asNewNativeImage() const
    8888{
    89     const unsigned char* bytes = (const unsigned char*)m_bytes.data();
    90    
     89    wxBitmap* bmp = new wxBitmap(width(), height(), 32);
    9190    typedef wxPixelData<wxBitmap, wxAlphaPixelFormat> WxPixelData;
    92 
    93     wxBitmap* bmp = new wxBitmap(width(), height(), 32);
    9491    WxPixelData data(*bmp);
    95    
    96     int rowCounter = 0;
    97     long pixelCounter = 0;
    98    
    99     WxPixelData::Iterator p(data);
    100    
    101     WxPixelData::Iterator rowStart = p;
    10292   
    10393    // NB: It appears that the data is in BGRA format instead of RGBA format.
    10494    // This code works properly on both ppc and intel, meaning the issue is
    10595    // likely not an issue of byte order getting mixed up on different archs.
    106     for (long i = 0; i < m_bytes.size() * sizeof(PixelData); i += sizeof(PixelData)) {
     96    const unsigned char* bytes = (const unsigned char*)m_bytes.data();
     97    int rowCounter = 0;
     98    long pixelCounter = 0;
     99    WxPixelData::Iterator p(data);
     100    WxPixelData::Iterator rowStart = p;
     101    for (size_t i = 0; i < m_bytes.size() * sizeof(PixelData); i += sizeof(PixelData)) {
    107102        p.Red() = bytes[i+2];
    108103        p.Green() = bytes[i+1];
     
    113108
    114109        pixelCounter++;
    115         if ( (pixelCounter % width() ) == 0 ) {
     110        if ((pixelCounter % width()) == 0) {
    116111            rowCounter++;
    117112            p = rowStart;
    118113            p.MoveTo(data, 0, rowCounter);
    119114        }
    120 
    121115    }
    122116#if !wxCHECK_VERSION(2,9,0)
     
    126120
    127121#if USE(WXGC)
    128     wxGraphicsBitmap* bitmap =  new wxGraphicsBitmap(wxGraphicsRenderer::GetDefaultRenderer()->CreateBitmap(*bmp));
     122    wxGraphicsBitmap* bitmap = new wxGraphicsBitmap(wxGraphicsRenderer::GetDefaultRenderer()->CreateBitmap(*bmp));
    129123    delete bmp;
    130124    return bitmap;
     
    162156}
    163157
    164 int RGBA32Buffer::width() const {
     158int RGBA32Buffer::width() const
     159{
    165160    return m_size.width();
    166161}
    167162
    168 int RGBA32Buffer::height() const {
     163int RGBA32Buffer::height() const
     164{
    169165    return m_size.height();
    170166}
Note: See TracChangeset for help on using the changeset viewer.