2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "ImageDecoder.h"
29 // FIXME: Are all these needed?
31 #include <wx/bitmap.h>
33 #include <wx/graphics.h>
36 #include <wx/rawbmp.h>
40 NativeImagePtr ImageFrame::asNewNativeImage() const
42 wxBitmap* bmp = new wxBitmap(width(), height(), 32);
45 typedef wxPixelData<wxBitmap, wxAlphaPixelFormat> WxPixelData;
46 WxPixelData data(*bmp);
48 // NB: It appears that the data is in BGRA format instead of RGBA format.
49 // This code works properly on both ppc and intel, meaning the issue is
50 // likely not an issue of byte order getting mixed up on different archs.
51 const unsigned char* bytes = (const unsigned char*)m_bytes;
53 long pixelCounter = 0;
54 WxPixelData::Iterator p(data);
55 WxPixelData::Iterator rowStart = p;
56 for (size_t i = 0; i < m_size.width() * m_size.height() * sizeof(PixelData); i += sizeof(PixelData)) {
58 p.Alpha() = bytes[i + 3];
59 p.Red() = bytes[i + 2];
60 p.Green() = bytes[i + 1];
61 p.Blue() = bytes[i + 0];
63 p.Alpha() = bytes[i + 0];
64 p.Red() = bytes[i + 1];
65 p.Green() = bytes[i + 2];
66 p.Blue() = bytes[i + 3];
71 if ((pixelCounter % width()) == 0) {
74 p.MoveTo(data, 0, rowCounter);
77 #if !wxCHECK_VERSION(2,9,0)
80 } // ensure that WxPixelData is destroyed as it unlocks the bitmap data in
81 // its dtor and we can't access it (notably in CreateBitmap() below)
82 // before this is done
87 wxGraphicsBitmap* bitmap = new wxGraphicsBitmap(wxGraphicsRenderer::GetDefaultRenderer()->CreateBitmap(*bmp));
95 } // namespace WebCore