~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/graphic/render/sdl_surface.cc

  • Committer: Holger Rapp
  • Date: 2014-07-14 05:36:24 UTC
  • mfrom: (7076.1.2 bug-1330599)
  • Revision ID: sirver@gmx.de-20140714053624-84wdn9zecgig4tqh
Remove SDL integer types and forbid its use.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        assert(m_surface);
73
73
 
74
74
        // Locking not needed: reading only
75
 
        const Uint8 bytes_per_pixel = m_surface->format->BytesPerPixel;
76
 
        Uint8 * const pix =
77
 
                static_cast<Uint8 *>(m_surface->pixels) +
 
75
        const uint8_t bytes_per_pixel = m_surface->format->BytesPerPixel;
 
76
        uint8_t * const pix =
 
77
                static_cast<uint8_t *>(m_surface->pixels) +
78
78
                y * m_surface->pitch + x * bytes_per_pixel;
79
79
 
80
80
        switch (bytes_per_pixel) {
81
81
        case 1:
82
82
                return *pix; //  Maybe needed for save_png.
83
83
        case 2:
84
 
                return *reinterpret_cast<const Uint16 *>(pix);
 
84
                return *reinterpret_cast<const uint16_t *>(pix);
85
85
        case 3: //Needed for save_png.
86
86
                //  We can not dereference a pointer to a size 4 object in this case
87
87
                //  since that would casue a read beyond the end of the block pointed to
98
98
                //  shifting the values. It is alignment safe.
99
99
                return pix[0] << 0x00 | pix[1] << 0x08 | pix[2] << 0x10;
100
100
        case 4:
101
 
                return *reinterpret_cast<const Uint32 *>(pix);
 
101
                return *reinterpret_cast<const uint32_t *>(pix);
102
102
        default:
103
103
                assert(false);
104
104
        }
106
106
        return 0; // Should never be here
107
107
}
108
108
 
109
 
void SDLSurface::set_pixel(uint16_t x, uint16_t y, const Uint32 clr) {
 
109
void SDLSurface::set_pixel(uint16_t x, uint16_t y, const uint32_t clr) {
110
110
        x += m_offsx;
111
111
        y += m_offsy;
112
112
 
117
117
        if (SDL_MUSTLOCK(m_surface))
118
118
                SDL_LockSurface(m_surface);
119
119
 
120
 
        const Uint8 bytes_per_pixel = m_surface->format->BytesPerPixel;
121
 
        Uint8 * const pix =
122
 
                static_cast<Uint8 *>(m_surface->pixels) +
 
120
        const uint8_t bytes_per_pixel = m_surface->format->BytesPerPixel;
 
121
        uint8_t * const pix =
 
122
                static_cast<uint8_t *>(m_surface->pixels) +
123
123
                y * m_surface->pitch + x * bytes_per_pixel;
124
124
        switch (bytes_per_pixel) {
125
 
        case 2: *reinterpret_cast<Uint16 *>(pix) = static_cast<Uint16>(clr); break;
126
 
        case 4: *reinterpret_cast<Uint32 *>(pix) = clr;                      break;
 
125
        case 2: *reinterpret_cast<uint16_t *>(pix) = static_cast<uint16_t>(clr); break;
 
126
        case 4: *reinterpret_cast<uint32_t *>(pix) = clr;                      break;
127
127
        default: break;
128
128
        };
129
129
 
183
183
        const uint32_t color = clr.map(format());
184
184
 
185
185
        SDL_Rect r = {
186
 
                static_cast<Sint16>(rc.x), static_cast<Sint16>(rc.y),
187
 
                static_cast<Uint16>(rc.w), static_cast<Uint16>(rc.h)
 
186
                static_cast<int16_t>(rc.x), static_cast<int16_t>(rc.y),
 
187
                static_cast<uint16_t>(rc.w), static_cast<uint16_t>(rc.h)
188
188
                };
189
189
        SDL_FillRect(m_surface, &r, color);
190
190
}
219
219
                        for (int32_t x = rc.x; x < bl.x; ++x)
220
220
                {
221
221
 
222
 
                        Uint8 * const pix =
223
 
                                static_cast<Uint8 *>(m_surface->pixels) +
 
222
                        uint8_t * const pix =
 
223
                                static_cast<uint8_t *>(m_surface->pixels) +
224
224
                                (y + m_offsy) * m_surface->pitch + (x + m_offsx) * 4;
225
225
 
226
 
                        uint32_t const clr = *reinterpret_cast<const Uint32 *>(pix);
 
226
                        uint32_t const clr = *reinterpret_cast<const uint32_t *>(pix);
227
227
                        uint8_t gr, gg, gb;
228
228
                        SDL_GetRGB(clr, m_surface->format, &gr, &gg, &gb);
229
229
                        int16_t r = gr + factor;
237
237
                        if (r & 0xFF00)
238
238
                                r = ~r >> 24;
239
239
 
240
 
                        *reinterpret_cast<Uint32 *>(pix) =
 
240
                        *reinterpret_cast<uint32_t *>(pix) =
241
241
                                SDL_MapRGB(m_surface->format, r, g, b);
242
242
                }
243
243
        } else if (m_surface->format->BytesPerPixel == 2) {
244
244
                for (int32_t y = rc.y; y < bl.y; ++y)
245
245
                        for (int32_t x = rc.x; x < bl.x; ++x)
246
246
                {
247
 
                        Uint8 * const pix =
248
 
                                static_cast<Uint8 *>(m_surface->pixels) +
 
247
                        uint8_t * const pix =
 
248
                                static_cast<uint8_t *>(m_surface->pixels) +
249
249
                                (y + m_offsy) * m_surface->pitch + (x + m_offsx) * 2;
250
250
 
251
 
                        uint32_t const clr = *reinterpret_cast<const Uint16 *>(pix);
 
251
                        uint32_t const clr = *reinterpret_cast<const uint16_t *>(pix);
252
252
                        uint8_t gr, gg, gb;
253
253
                        SDL_GetRGB(clr, m_surface->format, &gr, &gg, &gb);
254
254
                        int16_t r = gr + factor;
262
262
                        if (r & 0xFF00)
263
263
                                r = ~r >> 24;
264
264
 
265
 
                        *reinterpret_cast<Uint16 *>(pix) =
 
265
                        *reinterpret_cast<uint16_t *>(pix) =
266
266
                                SDL_MapRGB(m_surface->format, r, g, b);
267
267
                }
268
268
        }
327
327
{
328
328
        SDL_Surface* sdlsurf = static_cast<const SDLSurface*>(src)->get_sdl_surface();
329
329
        SDL_Rect srcrect = {
330
 
                static_cast<Sint16>(srcrc.x), static_cast<Sint16>(srcrc.y),
331
 
                static_cast<Uint16>(srcrc.w), static_cast<Uint16>(srcrc.h)
 
330
                static_cast<int16_t>(srcrc.x), static_cast<int16_t>(srcrc.y),
 
331
                static_cast<uint16_t>(srcrc.w), static_cast<uint16_t>(srcrc.h)
332
332
                };
333
333
        SDL_Rect dstrect = {
334
 
                static_cast<Sint16>(dst.x), static_cast<Sint16>(dst.y),
 
334
                static_cast<int16_t>(dst.x), static_cast<int16_t>(dst.y),
335
335
                0, 0
336
336
                };
337
337