+
+ SDLSurfacePtr subimage(SDL_CreateRGBSurfaceFrom(static_cast<uint8_t*>(image->pixels) +
+ rect.top * image->pitch +
+ rect.left * image->format->BytesPerPixel,
+ rect.get_width(), rect.get_height(),
+ image->format->BitsPerPixel,
+ image->pitch,
+ image->format->Rmask,
+ image->format->Gmask,
+ image->format->Bmask,
+ image->format->Amask));
+ if (!subimage)
+ {
+ throw std::runtime_error("SDL_CreateRGBSurfaceFrom() call failed");
+ }
+
+#ifdef OLD_SDL
+ if (image->format->palette)
+ { // copy the image palette to subimage if present
+ SDL_SetSurfacePalette(subimage.get(), image->format->palette->colors);
+ }
+#endif
+
+ return VideoSystem::current()->new_texture(subimage.get());