diff --git a/sc2/src/msvc++/UrQuanMasters.dsp b/sc2/src/msvc++/UrQuanMasters.dsp index 2a960720f..e28730192 100644 --- a/sc2/src/msvc++/UrQuanMasters.dsp +++ b/sc2/src/msvc++/UrQuanMasters.dsp @@ -711,18 +711,6 @@ SOURCE=..\sc2code\libs\strings\strintrn.h # Begin Group "video" # PROP Default_Filter "" -# Begin Group "sdl video" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\sc2code\libs\video\sdl\sdlvideo.c -# End Source File -# Begin Source File - -SOURCE=..\sc2code\libs\video\sdl\sdlvideo.h -# End Source File -# End Group # Begin Source File SOURCE=..\sc2code\libs\video\vfileins.c diff --git a/sc2/src/sc2code/libs/graphics/sdl/canvas.c b/sc2/src/sc2code/libs/graphics/sdl/canvas.c index 162c5d34b..956487b85 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/canvas.c +++ b/sc2/src/sc2code/libs/graphics/sdl/canvas.c @@ -147,7 +147,8 @@ TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, int scale, int r, int UnlockMutex (img->mutex); } -TFB_Canvas TFB_DrawCanvas_New_TrueColor (int w, int h, BOOLEAN hasalpha) +TFB_Canvas +TFB_DrawCanvas_New_TrueColor (int w, int h, BOOLEAN hasalpha) { SDL_Surface *new_surf; new_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, hasalpha ? 0xff000000 : 0); @@ -158,6 +159,37 @@ TFB_Canvas TFB_DrawCanvas_New_TrueColor (int w, int h, BOOLEAN hasalpha) return new_surf; } +TFB_Canvas +TFB_DrawCanvas_New_ForScreen (int w, int h, BOOLEAN withalpha) +{ + SDL_Surface *new_surf; + SDL_PixelFormat* fmt = SDL_Screen->format; + + if (fmt->palette) + { + fprintf(stderr, "TFB_DrawCanvas_New_ForScreen() WARNING:" + "Paletted display format will be slow"); + + new_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, + 32, 0x000000ff, 0x0000ff00, 0x00ff0000, + withalpha ? 0xff000000 : 0); + } + else + { + new_surf = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, + fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, + withalpha ? fmt->Amask : 0); + } + + if (!new_surf) + { + fprintf(stderr, "TFB_DrawCanvas_New_ForScreen() INTERNAL PANIC:" + "Failed to create TFB_Canvas: %s", SDL_GetError()); + exit (-1); + } + return new_surf; +} + TFB_Canvas TFB_DrawCanvas_New_Paletted (int w, int h, TFB_Palette *palette, int transparent_index) { @@ -864,3 +896,36 @@ TFB_DrawCanvas_Rescale_Trilinear (TFB_Canvas src_canvas, TFB_Canvas dest_canvas, src->format->BitsPerPixel, dst->format->BitsPerPixel, mipmap->format->BitsPerPixel); } } + +void +TFB_DrawCanvas_GetScreenFormat (TFB_PixelFormat *fmt) +{ + SDL_PixelFormat *sdl = SDL_Screen->format; + + if (sdl->palette) + { + fprintf(stderr, "TFB_DrawCanvas_GetScreenFormat() WARNING:" + "Paletted display format will be slow"); + + fmt->BitsPerPixel = 32; + fmt->Rmask = 0x000000ff; + fmt->Gmask = 0x0000ff00; + fmt->Bmask = 0x00ff0000; + fmt->Amask = 0xff000000; + } + else + { + fmt->BitsPerPixel = sdl->BitsPerPixel; + fmt->Rmask = sdl->Rmask; + fmt->Gmask = sdl->Gmask; + fmt->Bmask = sdl->Bmask; + fmt->Amask = sdl->Amask; + } +} + +void* +TFB_DrawCanvas_GetLine (TFB_Canvas canvas, int line) +{ + SDL_Surface* surf = (SDL_Surface *)canvas; + return (uint8*)surf->pixels + surf->pitch * line; +} diff --git a/sc2/src/sc2code/libs/graphics/tfb_draw.c b/sc2/src/sc2code/libs/graphics/tfb_draw.c index 9dea57083..777958fbe 100644 --- a/sc2/src/sc2code/libs/graphics/tfb_draw.c +++ b/sc2/src/sc2code/libs/graphics/tfb_draw.c @@ -268,6 +268,22 @@ TFB_DrawImage_New (TFB_Canvas canvas) return img; } +TFB_Image* +TFB_DrawImage_CreateForScreen (int w, int h, BOOLEAN withalpha) +{ + TFB_Image* img = HMalloc (sizeof (TFB_Image)); + img->mutex = CreateMutex ("image lock", SYNC_CLASS_VIDEO); + img->ScaledImg = NULL; + img->MipmapImg = NULL; + img->colormap_index = -1; + img->last_scale_type = -1; + img->Palette = NULL; + + img->NormalImg = TFB_DrawCanvas_New_ForScreen (w, h, withalpha); + + return img; +} + void TFB_DrawImage_Delete (TFB_Image *image) { diff --git a/sc2/src/sc2code/libs/graphics/tfb_draw.h b/sc2/src/sc2code/libs/graphics/tfb_draw.h index 7b1f2c46e..bd2a302dc 100644 --- a/sc2/src/sc2code/libs/graphics/tfb_draw.h +++ b/sc2/src/sc2code/libs/graphics/tfb_draw.h @@ -57,6 +57,15 @@ typedef struct tfb_image BOOLEAN dirty; } TFB_Image; +// we do not support paletted format for now +typedef struct tfb_pixelformat +{ + int BitsPerPixel; + int BytesPerPixel; + DWORD Rmask, Gmask, Bmask, Amask; + DWORD Rshift, Gshift, Bshift, Ashift; + DWORD Rloss, Gloss, Bloss, Aloss; +} TFB_PixelFormat; // Drawing commands @@ -72,6 +81,7 @@ void TFB_DrawScreen_SetPalette (int paletteIndex, int r, int g, int b); void TFB_FlushPaletteCache (void); TFB_Image *TFB_DrawImage_New (TFB_Canvas canvas); +TFB_Image *TFB_DrawImage_CreateForScreen (int w, int h, BOOLEAN withalpha); void TFB_DrawImage_Delete (TFB_Image *image); void TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type); @@ -81,6 +91,7 @@ void TFB_DrawImage_Image (TFB_Image *img, int x, int y, int scale, TFB_Palette * void TFB_DrawImage_FilledImage (TFB_Image *img, int x, int y, int scale, int r, int g, int b, TFB_Image *target); TFB_Canvas TFB_DrawCanvas_New_TrueColor (int w, int h, BOOLEAN hasalpha); +TFB_Canvas TFB_DrawCanvas_New_ForScreen (int w, int h, BOOLEAN withalpha); TFB_Canvas TFB_DrawCanvas_New_Paletted (int w, int h, TFB_Palette *palette, int transparent_index); TFB_Canvas TFB_DrawCanvas_New_ScaleTarget (TFB_Canvas canvas, TFB_Canvas oldcanvas, int type, int last_type); TFB_Canvas TFB_DrawCanvas_ToScreenFormat (TFB_Canvas canvas); @@ -102,5 +113,7 @@ int TFB_DrawCanvas_GetTransparentIndex (TFB_Canvas canvas); void TFB_DrawCanvas_SetTransparentIndex (TFB_Canvas canvas, int i, BOOLEAN rleaccel); void TFB_DrawCanvas_SetTransparentColor (TFB_Canvas canvas, int r, int g, int b, BOOLEAN rleaccel); void TFB_DrawCanvas_Initialize (void); +void TFB_DrawCanvas_GetScreenFormat (TFB_PixelFormat *fmt); +void* TFB_DrawCanvas_GetLine (TFB_Canvas canvas, int line); #endif diff --git a/sc2/src/sc2code/libs/video/Makeinfo b/sc2/src/sc2code/libs/video/Makeinfo index 339bbd53a..76c206752 100644 --- a/sc2/src/sc2code/libs/video/Makeinfo +++ b/sc2/src/sc2code/libs/video/Makeinfo @@ -1,2 +1 @@ uqm_CFILES="vfileins.c video.c videodec.c vidplayer.c dukvid.c" -uqm_SUBDIRS="sdl" diff --git a/sc2/src/sc2code/libs/video/dukvid.c b/sc2/src/sc2code/libs/video/dukvid.c index 147a64c41..3b0955e83 100644 --- a/sc2/src/sc2code/libs/video/dukvid.c +++ b/sc2/src/sc2code/libs/video/dukvid.c @@ -14,7 +14,7 @@ #define _THIS TFB_VideoDecoder* This int dukv_GetError (_THIS); -bool dukv_Init (_THIS, TFB_VideoFormat* fmt); +bool dukv_Init (_THIS, TFB_PixelFormat* fmt); void dukv_Term (_THIS); bool dukv_Open (_THIS, uio_DirHandle *dir, const char *filename); void dukv_Close (_THIS); @@ -412,7 +412,7 @@ dukv_InitDeltas (TFB_DuckVideo* dukv, uint8* vectors, sint32* pl, sint32* pc) } __inline__ uint32 -dukv_PixelConv (uint16 pix, const TFB_VideoFormat* fmt) +dukv_PixelConv (uint16 pix, const TFB_PixelFormat* fmt) { uint32 r, g, b; @@ -430,7 +430,7 @@ void dukv_RenderFrame (_THIS) { TFB_DuckVideo* dukv = This->dec_data; - const TFB_VideoFormat* fmt = This->format; + const TFB_PixelFormat* fmt = This->format; uint32 h, x, y; uint32* dec = dukv->decbuf; @@ -508,7 +508,7 @@ int dukv_GetError (_THIS) } bool -dukv_Init (_THIS, TFB_VideoFormat* fmt) +dukv_Init (_THIS, TFB_PixelFormat* fmt) { This->format = fmt; This->audio_synced = 1; diff --git a/sc2/src/sc2code/libs/video/sdl/Makeinfo b/sc2/src/sc2code/libs/video/sdl/Makeinfo deleted file mode 100644 index f400650ea..000000000 --- a/sc2/src/sc2code/libs/video/sdl/Makeinfo +++ /dev/null @@ -1 +0,0 @@ -uqm_CFILES="sdlvideo.c" diff --git a/sc2/src/sc2code/libs/video/sdl/sdlvideo.c b/sc2/src/sc2code/libs/video/sdl/sdlvideo.c deleted file mode 100644 index 07f8bf45e..000000000 --- a/sc2/src/sc2code/libs/video/sdl/sdlvideo.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "libs/graphics/sdl/sdl_common.h" -#include "libs/video/video.h" -#include "sdlvideo.h" - - -void -TFB_GetScreenFormat (TFB_VideoFormat *fmt) -{ - SDL_PixelFormat *sdl = SDL_Video->format; - fmt->BitsPerPixel = sdl->BitsPerPixel; - fmt->Rmask = sdl->Rmask; - fmt->Gmask = sdl->Gmask; - fmt->Bmask = sdl->Bmask; - fmt->Amask = 0; // no alpha support for now -} - -TFB_Image* -TFB_CreateVideoImage (int w, int h) -{ - TFB_Image* img; - SDL_PixelFormat* fmt = SDL_Video->format; - - img = HMalloc (sizeof (TFB_Image)); - img->mutex = CreateMutex ("vid image lock", SYNC_CLASS_VIDEO); - img->ScaledImg = NULL; - img->MipmapImg = NULL; - img->colormap_index = -1; - img->last_scale_type = -1; - img->Palette = NULL; - - img->NormalImg = SDL_CreateRGBSurface (SDL_SWSURFACE, w, h, - fmt->BitsPerPixel, fmt->Rmask, fmt->Gmask, fmt->Bmask, 0); - - return img; -} - -void* -TFB_GetVideoLine (TFB_Image* img, uint32 line) -{ - SDL_Surface* surf = img->NormalImg; - return (uint8*)surf->pixels + surf->pitch * line; -} diff --git a/sc2/src/sc2code/libs/video/sdl/sdlvideo.h b/sc2/src/sc2code/libs/video/sdl/sdlvideo.h deleted file mode 100644 index 5ac298b41..000000000 --- a/sc2/src/sc2code/libs/video/sdl/sdlvideo.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef _SDLVIDEO_H -#define _SDLVIDEO_H - -#include "libs/graphics/gfx_common.h" -#include "libs/graphics/tfb_draw.h" -#include "libs/gfxlib.h" - -void TFB_GetScreenFormat (TFB_VideoFormat *fmt); -TFB_Image* TFB_CreateVideoImage (int w, int h); -void* TFB_GetVideoLine (TFB_Image* img, uint32 line); - -#endif // _SDLVIDEO_H diff --git a/sc2/src/sc2code/libs/video/video.c b/sc2/src/sc2code/libs/video/video.c index 9f3d68fa2..afc4528e1 100644 --- a/sc2/src/sc2code/libs/video/video.c +++ b/sc2/src/sc2code/libs/video/video.c @@ -17,7 +17,6 @@ */ #include "video.h" -#include "sdl/sdlvideo.h" #include "vidplayer.h" #define NULL_VIDEO_REF (0) @@ -27,11 +26,11 @@ BOOLEAN InitVideo (BOOLEAN useCDROM) //useCDROM doesn't really apply to us { - TFB_VideoFormat fmt; + TFB_PixelFormat fmt; - TFB_GetScreenFormat (&fmt); + TFB_DrawCanvas_GetScreenFormat (&fmt); if (!VideoDecoder_Init (0, fmt.BitsPerPixel, fmt.Rmask, - fmt.Gmask, fmt.Bmask, fmt.Amask)) + fmt.Gmask, fmt.Bmask, 0)) return FALSE; return TFB_InitVideoPlayer (); diff --git a/sc2/src/sc2code/libs/video/videodec.c b/sc2/src/sc2code/libs/video/videodec.c index be9da6d36..52d620d40 100644 --- a/sc2/src/sc2code/libs/video/videodec.c +++ b/sc2/src/sc2code/libs/video/videodec.c @@ -19,7 +19,7 @@ #include "dukvid.h" static bool vd_inited = 0; -static TFB_VideoFormat vd_vidfmt; +static TFB_PixelFormat vd_vidfmt; static struct vd_DecoderInfo { @@ -33,7 +33,7 @@ vd_decoders[] = {NULL, NULL, NULL} // null term }; -static void vd_computeMasks (uint32 mask, uint32* shift, uint32* loss); +static void vd_computeMasks (uint32 mask, DWORD* shift, DWORD* loss); bool VideoDecoder_Init (int flags, int depth, uint32 Rmask, uint32 Gmask, @@ -208,7 +208,7 @@ VideoDecoder_Free (TFB_VideoDecoder *decoder) // BEGIN: adapted from SDL static void -vd_computeMasks (uint32 mask, uint32* shift, uint32* loss) +vd_computeMasks (uint32 mask, DWORD* shift, DWORD* loss) { *shift = 0; *loss = 8; diff --git a/sc2/src/sc2code/libs/video/videodec.h b/sc2/src/sc2code/libs/video/videodec.h index 532e6e739..0f9c9dcb4 100644 --- a/sc2/src/sc2code/libs/video/videodec.h +++ b/sc2/src/sc2code/libs/video/videodec.h @@ -24,23 +24,12 @@ // forward-declare typedef struct tfb_videodecoder TFB_VideoDecoder; -// we do not support paletted format for now -typedef struct tfb_videoformat -{ - uint32 BitsPerPixel; - uint32 BytesPerPixel; - uint32 Rmask, Gmask, Bmask, Amask; - uint32 Rshift, Gshift, Bshift, Ashift; - uint32 Rloss, Gloss, Bloss, Aloss; - -} TFB_VideoFormat; - #define _THIS TFB_VideoDecoder* typedef struct tfb_videodecoderfunc { int (* GetError) (_THIS); - bool (* Init) (_THIS, TFB_VideoFormat* fmt); + bool (* Init) (_THIS, TFB_PixelFormat* fmt); void (* Term) (_THIS); bool (* Open) (_THIS, uio_DirHandle *dir, const char *filename); void (* Close) (_THIS); @@ -74,7 +63,7 @@ struct tfb_videodecoder // decoder virtual funcs - R/O const TFB_VideoDecoderFuncs *funcs; // video formats - R/O - const TFB_VideoFormat *format; + const TFB_PixelFormat *format; // decoder-set data - R/O uint32 w, h; float length; // total length in seconds diff --git a/sc2/src/sc2code/libs/video/vidplayer.c b/sc2/src/sc2code/libs/video/vidplayer.c index 07b3cf4d7..659b77738 100644 --- a/sc2/src/sc2code/libs/video/vidplayer.c +++ b/sc2/src/sc2code/libs/video/vidplayer.c @@ -14,8 +14,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "libs/graphics/gfx_common.h" +#include "libs/graphics/tfb_draw.h" #include "vidplayer.h" -#include "sdl/sdlvideo.h" // video callbacks static void* vp_GetCanvasLine (TFB_VideoDecoder*, uint32 line); @@ -46,7 +47,7 @@ static TFB_SoundCallbacks vp_AudioCBs = // inter-thread param guarded by mutex static Semaphore vp_interthread_lock = 0; -void* vp_interthread_clip = NULL; +static void* vp_interthread_clip = NULL; typedef struct { @@ -304,7 +305,7 @@ TFB_PlayVideo (VIDEO_REF VidRef, uint32 x, uint32 y) vid->decoder->callbacks = vp_DecoderCBs; vid->decoder->data = vid; - vid->frame = TFB_CreateVideoImage (vid->w, vid->h); + vid->frame = TFB_DrawImage_CreateForScreen (vid->w, vid->h, FALSE); vid->cur_frame = -1; vid->want_frame = -1; @@ -455,7 +456,7 @@ vp_GetCanvasLine (TFB_VideoDecoder* decoder, uint32 line) if (!vid) return NULL; - return TFB_GetVideoLine (vid->frame, line); + return TFB_DrawCanvas_GetLine (vid->frame->NormalImg, line); } static uint32