Changeset 2551


Ignore:
Timestamp:
Mar 5, 2013, 4:48:11 PM (10 years ago)
Author:
sam
Message:

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

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/image/codec/android-image.cpp

    r2550 r2551  
    3939    virtual bool Close();
    4040
    41     virtual void *GetData() const;
     41    virtual uint8_t *GetData() const;
    4242
    4343private:
     
    131131}
    132132
    133 void * AndroidImageData::GetData() const
     133uint8_t *AndroidImageData::GetData() const
    134134{
    135     return pixels;
     135    return (uint8_t *)pixels;
    136136}
    137137
  • trunk/src/image/codec/dummy-image.cpp

    r2550 r2551  
    3131    virtual bool Close();
    3232
    33     virtual void *GetData() const;
     33    virtual uint8_t *GetData() const;
    3434
    3535private:
     
    4747    m_size = ivec2(256);
    4848    m_format = PixelFormat::RGBA_8;
    49     pixels = (uint8_t *)malloc(256 * 256 * 4 * sizeof(*pixels));
     49    pixels = new uint8_t[256 * 256 * 4 * sizeof(*pixels)];
    5050    uint8_t *parser = pixels;
    5151    for (int j = 0; j < 256; j++)
     
    6363bool DummyImageData::Close()
    6464{
    65     free(pixels);
     65    delete[] pixels;
    6666
    6767    return true;
    6868}
    6969
    70 void * DummyImageData::GetData() const
     70uint8_t * DummyImageData::GetData() const
    7171{
    7272    return pixels;
  • trunk/src/image/codec/gdiplus-image.cpp

    r2550 r2551  
    3838    virtual bool Close();
    3939
    40     virtual void *GetData() const;
     40    virtual uint8_t *GetData() const;
    4141
    4242private:
     
    148148}
    149149
    150 void * GdiPlusImageData::GetData() const
     150uint8_t * GdiPlusImageData::GetData() const
    151151{
    152152    return m_bdata.Scan0;
  • trunk/src/image/codec/ios-image.cpp

    r2550 r2551  
    3535    virtual bool Close();
    3636
    37     virtual void *GetData() const;
     37    virtual uint8_t *GetData() const;
    3838
    3939private:
     
    9191}
    9292
    93 void * IosImageData::GetData() const
     93uint8_t * IosImageData::GetData() const
    9494{
    9595    return pixels;
  • trunk/src/image/codec/ps3-image.cpp

    r2550 r2551  
    3636    virtual bool Close();
    3737
    38     virtual void *GetData() const;
     38    virtual uint8_t *GetData() const;
    3939
    4040private:
     
    180180}
    181181
    182 void * Ps3ImageData::GetData() const
     182uint8_t * Ps3ImageData::GetData() const
    183183{
    184184    return pixels;
  • trunk/src/image/codec/sdl-image.cpp

    r2550 r2551  
    4444    virtual bool Close();
    4545
    46     virtual void *GetData() const;
     46    virtual uint8_t *GetData() const;
    4747
    4848    static SDL_Surface *Create32BppSurface(ivec2 size);
     
    9797}
    9898
    99 void * SdlImageData::GetData() const
     99uint8_t * SdlImageData::GetData() const
    100100{
    101     return m_img->pixels;
     101    return (uint8_t *)m_img->pixels;
    102102}
    103103
  • trunk/src/image/image-private.h

    r2550 r2551  
    7777    virtual bool Close() = 0;
    7878
    79     virtual void *GetData() const = 0;
     79    virtual uint8_t *GetData() const = 0;
    8080
    8181protected:
  • trunk/src/image/image.cpp

    r2550 r2551  
    2323static bool RegisterAllLoaders()
    2424{
    25     /* We cannot make this an ImageLoader member function, because the
     25    /* HACK: We cannot make this an ImageLoader member function, because the
    2626     * REGISTER_IMAGE_LOADER macro forward-declares free functions from
    2727     * the "lol" namespace. An apparent bug in Visual Studio's compiler
     
    2929     * namespace when the forward declaration is in a class member function.
    3030     * To avoid the problem, we make the forward declaration in a free
    31      * function. */
     31     * function.
     32     * The bug was reported to Microsoft and fixed by them, but the fix
     33     * is not yet available.
     34     * https://connect.microsoft.com/VisualStudio/feedback/details/730878/ */
    3235#if defined __ANDROID__
    3336    REGISTER_IMAGE_LOADER(AndroidImageData)
     
    7275}
    7376
    74 void * Image::GetData() const
     77uint8_t * Image::GetData() const
    7578{
    7679    return m_data->GetData();
  • trunk/src/lol/image/image.h

    r2550 r2551  
    3030    ivec2 GetSize() const;
    3131    PixelFormat GetFormat() const;
    32     void *GetData() const;
     32    uint8_t *GetData() const;
    3333
    3434private:
  • trunk/src/tileset.cpp

    r2550 r2551  
    134134        int h = PotUp(data->isize.y);
    135135
    136         uint8_t *pixels = (uint8_t *)data->img->GetData();
     136        uint8_t *pixels = data->img->GetData();
    137137        if (w != data->isize.x || h != data->isize.y)
    138138        {
    139             uint8_t *tmp = (uint8_t *)malloc(planes * w * h);
     139            uint8_t *tmp = new uint8_t[planes * w * h];
    140140            for (int line = 0; line < data->isize.y; line++)
    141141                memcpy(tmp + planes * w * line,
     
    149149
    150150        if (pixels != data->img->GetData())
    151             free(pixels);
     151            delete[] pixels;
    152152        delete data->img;
    153153        data->img = nullptr;
  • trunk/test/unit/image.cpp

    r2183 r2551  
    3131        LOLUNIT_ASSERT_EQUAL(size.y, 16);
    3232
    33         uint8_t *data = (uint8_t *)image.GetData();
     33        uint8_t *data = image.GetData();
    3434        LOLUNIT_ASSERT(data);
    3535
Note: See TracChangeset for help on using the changeset viewer.