mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-14 21:59:17 +00:00
GRAPHICS: Add functions for getting and setting pixels in a surface
This commit is contained in:
parent
71a741822b
commit
099b593943
@ -174,6 +174,29 @@ public:
|
|||||||
*/
|
*/
|
||||||
DisposeAfterUse::Flag disposeAfterUse() const { return _disposeAfterUse; }
|
DisposeAfterUse::Flag disposeAfterUse() const { return _disposeAfterUse; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the pixel at the specified point.
|
||||||
|
*
|
||||||
|
* @param x The x coordinate of the pixel.
|
||||||
|
* @param y The y coordinate of the pixel.
|
||||||
|
*
|
||||||
|
* @return The value of the pixel.
|
||||||
|
*/
|
||||||
|
inline uint32 getPixel(int x, int y) const {
|
||||||
|
return _innerSurface.getPixel(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the pixel at the specified point.
|
||||||
|
*
|
||||||
|
* @param x The x coordinate of the pixel.
|
||||||
|
* @param y The y coordinate of the pixel.
|
||||||
|
* @param pixel The value of the pixel.
|
||||||
|
*/
|
||||||
|
inline void setPixel(int x, int y, uint32 pixel) {
|
||||||
|
return _innerSurface.setPixel(x, y, pixel);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a pointer to the pixel at the specified point.
|
* Return a pointer to the pixel at the specified point.
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#define GRAPHICS_SURFACE_H
|
#define GRAPHICS_SURFACE_H
|
||||||
|
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
|
#include "common/endian.h"
|
||||||
#include "common/list.h"
|
#include "common/list.h"
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
@ -142,6 +143,47 @@ public:
|
|||||||
return static_cast<byte *>(pixels) + y * pitch + x * format.bytesPerPixel;
|
return static_cast<byte *>(pixels) + y * pitch + x * format.bytesPerPixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the pixel at the specified point.
|
||||||
|
*
|
||||||
|
* @param x The x coordinate of the pixel.
|
||||||
|
* @param y The y coordinate of the pixel.
|
||||||
|
*
|
||||||
|
* @return The value of the pixel.
|
||||||
|
*/
|
||||||
|
inline uint32 getPixel(int x, int y) const {
|
||||||
|
assert(format.bytesPerPixel > 0 && format.bytesPerPixel <= 4);
|
||||||
|
if (format.bytesPerPixel == 1)
|
||||||
|
return *((const uint8 *)getBasePtr(x, y));
|
||||||
|
else if (format.bytesPerPixel == 2)
|
||||||
|
return *((const uint16 *)getBasePtr(x, y));
|
||||||
|
else if (format.bytesPerPixel == 3)
|
||||||
|
return READ_UINT24(getBasePtr(x, y));
|
||||||
|
else if (format.bytesPerPixel == 4)
|
||||||
|
return *((const uint32 *)getBasePtr(x, y));
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the pixel at the specified point.
|
||||||
|
*
|
||||||
|
* @param x The x coordinate of the pixel.
|
||||||
|
* @param y The y coordinate of the pixel.
|
||||||
|
* @param pixel The value of the pixel.
|
||||||
|
*/
|
||||||
|
inline void setPixel(int x, int y, int pixel) {
|
||||||
|
assert(format.bytesPerPixel > 0 && format.bytesPerPixel <= 4);
|
||||||
|
if (format.bytesPerPixel == 1)
|
||||||
|
*((uint8 *)getBasePtr(x, y)) = pixel;
|
||||||
|
else if (format.bytesPerPixel == 2)
|
||||||
|
*((uint16 *)getBasePtr(x, y)) = pixel;
|
||||||
|
else if (format.bytesPerPixel == 3)
|
||||||
|
WRITE_UINT24(getBasePtr(x, y), pixel);
|
||||||
|
else if (format.bytesPerPixel == 4)
|
||||||
|
*((uint32 *)getBasePtr(x, y)) = pixel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate memory for the pixel data of the surface.
|
* Allocate memory for the pixel data of the surface.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user