Fixed loading of PNG images in the ROMInfoWidget.

Added fallback to FBSurface::drawSurface() in case certain ports don't
want to implement it natively.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2888 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2014-05-09 17:44:04 +00:00
parent e31274c753
commit d57184a4fc
7 changed files with 62 additions and 32 deletions

View File

@ -82,16 +82,10 @@ void FBSurfaceSDL2::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 colo
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurfaceSDL2::drawSurface(const FBSurface* surface, uInt32 tx, uInt32 ty)
void FBSurfaceSDL2::drawSurface(const FBSurface* surface)
{
const FBSurfaceSDL2* s = (const FBSurfaceSDL2*) surface;
SDL_Rect dst;
dst.x = tx;
dst.y = ty;
dst.w = s->mySrcR.w;
dst.h = s->mySrcR.h;
SDL_Rect dst = s->myDstR;
SDL_BlitSurface(s->mySurface, &(s->mySrcR), mySurface, &dst);
}
@ -130,6 +124,18 @@ void FBSurfaceSDL2::setInterpolationAndBlending(
reload();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 FBSurfaceSDL2::width() const
{
return mySurface->w;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt32 FBSurfaceSDL2::height() const
{
return mySurface->h;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const GUI::Rect& FBSurfaceSDL2::srcRect()
{

View File

@ -40,13 +40,16 @@ class FBSurfaceSDL2 : public FBSurface
// the ones implemented here use SDL-specific code for extra performance
//
void fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h, uInt32 color);
void drawSurface(const FBSurface* surface, uInt32 x, uInt32 y);
void drawSurface(const FBSurface* surface);
void addDirtyRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h);
void setStaticContents(const uInt32* pixels, uInt32 pitch);
void setInterpolationAndBlending(bool smoothScale, bool useBlend,
uInt32 blendAlpha);
uInt32 width() const;
uInt32 height() const;
const GUI::Rect& srcRect();
const GUI::Rect& dstRect();
void setSrcPos(uInt32 x, uInt32 y);

View File

@ -52,6 +52,9 @@ class FBSurfaceTIA : public FBSurface
void setInterpolationAndBlending(bool smoothScale, bool useBlend,
uInt32 blendAlpha) { }
uInt32 width() const { return 0; }
uInt32 height() const { return 0; }
const GUI::Rect& srcRect() { return GUI::Rect(); }
const GUI::Rect& dstRect() { return GUI::Rect(); }
///////////////////////////////////////////////////////

View File

@ -310,7 +310,6 @@ bool PNGLibrary::allocateStorage(png_uint_32 w, png_uint_32 h)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void PNGLibrary::scaleImagetoSurface(const FrameBuffer& fb, FBSurface& surface)
{
#if 0 //FIXSDL
// Figure out the original zoom level of the snapshot
// All snapshots generated by Stella are at most some multiple of 320
// pixels wide
@ -320,14 +319,14 @@ void PNGLibrary::scaleImagetoSurface(const FrameBuffer& fb, FBSurface& surface)
// but since Stella only generates snapshots at up to 10x, we should
// be fine for a while ...
uInt32 izoom = uInt32(ceil(ReadInfo.width/320.0)),
szoom = surface.getWidth()/320;
szoom = surface.width()/320;
uInt32 sw = ReadInfo.width / izoom * szoom,
sh = ReadInfo.height / izoom * szoom;
sw = BSPF_min(sw, surface.getWidth());
sh = BSPF_min(sh, surface.getHeight());
surface.setWidth(sw);
surface.setHeight(sh);
sw = BSPF_min(sw, surface.width());
sh = BSPF_min(sh, surface.height());
surface.setSrcSize(sw, sh);
surface.setDstSize(sw, sh);
// Decompress the image, and scale it correctly
uInt32 buf_offset = ReadInfo.pitch * izoom;
@ -357,7 +356,6 @@ void PNGLibrary::scaleImagetoSurface(const FrameBuffer& fb, FBSurface& surface)
while(ystride--)
surface.drawPixels(ReadInfo.line, 0, srow++, sw);
}
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -260,3 +260,21 @@ void FBSurface::drawString(const GUI::Font& font, const string& s,
x += w;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void FBSurface::drawSurface(const FBSurface* surface)
{
const GUI::Rect& srcR = ((FBSurface*)surface)->srcRect();
const GUI::Rect& dstR = ((FBSurface*)surface)->dstRect();
const uInt32* src = surface->myPixels + srcR.y() * surface->myPitch + srcR.x();
uInt32* dst = myPixels + dstR.y() * myPitch + dstR.x();
uInt32 h = srcR.height(), w = srcR.width() * 4;
while(h--)
{
memcpy(dst, src, w);
src += surface->myPitch;
dst += myPitch;
}
}

View File

@ -195,13 +195,13 @@ class FBSurface
/**
This method should be called copy the contents of the given
surface into the FrameBuffer surface.
surface into the FrameBuffer surface. No scaling is done; that is,
a straight-forward copy of the surface pixels is done at the specified
destination.
@param surface The data to draw
@param x The x coordinate
@param y The y coordinate
*/
virtual void drawSurface(const FBSurface* surface, uInt32 x, uInt32 y) { }
virtual void drawSurface(const FBSurface* surface);
/**
This method should be called to add a dirty rectangle
@ -223,7 +223,15 @@ class FBSurface
//////////////////////////////////////////////////////////////////////////
/**
These methods answer the current dimensions of the specified surface.
These methods answer the current *real* dimensions of the specified
surface.
*/
virtual uInt32 width() const = 0;
virtual uInt32 height() const = 0;
/**
These methods answer the current *rendering* dimensions of the
specified surface.
*/
virtual const GUI::Rect& srcRect() = 0;
virtual const GUI::Rect& dstRect() = 0;

View File

@ -86,7 +86,6 @@ void RomInfoWidget::clearProperties()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void RomInfoWidget::parseProperties()
{
#if 0 //FIXSDL
// Check if a surface has ever been created; if so, we use it
// The surface will always be the maximum size, but sometimes we'll
// only draw certain parts of it
@ -97,11 +96,6 @@ void RomInfoWidget::parseProperties()
320*myZoomLevel, 256*myZoomLevel);
mySurface = instance().frameBuffer().surface(mySurfaceID);
}
else
{
mySurface->setWidth(320*myZoomLevel);
mySurface->setHeight(256*myZoomLevel);
}
// Initialize to empty properties entry
mySurfaceErrorMsg = "";
@ -132,7 +126,6 @@ void RomInfoWidget::parseProperties()
myRomInfo.push_back("Note: " + myProperties.get(Cartridge_Note));
myRomInfo.push_back("Controllers: " + myProperties.get(Controller_Left) +
" (left), " + myProperties.get(Controller_Right) + " (right)");
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -150,10 +143,11 @@ void RomInfoWidget::drawWidget(bool hilite)
if(mySurfaceIsValid)
{
const GUI::Rect& r = mySurface->dstRect();
uInt32 x = _x + ((_w - r.width()) >> 1);
uInt32 y = _y + ((yoff - r.height()) >> 1);
s.drawSurface(mySurface, x, y);
const GUI::Rect& src = mySurface->srcRect();
uInt32 x = _x + ((_w - src.width()) >> 1);
uInt32 y = _y + ((yoff - src.height()) >> 1);
mySurface->setDstPos(x, y);
s.drawSurface(mySurface);
}
else if(mySurfaceErrorMsg != "")
{