Browse Source

Create a fake Image if SDL_image is not available, so that we can test

stuff anyway.
legacy
Sam Hocevar sam 14 years ago
parent
commit
7fd4603a82
1 changed files with 21 additions and 3 deletions
  1. +21
    -3
      src/image.cpp

+ 21
- 3
src/image.cpp View File

@@ -40,6 +40,8 @@ private:

#if defined USE_SDL
SDL_Surface *img;
#else
uint8_t *dummy;
#endif
};

@@ -67,8 +69,18 @@ Image::Image(char const *path)
data->size = vec2i(data->img->w, data->img->h);
data->format = data->img->format->Amask ? FORMAT_RGBA : FORMAT_RGB;
#else
data->size = 0;
data->format = FORMAT_UNKNOWN;
data->size = 256;
data->format = FORMAT_RGBA;
data->dummy = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*data->dummy));
uint8_t *parser = data->dummy;
for (int j = 0; j < 256; j++)
for (int i = 0; i < 256; i++)
{
*parser++ = ((i ^ j) & 1) * 0xff;
*parser++ = (uint8_t)i;
*parser++ = (uint8_t)j;
*parser++ = (((i >> 4) ^ (j >> 4)) & 1) * 0xff;
}
#endif
}

@@ -84,13 +96,19 @@ Image::format_t Image::GetFormat() const

void * Image::GetData() const
{
#if defined USE_SDL
return data->img->pixels;
#else
return data->dummy;
#endif
}

Image::~Image()
{
#if defined USE_LOL
#if defined USE_SDL
SDL_FreeSurface(data->img);
#else
free(data->dummy);
#endif
delete data;
}


Loading…
Cancel
Save