diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 2cd9343acd2..4345949d7cd 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -550,6 +550,96 @@ Graphics::Surface *Surface::convertTo(const PixelFormat &dstFormat, const byte * 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 = " .:\';+*(x, w); + y = MIN(y, h); + + int tox = MIN(x + width, w); + int toy = MIN(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) { _surface = surface; _oldColor = oldColor; diff --git a/graphics/surface.h b/graphics/surface.h index 152bc0ff1cf..810296bcc7f 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -424,6 +424,21 @@ public: */ 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; }; /**