Hi Herbert, all,

Le 15 avr. 09 à 09:07, Herbert Duerr a écrit :

Create a SvFileStream/SvMemoryStream/ etc. (see tools/stream.hxx)
Create a PNGReader for that stream (see vcl/pngread.hxx)
Do a Read() on that PNGReader to get the BitmapEx.

Thorsten Behrens (thanks to him ! ) helped me to understand how to play with Streams, and now I got some working code (no more crashes, havePng() returns true, and I can verify the Stream is open and functionnal), but I need your opinion.

At the beginning, I modified the splash.hxx and the splash.cxx accordingly to replace all .bmp with .png equivalents. As summary, the current buffer seems to be ok. , but I continue to see nothing, and this is certainly my fault.

Probably the problem is caused by  SetBackgroundBitmap( _aIntroBmp );

I replaced in SplashScreen::updateStatus() with :

        Point xtopleft(212,216);
        OutputDevice::DrawBitmapEx (xtopleft, _aIntroPng);

... but I'll debug this part later. Anyway, let's do things progressively :-) :

I have pasted some code (including some comments for my own understanding) below, and it would be great to have your opinion, or confirmation it looks ok for you ... or needs changes? As reminder, the real process in the code below involves the following methods : initPng() calling findPng(), itself calling loadBitmap(), and I first had to create the SvStream thing.


Thanks in advance :)
Eric Bachard


Notes:

1) rBmpFileName does contain the .png file name, means ending with .png instead of .bmp

2) _aIntroBitmap is of BitmapEx type

3) the dbg_dump() thing is there for debug purpose only.



// ---------  Quote -------------------
std::auto_ptr< SvStream > wrapStream( SvStream & stream )
{
    std::auto_ptr< SvStream > s(new SvMemoryStream);

// The for loop is there, because we read part by part the bitmap datas, and ignore // how many rounds we will do, except if we know the exact size of the buffer
    // FIXME : stream.GetBufferSize() returns 1024.
// Is it really efficient to use several times ( png size / 1024 ) a full 1024 Bytes buffer // or one pass of (.png size +1) only (and remove this hackish loop...) ?
    for (;;)
    {
// 84010 is the exact size of the .png in bytes, so we need size = 84010 + 1 // other solution is to use stream.GetBufferSize(), but returns 1024 (?)
        // Thorsten suggested 4096 (similar)
        sal_Int32 const size = 84010 + 1;

        //stream.SetBufferSize( size);
        void* data = rtl_allocateMemory( size );

#ifdef DEBUG
fprintf( stderr, " size = stream.GetBufferSize() returns %ld \n", size);
#endif
        // to avoid crashes : stream.Open() before Read() !
        sal_Int32 n = stream.Read(data, size);
        s->Write(data, n);
// condition of output of the loop : the data have been read all
        if (n < size)
            break;
    }
    s->Seek(0);
    return s;
}

bool SplashScreen::loadPng( rtl::OUString const & path, const rtl::OUString &rBmpFileName )
{
    if ( rBmpFileName.getLength() == 0 )
        return false;

    INetURLObject aObj( path, INET_PROT_FILE );
    aObj.insertName( rBmpFileName );

#ifdef DEBUG
    fprintf( stderr, " We are in %s\n", __func__ );
fprintf( stderr, " rBmpFileName contains: %s \n",dbg_dump (rtl::OUString(rBmpFileName))); fprintf( stderr, " aObj.PathToFileName() contains: %s \n",dbg_dump(rtl::OUString(aObj.PathToFileName())));
#endif

if (aObj.PathToFileName().endsWithAsciiL (RTL_CONSTASCII_STRINGPARAM(".png")))
    {
        SvFileStream pStream( aObj.PathToFileName(), STREAM_STD_READ );
        pStream.Open( aObj.PathToFileName(), STREAM_STD_READ  );
        std::auto_ptr< SvStream > s(wrapStream(pStream));

//      probably wrong
//      pStream >> _aIntroPng;

        _aIntroPng = vcl::PNGReader(*s).Read();
        return true;
    }
    else
        return false;
}
// ---------  End Quote -------------------


--
qɔᴉɹə




Reply via email to