GRAPHICS: Implemented debug output for Surface
This commit is contained in:
parent
5e6e9bf74b
commit
ed9c2f97ca
2 changed files with 105 additions and 0 deletions
|
@ -550,6 +550,96 @@ Graphics::Surface *Surface::convertTo(const PixelFormat &dstFormat, const byte *
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Surface::debugPrint(int debuglevel, int width, int height, int x, int y, int scale, int maxwidth, const byte *palette) const {
|
||||||
|
// 012 3456789abcdef
|
||||||
|
const char *gradient = " .:\';+*<?F7RQ&%#";
|
||||||
|
|
||||||
|
if (width <= 0) width = w;
|
||||||
|
if (height <= 0) height = h;
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
if (y < 0) y = 0;
|
||||||
|
|
||||||
|
maxwidth -= 2; // Compensate for the frame
|
||||||
|
if (maxwidth < 0) maxwidth = 80;
|
||||||
|
|
||||||
|
if (scale < 1) {
|
||||||
|
scale = MAX(1, (width + maxwidth - 1) / maxwidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
x = MIN<int>(x, w);
|
||||||
|
y = MIN<int>(y, h);
|
||||||
|
|
||||||
|
int tox = MIN<int>(x + width, w);
|
||||||
|
int toy = MIN<int>(y + height, h);
|
||||||
|
|
||||||
|
debug(debuglevel, "Surface: %d x %d, bpp: %d, format: %s, address: %p", w, h, format.bytesPerPixel, format.toString().c_str(), (void *)this);
|
||||||
|
debug(debuglevel, "displaying: %d x %d @ %d,%d, scale: %d", width, height, x, y, scale);
|
||||||
|
debugN(debuglevel, "+");
|
||||||
|
for (int xx = x; xx < tox; xx += scale)
|
||||||
|
debugN(debuglevel, "-");
|
||||||
|
debug(debuglevel, "+");
|
||||||
|
|
||||||
|
for (int yy = y; yy < toy; yy += scale) {
|
||||||
|
debugN(debuglevel, "|");
|
||||||
|
for (int xx = x; xx < tox; xx += scale) {
|
||||||
|
double grayscale = 0.0;
|
||||||
|
int pixelcount = 0;
|
||||||
|
|
||||||
|
for (int ys = 0; ys < scale && yy + ys < h; ys++) {
|
||||||
|
const byte *srcRow = (const byte *)getBasePtr(xx, yy + ys);
|
||||||
|
|
||||||
|
for (int xs = 0; xs < scale && xx + xs < w; xs++) {
|
||||||
|
byte r, g, b, a;
|
||||||
|
uint32 color;
|
||||||
|
|
||||||
|
switch (format.bytesPerPixel) {
|
||||||
|
case 1: {
|
||||||
|
byte index = *srcRow;
|
||||||
|
|
||||||
|
if (palette) {
|
||||||
|
r = palette[index * 3];
|
||||||
|
g = palette[index * 3 + 1];
|
||||||
|
b = palette[index * 3 + 2];
|
||||||
|
} else {
|
||||||
|
r = g = b = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
a = 0xff;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
color = READ_UINT16(srcRow);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
color = READ_UINT24(srcRow);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
color = READ_UINT32(srcRow);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error("Surface::debugPrint: Unsupported bpp: %d", format.bytesPerPixel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (format.bytesPerPixel > 1)
|
||||||
|
format.colorToARGB(color, a, r, g, b);
|
||||||
|
|
||||||
|
grayscale += (0.29 * r + 0.58 * g + 0.11 * b) / 3.0;
|
||||||
|
pixelcount++;
|
||||||
|
|
||||||
|
srcRow += format.bytesPerPixel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debugN(debuglevel, "%c", gradient[(int)(grayscale / pixelcount / 16)]);
|
||||||
|
}
|
||||||
|
debug(debuglevel, "|");
|
||||||
|
}
|
||||||
|
debugN(debuglevel, "+");
|
||||||
|
for (int xx = x; xx < tox; xx += scale)
|
||||||
|
debugN(debuglevel, "-");
|
||||||
|
debug(debuglevel, "+");
|
||||||
|
}
|
||||||
|
|
||||||
FloodFill::FloodFill(Graphics::Surface *surface, uint32 oldColor, uint32 fillColor, bool maskMode) {
|
FloodFill::FloodFill(Graphics::Surface *surface, uint32 oldColor, uint32 fillColor, bool maskMode) {
|
||||||
_surface = surface;
|
_surface = surface;
|
||||||
_oldColor = oldColor;
|
_oldColor = oldColor;
|
||||||
|
|
|
@ -424,6 +424,21 @@ public:
|
||||||
*/
|
*/
|
||||||
Graphics::Surface *rotoscale(const TransformStruct &transform, bool filtering = false) const;
|
Graphics::Surface *rotoscale(const TransformStruct &transform, bool filtering = false) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print surface content on console in pseudographics
|
||||||
|
*
|
||||||
|
* @param debuglevel debug level to print at, default is 0.
|
||||||
|
* @param width width of the printed area in pixels. Default is 0 which is whole surface.
|
||||||
|
* @param height height of the printed area in pixels. Default is 0 which is whole surface.
|
||||||
|
* @param x horizontal offset to the print area. Default is 0.
|
||||||
|
* @param y vertical offset to the print area. Default is 0.
|
||||||
|
* @param scale number of pixels per single character. Default is -1, fit whole surface to maxwidth
|
||||||
|
* @param maxwidth horizontal size of the print out in characters. Default is 160. Note that 2 characters
|
||||||
|
* are taken by the frame
|
||||||
|
* @param palette ˚palette to use for 1bpp pixels. If omitted, we assume grayscale palette
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void debugPrint(int debuglevel = 0, int width = 0, int height = 0, int x = 0, int y = 0, int scale = -1, int maxwidth = 160, const byte *palette = NULL) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue