Using rawbmp.h

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
jansari
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Mar 01, 2006 3:57 pm

Using rawbmp.h

Post by jansari »

I am trying to work with raw images using wxWidgets, and have come across some objects defined in rawbmp.h However it appears that they only work on certain platforms. Can anyone direct to some good information on this library, if it exists. thanks.
leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio »

wxRawBitmap works on all of the major platforms, as far I know. Certainly on wxMSW and wxGTK, I'm pretty sure also on wxMac. The only problem is, that no-one has gotten around to document it yet.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/
Izhaki
Earned a small fee
Earned a small fee
Posts: 13
Joined: Fri Feb 24, 2006 7:06 pm

Post by Izhaki »

Based on a reply I got on the users mailing list it works on MSW, GTK and MAC.

However, I'm having problems using it under MAC (haven't tried GTK and it works perfectly under MSW).

See my additional post on this forum regarding this.

If you need any additional help regarding this library let me know as I've spent quite some time going through the source code, sample, etc.

Cheers
Izhaki
leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio »

Perhaps you could even write some of the documentation for the class? At least list the public members and what they or something. If not latex, then just text - I or someone else can do the necessary converting.
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/
baxissimo
In need of some credit
In need of some credit
Posts: 2
Joined: Wed Feb 01, 2006 8:55 am

Getting raw bitmaps to work

Post by baxissimo »

Hmm, I was trying to use rawbmp.h on Windows, but it wasn't working for me. In the end after some debugging it seemed like it wasn't working because of wxBitmap::UngetRawData not being implemented fully. Here's the code in src/msw/bitmap.cpp:

Code: Select all

void wxBitmap::UngetRawData(wxPixelDataBase& dataBase)
{
#if wxUSE_WXDIB
    if ( !Ok() )
        return;

    if ( !&dataBase )
    {
        // invalid data, don't crash -- but don't assert neither as we're
        // called automatically from wxPixelDataBase dtor and so there is no
        // way to prevent this from happening
        return;
    }

    // if we're a DDB we need to convert DIB back to DDB now to make the
    // changes made via raw bitmap access effective
    if ( !GetBitmapData()->m_isDIB )
    {
        wxDIB *dib = GetBitmapData()->m_dib;
        GetBitmapData()->m_dib = NULL;

        // TODO: convert

        delete dib;
    }
#endif // wxUSE_WXDIB
}
Note the "TODO: convert" bit. Because of this it seemed like my modifications to the raw bitmap weren't making it back to the format actually getting displayed.

At least that's what I concluded at the time.

It would be great to get rid of some of the extra copies that result from drawing things into an offscreen wxImage, then blitting that to the screen. I'm thinking things like wxArt2D that use code like this to copy from a back buffer wxImage to the screen:

Code: Select all

      // copy out and draw just a portion of the offscreen wxImage buffer
      wxBitmap subbitmap( m_buffer.GetSubImage(rect) );
      wxMemoryDC mdc;
      mdc.SelectObject( subbitmap );

      dc->Blit( rect.x - bufferpos.x, rect.y - bufferpos.y, copyw, copyh, 
        &mdc, 0, 0 );

      mdc.SelectObject( wxNullBitmap );
I may have this wrong, but I think GetSubImage returns a copy first off, then the wxBitmap constructor makes another copy, and finally for actually blitting to the DC, the data gets copied again from a DIB to a DDB under the hood of wxBitmap. And then there's the actual blit. Sure would be nice if it were possible to copy directly to the DDB and eliminate a few of those intermediate copies.

Or was I just using it wrong? For what it's worth, here's the code I was trying to use that didn't work:

Code: Select all

    // m_blitbuffer is a wxBitmap
    if (m_blitbuffer.GetWidth() < copyw ||
        m_blitbuffer.GetHeight() < copyh)
    {
       m_blitbuffer = wxBitmap(m_buffer);
    }

      // Try to draw with the minimal number of copies, using the raw
      // interface.  Unfortunately the wxBitmap::UnGetRawData()
      // is not actually implemented right now, so the bits set here never get
      // written back to the underlying DDB.
      {
        typedef wxPixelFormat<unsigned char,32,3,2,1,0> PixFmt;
        //typedef wxNativePixelFormat PixFmt;
        typedef wxPixelData<wxBitmap, PixFmt> PixelData;
        PixelData data(m_blitbuffer);
        if ( data )
        {

          PixelData::Iterator p(data);
          //p.Offset(data, 10, 10);
          unsigned char *imgp = m_buffer.GetData();
          for ( int y = 0; y < copyh; ++y )
          {
            PixelData::Iterator rowStart = p;

            for ( int x = 0; x < copyw; ++x, ++p )
            {
              p.Red()   = imgp[0];
              p.Green() = imgp[1];
              p.Blue()  = imgp[2];
              imgp += 3;
            }

            p = rowStart;
            p.OffsetY(data, 1);
          }
        }
      }
      dc->DrawBitmap(m_blitbuffer,0,0);
Post Reply