GRAPHICS: Add a getSurface() function to JPEG to automatically convert to RGB
svn-id: r55301
This commit is contained in:
parent
5da1718beb
commit
503fdb6147
6 changed files with 69 additions and 40 deletions
|
@ -23,7 +23,9 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "graphics/conversion.h"
|
||||
#include "graphics/jpeg.h"
|
||||
#include "graphics/pixelformat.h"
|
||||
|
||||
#include "common/endian.h"
|
||||
#include "common/util.h"
|
||||
|
@ -73,6 +75,37 @@ JPEG::~JPEG() {
|
|||
reset();
|
||||
}
|
||||
|
||||
Surface *JPEG::getSurface(const PixelFormat &format) {
|
||||
// Make sure we have loaded data
|
||||
if (!isLoaded())
|
||||
return 0;
|
||||
|
||||
// Only accept >8bpp surfaces
|
||||
if (format.bytesPerPixel == 1)
|
||||
return 0;
|
||||
|
||||
// Get our component surfaces
|
||||
Graphics::Surface *yComponent = getComponent(1);
|
||||
Graphics::Surface *uComponent = getComponent(2);
|
||||
Graphics::Surface *vComponent = getComponent(3);
|
||||
|
||||
Graphics::Surface *output = new Graphics::Surface();
|
||||
output->create(yComponent->w, yComponent->h, format.bytesPerPixel);
|
||||
|
||||
for (uint16 i = 0; i < output->h; i++) {
|
||||
for (uint16 j = 0; j < output->w; j++) {
|
||||
byte r = 0, g = 0, b = 0;
|
||||
YUV2RGB(*((byte *)yComponent->getBasePtr(j, i)), *((byte *)uComponent->getBasePtr(j, i)), *((byte *)vComponent->getBasePtr(j, i)), r, g, b);
|
||||
if (format.bytesPerPixel == 2)
|
||||
*((uint16 *)output->getBasePtr(j, i)) = format.RGBToColor(r, g, b);
|
||||
else
|
||||
*((uint32 *)output->getBasePtr(j, i)) = format.RGBToColor(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void JPEG::reset() {
|
||||
// Reset member variables
|
||||
_str = NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue