Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <algorithm>
- #include <math.h>
- #include <CMisc.h>
- #include "Mipmapable.h"
- class ByteMap : public Mipmapable<ByteMap>
- {
- public:
- ByteMap::ByteMap(int width, int height) {
- if (width < 1 || height < 1)
- THROW("Error: Bad dimensions (" << width << "x" << height << ") on ByteMap; must be at least 1x1.");
- w = width;
- h = height;
- data = (BYTE*) malloc(sizeof(BYTE) * w * h);
- }
- ByteMap::~ByteMap(void) {
- free(data);
- }
- void setByte(int x, int y, BYTE b) {
- data[x + y * h] = b;
- }
- BYTE getByte(int x, int y) {
- return data[x + y * h];
- }
- int getWidth() {
- return w;
- }
- int getHeight() {
- return h;
- }
- /*bool canShrink() {
- return (w / 2 * 2 == w) && (h / 2 * 2 == h);
- }*/
- ByteMap* makeMipMap(void) {
- int width = w / 2;
- int height = h / 2;
- ByteMap* mipMap = new ByteMap(width, height);
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- BYTE interpolatedColorCorrected
- = (BYTE)((int)getByte(2 * x, 2 * y)
- + (int)getByte(2 * x + 1, 2 * y)
- + (int)getByte(2 * x, 2 * y + 1)
- + (int)getByte(2 * x + 1, 2 * y + 1) / 4);
- mipMap->setByte(x, y, interpolatedColorCorrected);
- }
- }
- return mipMap;
- }
- private:
- int w;
- int h;
- BYTE* data;
- };
Advertisement
Add Comment
Please, Sign In to add comment