}
#if defined(TARGET_SDL2)
+
+static boolean equalSDLPixelFormat(SDL_PixelFormat *format1,
+ SDL_PixelFormat *format2)
+{
+ return (format1->format == format2->format &&
+ format1->BitsPerPixel == format2->BitsPerPixel &&
+ format1->BytesPerPixel == format2->BytesPerPixel &&
+ format1->Rmask == format2->Rmask &&
+ format1->Gmask == format2->Gmask &&
+ format1->Bmask == format2->Bmask &&
+ format1->Amask == format2->Amask);
+}
+
+boolean SDLSetNativeSurface(SDL_Surface **surface)
+{
+ SDL_Surface *new_surface;
+
+ if (surface == NULL ||
+ *surface == NULL ||
+ backbuffer == NULL ||
+ backbuffer->surface == NULL)
+ return FALSE;
+
+ // if pixel format already optimized for destination surface, do nothing
+ if (equalSDLPixelFormat((*surface)->format, backbuffer->surface->format))
+ return FALSE;
+
+ new_surface = SDL_ConvertSurface(*surface, backbuffer->surface->format, 0);
+
+ SDL_FreeSurface(*surface);
+
+ *surface = new_surface;
+
+ return TRUE;
+}
+
+SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface)
+{
+ if (surface == NULL ||
+ backbuffer == NULL ||
+ backbuffer->surface == NULL)
+ return NULL;
+
+ return SDL_ConvertSurface(surface, backbuffer->surface->format, 0);
+}
+
SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface)
{
- if (backbuffer == NULL ||
+ if (surface == NULL ||
+ backbuffer == NULL ||
backbuffer->surface == NULL)
return NULL;
+#if 0
+ boolean same_pixel_format =
+ equalSDLPixelFormat(surface->format, backbuffer->surface->format);
+
+ printf("::: SDL_DisplayFormat: %08x -> %08x [%08x, %08x, %08x -> %08x, %08x, %08x] [%d, %d -> %d, %d] => %s\n",
+ surface->format->format,
+ backbuffer->surface->format->format,
+ surface->format->Rmask,
+ surface->format->Gmask,
+ surface->format->Bmask,
+ backbuffer->surface->format->Rmask,
+ backbuffer->surface->format->Gmask,
+ backbuffer->surface->format->Bmask,
+ surface->format->BitsPerPixel,
+ surface->format->BytesPerPixel,
+ backbuffer->surface->format->BitsPerPixel,
+ backbuffer->surface->format->BytesPerPixel,
+ (same_pixel_format ? "SAME" : "DIFF"));
+#endif
+
return SDL_ConvertSurface(surface, backbuffer->surface->format, 0);
}
+
+#else
+
+boolean SDLSetNativeSurface(SDL_Surface **surface)
+{
+ SDL_Surface *new_surface;
+
+ if (surface == NULL)
+ return FALSE;
+
+ new_surface = SDL_DisplayFormat(*surface);
+
+ if (new_surface == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
+
+ SDL_FreeSurface(*surface);
+
+ *surface = new_surface;
+
+ return TRUE;
+}
+
+SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface)
+{
+ SDL_Surface *new_surface = SDL_DisplayFormat(surface);
+
+ if (new_surface == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
+
+ return new_surface;
+}
+
#endif
void SDLInitVideoDisplay(void)
if (sdl_texture != NULL)
{
+#if 1
+ // use SDL default values for RGB masks and no alpha channel
+ new_surface = SDL_CreateRGBSurface(0, width, height, 32, 0,0,0, 0);
+#else
+
#if 1
// (do not use alpha channel)
new_surface = SDL_CreateRGBSurface(0, width, height, 32,
0x0000FF00,
0x000000FF,
0xFF000000);
+#endif
+
#endif
if (new_surface == NULL)
}
#endif
-void SDLCreateBitmapContent(Bitmap *new_bitmap, int width, int height,
+void SDLCreateBitmapContent(Bitmap *bitmap, int width, int height,
int depth)
{
+#if 1
+ SDL_Surface *surface =
+ SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, 0,0,0, 0);
+
+ if (surface == NULL)
+ Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
+
+ SDLSetNativeSurface(&surface);
+
+ bitmap->surface = surface;
+
+#else
+
SDL_Surface *surface_tmp, *surface_native;
if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth,
SDL_FreeSurface(surface_tmp);
new_bitmap->surface = surface_native;
+#endif
}
void SDLFreeBitmapPointers(Bitmap *bitmap)
return 0;
}
+#if 1
+
+int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst)
+{
+ int x, y, *sax, *say, *csax, *csay;
+ float sx, sy;
+ tColorRGBA *sp, *csp, *csp0, *dp;
+ int dgap;
+
+ /* use specialized zoom function when scaling down to exactly half size */
+ if (src->w == 2 * dst->w &&
+ src->h == 2 * dst->h)
+ return zoomSurfaceRGBA_scaleDownBy2(src, dst);
+
+#if 0
+ printf("::: zoomSurfaceRGBA: %d, %d -> %d, %d\n",
+ src->w, src->h, dst->w, dst->h);
+#endif
+
+ /* variable setup */
+ sx = (float) src->w / (float) dst->w;
+ sy = (float) src->h / (float) dst->h;
+
+ /* allocate memory for row increments */
+ csax = sax = (int *)checked_malloc((dst->w + 1) * sizeof(Uint32));
+ csay = say = (int *)checked_malloc((dst->h + 1) * sizeof(Uint32));
+
+ /* precalculate row increments */
+ for (x = 0; x <= dst->w; x++)
+ *csax++ = (int)(sx * x);
+
+ for (y = 0; y <= dst->h; y++)
+ *csay++ = (int)(sy * y);
+
+ /* pointer setup */
+ sp = csp = csp0 = (tColorRGBA *) src->pixels;
+ dp = (tColorRGBA *) dst->pixels;
+ dgap = dst->pitch - dst->w * 4;
+
+ csay = say;
+ for (y = 0; y < dst->h; y++)
+ {
+ sp = csp;
+ csax = sax;
+
+ for (x = 0; x < dst->w; x++)
+ {
+ /* draw */
+ *dp = *sp;
+
+ /* advance source pointers */
+ csax++;
+ sp = csp + *csax;
+
+ /* advance destination pointer */
+ dp++;
+ }
+
+ /* advance source pointer */
+ csay++;
+ csp = (tColorRGBA *) ((Uint8 *) csp0 + *csay * src->pitch);
+
+ /* advance destination pointers */
+ dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
+ }
+
+ free(sax);
+ free(say);
+
+ return 0;
+}
+
+#else
+
int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst)
{
int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy;
return 0;
}
+#endif
+
/*
-----------------------------------------------------------------------------
8 bit zoomer
else
{
/* new source surface is 32 bit with a defined RGB ordering */
- zoom_src = SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32,
+ zoom_src = SDL_CreateRGBSurface(SURFACE_FLAGS, src->w, src->h, 32,
0x000000ff, 0x0000ff00, 0x00ff0000, 0);
SDL_BlitSurface(src, NULL, zoom_src, NULL);
is_32bit = TRUE;
if (is_32bit)
{
/* target surface is 32 bit with source RGBA/ABGR ordering */
- zoom_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dst_width, dst_height, 32,
+ zoom_dst = SDL_CreateRGBSurface(SURFACE_FLAGS, dst_width, dst_height, 32,
zoom_src->format->Rmask,
zoom_src->format->Gmask,
zoom_src->format->Bmask, 0);
else
{
/* target surface is 8 bit */
- zoom_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dst_width, dst_height, 8,
+ zoom_dst = SDL_CreateRGBSurface(SURFACE_FLAGS, dst_width, dst_height, 8,
0, 0, 0, 0);
}
return zoom_dst;
}
+#if 1
+
+Bitmap *SDLZoomBitmap(Bitmap *src_bitmap, int dst_width, int dst_height)
+{
+#if 1
+
+ Bitmap *dst_bitmap = CreateBitmapStruct();
+ SDL_Surface **dst_surface = &dst_bitmap->surface;
+
+ dst_width = MAX(1, dst_width); /* prevent zero bitmap width */
+ dst_height = MAX(1, dst_height); /* prevent zero bitmap height */
+
+ dst_bitmap->width = dst_width;
+ dst_bitmap->height = dst_height;
+
+ /* create zoomed temporary surface from source surface */
+ *dst_surface = zoomSurface(src_bitmap->surface, dst_width, dst_height);
+
+ /* create native format destination surface from zoomed temporary surface */
+ SDLSetNativeSurface(dst_surface);
+
+ return dst_bitmap;
+
+#else
+
+ Bitmap *dst_bitmap = CreateBitmapStruct();
+ SDL_Surface *sdl_surface_tmp;
+
+ dst_width = MAX(1, dst_width); /* prevent zero bitmap width */
+ dst_height = MAX(1, dst_height); /* prevent zero bitmap height */
+
+ dst_bitmap->width = dst_width;
+ dst_bitmap->height = dst_height;
+
+ print_timestamp_init("SDLZoomBitmap");
+
+ /* create zoomed temporary surface from source surface */
+ sdl_surface_tmp = zoomSurface(src_bitmap->surface, dst_width, dst_height);
+ print_timestamp_time("zoomSurface");
+
+ /* create native format destination surface from zoomed temporary surface */
+ dst_bitmap->surface = SDL_DisplayFormat(sdl_surface_tmp);
+ print_timestamp_time("SDL_DisplayFormat");
+
+ /* free temporary surface */
+ SDL_FreeSurface(sdl_surface_tmp);
+ print_timestamp_time("SDL_FreeSurface");
+
+ print_timestamp_done("SDLZoomBitmap");
+
+ return dst_bitmap;
+
+#endif
+}
+
+#else
+
void SDLZoomBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap)
{
SDL_Surface *sdl_surface_tmp;
int dst_width = dst_bitmap->width;
int dst_height = dst_bitmap->height;
+ print_timestamp_init("SDLZoomBitmap");
+
/* throw away old destination surface */
SDL_FreeSurface(dst_bitmap->surface);
+ print_timestamp_time("SDL_FreeSurface");
/* create zoomed temporary surface from source surface */
sdl_surface_tmp = zoomSurface(src_bitmap->surface, dst_width, dst_height);
+ print_timestamp_time("zoomSurface");
/* create native format destination surface from zoomed temporary surface */
dst_bitmap->surface = SDL_DisplayFormat(sdl_surface_tmp);
+ print_timestamp_time("SDL_DisplayFormat");
/* free temporary surface */
SDL_FreeSurface(sdl_surface_tmp);
+ print_timestamp_time("SDL_FreeSurface");
+
+ print_timestamp_done("SDLZoomBitmap");
}
+#endif
+
/* ========================================================================= */
/* load image to bitmap */
UPDATE_BUSY_STATE();
/* create native non-transparent surface for current image */
+#if 1
+ if ((new_bitmap->surface = SDLGetNativeSurface(sdl_image_tmp)) == NULL)
+ {
+ SetError("SDL_DisplayFormat(): %s", SDL_GetError());
+
+ return NULL;
+ }
+#else
if ((new_bitmap->surface = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
{
SetError("SDL_DisplayFormat(): %s", SDL_GetError());
return NULL;
}
+#endif
print_timestamp_time("SDL_DisplayFormat (opaque)");
/* create native transparent surface for current image */
SDL_SetColorKey(sdl_image_tmp, SET_TRANSPARENT_PIXEL,
SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
+#if 1
+ if ((new_bitmap->surface_masked = SDLGetNativeSurface(sdl_image_tmp)) == NULL)
+ {
+ SetError("SDL_DisplayFormat(): %s", SDL_GetError());
+
+ return NULL;
+ }
+#else
if ((new_bitmap->surface_masked = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
{
SetError("SDL_DisplayFormat(): %s", SDL_GetError());
return NULL;
}
+#endif
print_timestamp_time("SDL_DisplayFormat (masked)");
Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height)
{
+#if 0
+ // !!! TEST ONLY !!!
+
Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH);
+ print_timestamp_time("CreateBitmap");
+
+ SDL_Rect src_rect, dst_rect;
+
+ src_rect.x = 0;
+ src_rect.y = 0;
+ src_rect.w = src_bitmap->width - 0;
+ src_rect.h = src_bitmap->height;
+
+ dst_rect.x = 0;
+ dst_rect.y = 0;
+ dst_rect.w = dst_bitmap->width;
+ dst_rect.h = dst_bitmap->height;
- SDLZoomBitmap(src_bitmap, dst_bitmap);
+ SDL_BlitScaled(src_bitmap->surface, &src_rect,
+ dst_bitmap->surface, &dst_rect);
+ print_timestamp_time("SDL_BlitScaled");
+
+#else
+
+ Bitmap *dst_bitmap = SDLZoomBitmap(src_bitmap, zoom_width, zoom_height);
+#endif
return dst_bitmap;
}
int old_width, old_height;
int new_width, new_height;
+ print_timestamp_init("CreateScaledBitmaps");
+
old_width = old_bitmap->width;
old_height = old_bitmap->height;
else if (width_0 == width_final)
tmp_bitmap_0 = tmp_bitmap_final;
else
+ {
+#if 0
+ if (old_width != width_0)
+ printf("::: %d, %d -> %d, %d\n",
+ old_width, old_height, width_0, height_0);
+#endif
+
tmp_bitmap_0 = ZoomBitmap(old_bitmap, width_0, height_0);
+ }
UPDATE_BUSY_STATE();
}
SDL_SetColorKey(old_surface, SET_TRANSPARENT_PIXEL,
SDL_MapRGB(old_surface->format, 0x00, 0x00, 0x00));
+#if 1
+ if ((old_bitmap->surface_masked = SDLGetNativeSurface(old_surface)) == NULL)
+ Error(ERR_EXIT, "SDL_DisplayFormat() failed");
+#else
if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) == NULL)
Error(ERR_EXIT, "SDL_DisplayFormat() failed");
+#endif
SDL_SetColorKey(old_surface, UNSET_TRANSPARENT_PIXEL, 0);
}
UPDATE_BUSY_STATE();
FreeBitmap(new_bitmap); /* this actually frees the _old_ bitmap now */
+
+ print_timestamp_done("CreateScaledBitmaps");
}
void CreateBitmapWithSmallBitmaps(Bitmap *old_bitmap, int zoom_factor,
#if NEW_TILESIZE
width = crumbled_border_size * TILESIZE_VAR / TILESIZE;
height = crumbled_border_size * TILESIZE_VAR / TILESIZE;
- cx = (dx > 0 ? TILEX - crumbled_border_size : 0) * TILESIZE_VAR / TILESIZE;
- cy = (dy > 0 ? TILEY - crumbled_border_size : 0) * TILESIZE_VAR / TILESIZE;
+ cx = (dx > 0 ? TILESIZE_VAR - width : 0);
+ cy = (dy > 0 ? TILESIZE_VAR - height : 0);
BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy,
width, height, FX + sx * TILEX_VAR + cx, FY + sy * TILEY_VAR + cy);
int width, height, bx, by, cx, cy;
int sx = SCREENX(x), sy = SCREENY(y);
int crumbled_border_size = graphic_info[graphic].border_size;
+ int crumbled_border_size_var = crumbled_border_size * TILESIZE_VAR / TILESIZE;
+ int crumbled_border_pos_var = TILESIZE_VAR - crumbled_border_size_var;
int i;
getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
/* draw simple, sloppy, non-corner-accurate crumbled border */
#if 1
- width = (dir == 1 || dir == 2 ? crumbled_border_size : TILEX);
- height = (dir == 0 || dir == 3 ? crumbled_border_size : TILEY);
- cx = (dir == 2 ? TILEX - crumbled_border_size : 0);
- cy = (dir == 3 ? TILEY - crumbled_border_size : 0);
+ width = (dir == 1 || dir == 2 ? crumbled_border_size_var : TILESIZE_VAR);
+ height = (dir == 0 || dir == 3 ? crumbled_border_size_var : TILESIZE_VAR);
+ cx = (dir == 2 ? crumbled_border_pos_var : 0);
+ cy = (dir == 3 ? crumbled_border_pos_var : 0);
#else
if (dir == 1 || dir == 2) /* left or right crumbled border */
{
#if NEW_TILESIZE
BlitBitmap(src_bitmap, drawto_field,
- src_x + cx * TILESIZE_VAR / TILESIZE,
- src_y + cy * TILESIZE_VAR / TILESIZE,
- width * TILESIZE_VAR / TILESIZE,
- height * TILESIZE_VAR / TILESIZE,
- FX + sx * TILEX_VAR + cx * TILESIZE_VAR / TILESIZE,
- FY + sy * TILEY_VAR + cy * TILESIZE_VAR / TILESIZE);
+ src_x + cx,
+ src_y + cy,
+ width,
+ height,
+ FX + sx * TILEX_VAR + cx,
+ FY + sy * TILEY_VAR + cy);
#else
BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy,
width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy);
/* correct corners of crumbled border, if needed */
#if 1
- for (i = -1; i <= 1; i+=2)
+ for (i = -1; i <= 1; i += 2)
{
int xx = x + (dir == 0 || dir == 3 ? i : 0);
int yy = y + (dir == 1 || dir == 2 ? i : 0);
{
/* no crumbled corner, but continued crumbled border */
- int c1 = (dir == 2 || dir == 3 ? TILESIZE - crumbled_border_size : 0);
- int c2 = (i == 1 ? TILESIZE - crumbled_border_size : 0);
- int b1 = (i == 1 ? crumbled_border_size :
- TILESIZE - 2 * crumbled_border_size);
+ int c1 = (dir == 2 || dir == 3 ? crumbled_border_pos_var : 0);
+ int c2 = (i == 1 ? crumbled_border_pos_var : 0);
+ int b1 = (i == 1 ? crumbled_border_size_var :
+ TILESIZE_VAR - 2 * crumbled_border_size_var);
- width = crumbled_border_size;
- height = crumbled_border_size;
+ width = crumbled_border_size_var;
+ height = crumbled_border_size_var;
if (dir == 1 || dir == 2)
{
#if NEW_TILESIZE
BlitBitmap(src_bitmap, drawto_field,
- src_x + bx * TILESIZE_VAR / TILESIZE,
- src_y + by * TILESIZE_VAR / TILESIZE,
- width * TILESIZE_VAR / TILESIZE,
- height * TILESIZE_VAR / TILESIZE,
- FX + sx * TILEX_VAR + cx * TILESIZE_VAR / TILESIZE,
- FY + sy * TILEY_VAR + cy * TILESIZE_VAR / TILESIZE);
+ src_x + bx,
+ src_y + by,
+ width,
+ height,
+ FX + sx * TILEX_VAR + cx,
+ FY + sy * TILEY_VAR + cy);
#else
BlitBitmap(src_bitmap, drawto_field, src_x + bx, src_y + by,
width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy);