Quellcode durchsuchen

image: GetData returns uint8_t* instead of void*, it's a lot safer.

legacy
Sam Hocevar sam vor 11 Jahren
Ursprung
Commit
f16704ecb0
11 geänderte Dateien mit 28 neuen und 25 gelöschten Zeilen
  1. +3
    -3
      src/image/codec/android-image.cpp
  2. +4
    -4
      src/image/codec/dummy-image.cpp
  3. +2
    -2
      src/image/codec/gdiplus-image.cpp
  4. +2
    -2
      src/image/codec/ios-image.cpp
  5. +2
    -2
      src/image/codec/ps3-image.cpp
  6. +3
    -3
      src/image/codec/sdl-image.cpp
  7. +1
    -1
      src/image/image-private.h
  8. +6
    -3
      src/image/image.cpp
  9. +1
    -1
      src/lol/image/image.h
  10. +3
    -3
      src/tileset.cpp
  11. +1
    -1
      test/unit/image.cpp

+ 3
- 3
src/image/codec/android-image.cpp Datei anzeigen

@@ -38,7 +38,7 @@ public:
virtual bool Open(char const *);
virtual bool Close();

virtual void *GetData() const;
virtual uint8_t *GetData() const;

private:
jobject bmp;
@@ -130,9 +130,9 @@ bool AndroidImageData::Close()
return true;
}

void * AndroidImageData::GetData() const
uint8_t *AndroidImageData::GetData() const
{
return pixels;
return (uint8_t *)pixels;
}

} /* namespace lol */


+ 4
- 4
src/image/codec/dummy-image.cpp Datei anzeigen

@@ -30,7 +30,7 @@ public:
virtual bool Open(char const *);
virtual bool Close();

virtual void *GetData() const;
virtual uint8_t *GetData() const;

private:
uint8_t *pixels;
@@ -46,7 +46,7 @@ bool DummyImageData::Open(char const *path)

m_size = ivec2(256);
m_format = PixelFormat::RGBA_8;
pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*pixels));
pixels = new uint8_t[256 * 256 * 4 * sizeof(*pixels)];
uint8_t *parser = pixels;
for (int j = 0; j < 256; j++)
for (int i = 0; i < 256; i++)
@@ -62,12 +62,12 @@ bool DummyImageData::Open(char const *path)

bool DummyImageData::Close()
{
free(pixels);
delete[] pixels;

return true;
}

void * DummyImageData::GetData() const
uint8_t * DummyImageData::GetData() const
{
return pixels;
}


+ 2
- 2
src/image/codec/gdiplus-image.cpp Datei anzeigen

@@ -37,7 +37,7 @@ public:
virtual bool Open(char const *);
virtual bool Close();

virtual void *GetData() const;
virtual uint8_t *GetData() const;

private:
Gdiplus::Bitmap *m_bitmap;
@@ -147,7 +147,7 @@ bool GdiPlusImageData::Close()
return true;
}

void * GdiPlusImageData::GetData() const
uint8_t * GdiPlusImageData::GetData() const
{
return m_bdata.Scan0;
}


+ 2
- 2
src/image/codec/ios-image.cpp Datei anzeigen

@@ -34,7 +34,7 @@ public:
virtual bool Open(char const *);
virtual bool Close();

virtual void *GetData() const;
virtual uint8_t *GetData() const;

private:
uint8_t *pixels;
@@ -90,7 +90,7 @@ bool IosImageData::Close()
return true;
}

void * IosImageData::GetData() const
uint8_t * IosImageData::GetData() const
{
return pixels;
}


+ 2
- 2
src/image/codec/ps3-image.cpp Datei anzeigen

@@ -35,7 +35,7 @@ public:
virtual bool Open(char const *);
virtual bool Close();

virtual void *GetData() const;
virtual uint8_t *GetData() const;

private:
static void* Malloc(uint32_t size, void* data) { return malloc(size); };
@@ -179,7 +179,7 @@ bool Ps3ImageData::Close()
return true;
}

void * Ps3ImageData::GetData() const
uint8_t * Ps3ImageData::GetData() const
{
return pixels;
}


+ 3
- 3
src/image/codec/sdl-image.cpp Datei anzeigen

@@ -43,7 +43,7 @@ public:
virtual bool Open(char const *);
virtual bool Close();

virtual void *GetData() const;
virtual uint8_t *GetData() const;

static SDL_Surface *Create32BppSurface(ivec2 size);

@@ -96,9 +96,9 @@ bool SdlImageData::Close()
return true;
}

void * SdlImageData::GetData() const
uint8_t * SdlImageData::GetData() const
{
return m_img->pixels;
return (uint8_t *)m_img->pixels;
}

SDL_Surface *SdlImageData::Create32BppSurface(ivec2 size)


+ 1
- 1
src/image/image-private.h Datei anzeigen

@@ -76,7 +76,7 @@ public:
virtual bool Open(char const *) = 0;
virtual bool Close() = 0;

virtual void *GetData() const = 0;
virtual uint8_t *GetData() const = 0;

protected:
ivec2 m_size;


+ 6
- 3
src/image/image.cpp Datei anzeigen

@@ -22,13 +22,16 @@ namespace lol

static bool RegisterAllLoaders()
{
/* We cannot make this an ImageLoader member function, because the
/* HACK: We cannot make this an ImageLoader member function, because the
* REGISTER_IMAGE_LOADER macro forward-declares free functions from
* the "lol" namespace. An apparent bug in Visual Studio's compiler
* makes it think these functions are actually in the top-level
* namespace when the forward declaration is in a class member function.
* To avoid the problem, we make the forward declaration in a free
* function. */
* function.
* The bug was reported to Microsoft and fixed by them, but the fix
* is not yet available.
* https://connect.microsoft.com/VisualStudio/feedback/details/730878/ */
#if defined __ANDROID__
REGISTER_IMAGE_LOADER(AndroidImageData)
#endif
@@ -71,7 +74,7 @@ PixelFormat Image::GetFormat() const
return m_data->m_format;
}

void * Image::GetData() const
uint8_t * Image::GetData() const
{
return m_data->GetData();
}


+ 1
- 1
src/lol/image/image.h Datei anzeigen

@@ -29,7 +29,7 @@ public:

ivec2 GetSize() const;
PixelFormat GetFormat() const;
void *GetData() const;
uint8_t *GetData() const;

private:
class ImageData *m_data;


+ 3
- 3
src/tileset.cpp Datei anzeigen

@@ -133,10 +133,10 @@ void TileSet::TickDraw(float seconds)
int w = PotUp(data->isize.x);
int h = PotUp(data->isize.y);

uint8_t *pixels = (uint8_t *)data->img->GetData();
uint8_t *pixels = data->img->GetData();
if (w != data->isize.x || h != data->isize.y)
{
uint8_t *tmp = (uint8_t *)malloc(planes * w * h);
uint8_t *tmp = new uint8_t[planes * w * h];
for (int line = 0; line < data->isize.y; line++)
memcpy(tmp + planes * w * line,
pixels + planes * data->isize.x * line,
@@ -148,7 +148,7 @@ void TileSet::TickDraw(float seconds)
data->m_texture->SetData(pixels);

if (pixels != data->img->GetData())
free(pixels);
delete[] pixels;
delete data->img;
data->img = nullptr;
}


+ 1
- 1
test/unit/image.cpp Datei anzeigen

@@ -30,7 +30,7 @@ LOLUNIT_FIXTURE(ImageTest)
LOLUNIT_ASSERT_EQUAL(size.x, 256);
LOLUNIT_ASSERT_EQUAL(size.y, 16);

uint8_t *data = (uint8_t *)image.GetData();
uint8_t *data = image.GetData();
LOLUNIT_ASSERT(data);

LOLUNIT_ASSERT_EQUAL((int)data[0], 0x00);


Laden…
Abbrechen
Speichern