⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 overlay.h

📁 linux下实现视频播放的播放器
💻 H
字号:
/* *  Copyright (C) 2005-2007  gulikoza * *  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. *//* $Id$ */#ifndef OVERLAY_H#define OVERLAY_H#define MODULE "Overlay"class Overlay : public Output {private:    SDL_Overlay * overlay;    bool iyuv;protected:public:    Overlay():overlay(NULL),iyuv(false) { ERROR_MSG("Created Overlay object"); }    ~Overlay() { Free(); ERROR_MSG("Destroyed Overlay object"); }    int Create(int w, int h, Uint32 f, SDL_Surface * s) {	width = w; height = h;	format = f; surface = s;	// Windows seems to prefer YV12, so we'll convert from IYUV here	if(f == SDL_IYUV_OVERLAY) {	    f = SDL_YV12_OVERLAY;	    iyuv = true;	} else {	    iyuv = false;	}	h = h>>half;	if(overlay=SDL_CreateYUVOverlay(w, h, f, s)) {	    ERROR_MSG("Created %s overlay, size %dx%d", overlay->hw_overlay ? "hardware" : "software", w, h);	}	return ((overlay == NULL) ? -1 : 0);    }    void Free(void) {	LOG_MSG("Freeing video surface");	if(overlay) SDL_FreeYUVOverlay(overlay); overlay = NULL;    }    int CopyData(struct Buffer * buffer) {        if(deinterlacer->IsHalf() != half) {            half = !half;            if(surface) {                Free();                Create(width, height, format, surface);            }        }	if((overlay == NULL) || (SDL_LockYUVOverlay(overlay) != 0))	    return -1;	unsigned char * ptr[3];	ptr[2] = (unsigned char*)overlay->pixels[0];	ptr[0] = (unsigned char*)overlay->pixels[1];	ptr[1] = (unsigned char*)overlay->pixels[2];	if(buffer == NULL) {	    for(int i = (height>>1)>>half; i; i--) {		SDL_memset(ptr[2], 0, width); ptr[2] += overlay->pitches[0];		SDL_memset(ptr[2], 0, width); ptr[2] += overlay->pitches[0];		SDL_memset(ptr[1], 0x80, width>>1); ptr[1] += overlay->pitches[2];		SDL_memset(ptr[0], 0x80, width>>1); ptr[0] += overlay->pitches[1];	    }	    SDL_UnlockYUVOverlay(overlay);	    return 0;	}	unsigned char * src[3];	src[2] = buffer->data[0];	src[0] = buffer->data[1+iyuv];	src[1] = buffer->data[2-iyuv];	deint d;	d.src_pitch[2] = buffer->src_width;	d.src_pitch[0] = d.src_pitch[1] = buffer->src_width>>1;	d.dst_pitch[2] = overlay->pitches[0];	d.dst_pitch[0] = overlay->pitches[1];	d.dst_pitch[1] = overlay->pitches[2];	d.width = buffer->dst_width;	d.height = buffer->height;	Render(ptr, src, &d);	SDL_UnlockYUVOverlay(overlay);	return 0;    }    int SwapBuffers(SDL_Rect * clip) {	if(overlay == NULL) return -1;#if (SDL_IS_PATCHED)        SDL_Rect pos;        if(SDL_GetWindowPosition(&pos)) {            pos.h = pos.y + pos.h;            int scan;            while((SDL_GetScanline(&scan) == 1) && (scan < pos.h));        }#endif	return SDL_DisplayYUVOverlay(overlay, clip);    }    SDL_Overlay * GetSurface() { return overlay; }};#undef MODULE#endif // OVERLAY_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -