diff --git a/aegisub/audio_provider_lavc.cpp b/aegisub/audio_provider_lavc.cpp index 60080647e..d5c468820 100644 --- a/aegisub/audio_provider_lavc.cpp +++ b/aegisub/audio_provider_lavc.cpp @@ -111,7 +111,7 @@ LAVCAudioProvider::LAVCAudioProvider(wxString _filename) } #endif audStream = -1; - for (int i = 0; i < lavcfile->fctx->nb_streams; i++) { + for (unsigned int i = 0; i < lavcfile->fctx->nb_streams; i++) { codecContext = lavcfile->fctx->streams[i]->codec; if (codecContext->codec_type == CODEC_TYPE_AUDIO) { stream = lavcfile->fctx->streams[i]; diff --git a/aegisub/utils.h b/aegisub/utils.h index 799c5bc13..6a7a930a5 100644 --- a/aegisub/utils.h +++ b/aegisub/utils.h @@ -57,15 +57,6 @@ void AppendBitmapMenuItem (wxMenu* parentMenu,int id,wxString text,wxString help int SmallestPowerOf2(int x); -/////////// -// Inlines -inline void IntSwap(int &a,int &b) { - int c = a; - a = b; - b = c; -} - - ////////// // Macros #ifndef MIN @@ -79,3 +70,34 @@ inline void IntSwap(int &a,int &b) { #ifndef MID #define MID(a,b,c) MAX((a),MIN((b),(c))) #endif + +#ifndef FORCEINLINE +#ifdef __VISUALC__ +#define FORCEINLINE __forceinline +#else +#define FORCEINLINE __attribute__((always_inline)) +#endif +#endif + + +/////////// +// Inlines +inline void IntSwap(int &a,int &b) { + int c = a; + a = b; + b = c; +} + + +////////////////////////// +// Clamp integer to range +// Code taken from http://bob.allegronetwork.com/prog/tricks.html#clamp +FORCEINLINE int ClampSignedInteger32(int x,int min,int max) { + x -= min; + x &= (~x) >> 31; + x += min; + x -= max; + x &= x >> 31; + x += max; + return x; +} diff --git a/aegisub/video_frame.cpp b/aegisub/video_frame.cpp index d9cc248e0..2b26a5612 100644 --- a/aegisub/video_frame.cpp +++ b/aegisub/video_frame.cpp @@ -299,9 +299,9 @@ void AegiVideoFrame::ConvertFrom(const AegiVideoFrame &source) { y = (*src_y++ - 16) * 298; // Assign - *dst++ = MID(0,(y + 516 * u + 128) >> 8,255); // Blue - *dst++ = MID(0,(y - 100 * u - 208 * v + 128) >> 8,255); // Green - *dst++ = MID(0,(y + 409 * v + 128) >> 8,255); // Red + *dst++ = ClampSignedInteger32((y + 516 * u + 128) >> 8,0,255); // Blue + *dst++ = ClampSignedInteger32((y - 100 * u - 208 * v + 128) >> 8,0,255); // Green + *dst++ = ClampSignedInteger32((y + 409 * v + 128) >> 8,0,255); // Red *dst++ = 0; } }