static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { image_width = width; image_height = height; vo_fs = flags & VOFLAG_FULLSCREEN; vo_dwidth = d_width; vo_dheight = d_height; vo_screenwidth = screenwidth; vo_screenheight = screenheight; aspect_save_orig(width, height); aspect_save_prescale(d_width, d_height); aspect_save_screenres(vo_screenwidth, vo_screenheight); resize(); int xs, ys; mp_get_chroma_shift(format, &xs, &ys); mpgxConfigYUVp(image_width, image_height, image_width >> xs, image_height >> ys); return VO_FALSE; }
/* connect to server, create and map window, * allocate colors and (shared) memory */ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { int xs, ys; image_height = height; image_width = width; image_format = format; is_yuv = mp_get_chroma_shift(image_format, &xs, &ys) > 0; is_yuv |= (xs << 8) | (ys << 16); glFindFormat(format, NULL, &gl_texfmt, &gl_format, &gl_type); int_pause = 0; vo_flipped = !!(flags & VOFLAG_FLIPPING); if (create_window(d_width, d_height, flags, title) < 0) return -1; if (vo_config_count) uninitGl(); if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED) return -1; if (mesa_buffer && !mpglAllocateMemoryMESA) { mp_msg(MSGT_VO, MSGL_ERR, "Can not enable mesa-buffer because AllocateMemoryMESA was not found\n"); mesa_buffer = 0; } initGl(vo_dwidth, vo_dheight); return 0; }
static void update_yuvconv(void) { int xs, ys, depth; float bri = eq_bri / 100.0; float cont = (eq_cont + 100) / 100.0; float hue = eq_hue / 100.0 * 3.1415927; float sat = (eq_sat + 100) / 100.0; float rgamma = exp(log(8.0) * eq_rgamma / 100.0); float ggamma = exp(log(8.0) * eq_ggamma / 100.0); float bgamma = exp(log(8.0) * eq_bgamma / 100.0); gl_conversion_params_t params = {gl_target, yuvconvtype, {colorspace, levelconv, bri, cont, hue, sat, rgamma, ggamma, bgamma, 0}, texture_width, texture_height, 0, 0, filter_strength, noise_strength}; mp_get_chroma_shift(image_format, &xs, &ys, &depth); params.chrom_texw = params.texw >> xs; params.chrom_texh = params.texh >> ys; params.csp_params.input_shift = -depth & 7; glSetupYUVConversion(¶ms); if (custom_prog) { FILE *f = fopen(custom_prog, "rb"); if (!f) { mp_msg(MSGT_VO, MSGL_WARN, "[gl] Could not read customprog %s\n", custom_prog); } else { char *prog = calloc(1, MAX_CUSTOM_PROG_SIZE + 1); fread(prog, 1, MAX_CUSTOM_PROG_SIZE, f); fclose(f); loadGPUProgram(GL_FRAGMENT_PROGRAM, prog); free(prog); } mpglProgramEnvParameter4f(GL_FRAGMENT_PROGRAM, 0, 1.0 / texture_width, 1.0 / texture_height, texture_width, texture_height); } if (custom_tex) { FILE *f = fopen(custom_tex, "rb"); if (!f) { mp_msg(MSGT_VO, MSGL_WARN, "[gl] Could not read customtex %s\n", custom_tex); } else { int width, height, maxval; mpglActiveTexture(GL_TEXTURE3); if (glCreatePPMTex(custom_trect?GL_TEXTURE_RECTANGLE:GL_TEXTURE_2D, 0, custom_tlin?GL_LINEAR:GL_NEAREST, f, &width, &height, &maxval)) { mpglProgramEnvParameter4f(GL_FRAGMENT_PROGRAM, 1, 1.0 / width, 1.0 / height, width, height); } else mp_msg(MSGT_VO, MSGL_WARN, "[gl] Error parsing customtex %s\n", custom_tex); fclose(f); mpglActiveTexture(GL_TEXTURE0); } } }
static int initTextures(void) { struct TexSquare *tsq=0; GLfloat texpercx, texpercy; int s; int x=0, y=0; // textures smaller than 64x64 might not be supported s=64; while (s<image_width) s*=2; texture_width=s; s=64; while (s<image_height) s*=2; texture_height=s; if (!is_yuv) gl_internal_format = getInternalFormat(); /* Test the max texture size */ do { GLint w; glTexImage2D (GL_PROXY_TEXTURE_2D, 0, gl_internal_format, texture_width, texture_height, 0, gl_bitmap_format, gl_bitmap_type, NULL); glGetTexLevelParameteriv (GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); if (w >= texture_width) break; mp_msg (MSGT_VO, MSGL_V, "[gl_tiled] Needed texture [%dx%d] too big, trying ", texture_width, texture_height); if (texture_width > texture_height) texture_width /= 2; else texture_height /= 2; mp_msg (MSGT_VO, MSGL_V, "[%dx%d] !\n", texture_width, texture_height); if(texture_width < 64 || texture_height < 64) { mp_msg (MSGT_VO, MSGL_FATAL, "[gl_tiled] Give up .. usable texture size not available, or texture config error !\n"); return -1; } } while (texture_width > 1 && texture_height > 1); #ifdef TEXTURE_WIDTH texture_width = TEXTURE_WIDTH; #endif #ifdef TEXTURE_HEIGHT texture_height = TEXTURE_HEIGHT; #endif texnumx = image_width / texture_width; if ((image_width % texture_width) > 0) texnumx++; texnumy = image_height / texture_height; if ((image_height % texture_height) > 0) texnumy++; mp_msg(MSGT_VO, MSGL_V, "[gl_tiled] Creating %dx%d textures of size %dx%d ...\n", texnumx, texnumy, texture_width,texture_height); /* Allocate the texture memory */ texpercx = (GLfloat) texture_width / (GLfloat) image_width; texpercy = (GLfloat) texture_height / (GLfloat) image_height; free(texgrid); texgrid = calloc (texnumx * texnumy, sizeof (struct TexSquare)); raw_line_len = image_width * image_bytes; mp_msg (MSGT_VO, MSGL_DBG2, "[gl_tiled] texture-usage %d*width=%d, %d*height=%d\n", (int) texnumx, (int) texture_width, (int) texnumy, (int) texture_height); tsq = texgrid; for (y = 0; y < texnumy; y++) { for (x = 0; x < texnumx; x++) { tsq->fx = x * texpercx; tsq->fy = y * texpercy; tsq->fw = texpercx; tsq->fh = texpercy; tsq->texobj=0; tsq->uvtexobjs[0] = tsq->uvtexobjs[1] = 0; glGenTextures (1, &(tsq->texobj)); glBindTexture (GL_TEXTURE_2D, tsq->texobj); if (is_yuv) { glGenTextures(2, tsq->uvtexobjs); mpglActiveTexture(GL_TEXTURE1); glBindTexture (GL_TEXTURE_2D, tsq->uvtexobjs[0]); mpglActiveTexture(GL_TEXTURE2); glBindTexture (GL_TEXTURE_2D, tsq->uvtexobjs[1]); mpglActiveTexture(GL_TEXTURE0); } glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format, gl_bitmap_type, GL_LINEAR, texture_width, texture_height, 0); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); if (is_yuv) { int xs, ys, depth; int chroma_clear_val = 128; mp_get_chroma_shift(image_format, &xs, &ys, &depth); chroma_clear_val >>= -depth & 7; mpglActiveTexture(GL_TEXTURE1); glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format, gl_bitmap_type, GL_LINEAR, texture_width >> xs, texture_height >> ys, chroma_clear_val); mpglActiveTexture(GL_TEXTURE2); glCreateClearTex(GL_TEXTURE_2D, gl_internal_format, gl_bitmap_format, gl_bitmap_type, GL_LINEAR, texture_width >> xs, texture_height >> ys, chroma_clear_val); mpglActiveTexture(GL_TEXTURE0); } tsq++; } /* for all texnumx */ } /* for all texnumy */ return 0; }
void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){ mpi->flags&=~(MP_IMGFLAG_PLANAR|MP_IMGFLAG_YUV|MP_IMGFLAG_SWAPPED); mpi->imgfmt=out_fmt; // compressed formats if(out_fmt == IMGFMT_MPEGPES || IMGFMT_IS_HWACCEL(out_fmt)){ mpi->bpp=0; return; } mpi->num_planes=1; if (IMGFMT_IS_RGB(out_fmt)) { if (IMGFMT_RGB_DEPTH(out_fmt) < 8 && !(out_fmt&128)) mpi->bpp = IMGFMT_RGB_DEPTH(out_fmt); else mpi->bpp=(IMGFMT_RGB_DEPTH(out_fmt)+7)&(~7); return; } if (IMGFMT_IS_BGR(out_fmt)) { if (IMGFMT_BGR_DEPTH(out_fmt) < 8 && !(out_fmt&128)) mpi->bpp = IMGFMT_BGR_DEPTH(out_fmt); else mpi->bpp=(IMGFMT_BGR_DEPTH(out_fmt)+7)&(~7); mpi->flags|=MP_IMGFLAG_SWAPPED; return; } mpi->flags|=MP_IMGFLAG_YUV; mpi->num_planes=3; if (mp_get_chroma_shift(out_fmt, NULL, NULL, NULL)) { mpi->flags|=MP_IMGFLAG_PLANAR; mpi->bpp = mp_get_chroma_shift(out_fmt, &mpi->chroma_x_shift, &mpi->chroma_y_shift, NULL); mpi->chroma_width = mpi->width >> mpi->chroma_x_shift; mpi->chroma_height = mpi->height >> mpi->chroma_y_shift; } switch(out_fmt){ case IMGFMT_I420: case IMGFMT_IYUV: mpi->flags|=MP_IMGFLAG_SWAPPED; case IMGFMT_YV12: return; case IMGFMT_420A: case IMGFMT_IF09: mpi->num_planes=4; case IMGFMT_YVU9: case IMGFMT_444P: case IMGFMT_422P: case IMGFMT_411P: case IMGFMT_440P: case IMGFMT_444P16_LE: case IMGFMT_444P16_BE: case IMGFMT_444P10_LE: case IMGFMT_444P10_BE: case IMGFMT_444P9_LE: case IMGFMT_444P9_BE: case IMGFMT_422P16_LE: case IMGFMT_422P16_BE: case IMGFMT_422P10_LE: case IMGFMT_422P10_BE: case IMGFMT_420P16_LE: case IMGFMT_420P16_BE: case IMGFMT_420P10_LE: case IMGFMT_420P10_BE: case IMGFMT_420P9_LE: case IMGFMT_420P9_BE: return; case IMGFMT_Y800: case IMGFMT_Y8: /* they're planar ones, but for easier handling use them as packed */ mpi->flags&=~MP_IMGFLAG_PLANAR; mpi->num_planes=1; return; case IMGFMT_UYVY: mpi->flags|=MP_IMGFLAG_SWAPPED; case IMGFMT_YUY2: mpi->bpp=16; mpi->num_planes=1; return; case IMGFMT_NV12: mpi->flags|=MP_IMGFLAG_SWAPPED; case IMGFMT_NV21: mpi->flags|=MP_IMGFLAG_PLANAR; mpi->bpp=12; mpi->num_planes=2; mpi->chroma_width=(mpi->width>>0); mpi->chroma_height=(mpi->height>>1); mpi->chroma_x_shift=0; mpi->chroma_y_shift=1; return; } mp_msg(MSGT_DECVIDEO,MSGL_WARN,"mp_image: unknown out_fmt: 0x%X\n",out_fmt); mpi->bpp=0; }
static int query_format(uint32_t format) { if (mp_get_chroma_shift(format, NULL, NULL)) // Accept any planar YUV format. return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE | VOCAP_NOSLICES; else return VO_FALSE; }
/** * \brief Initialize a (new or reused) OpenGL context. * set global gl-related variables to their default values */ static int initGl(uint32_t d_width, uint32_t d_height) { GLint scale_type = get_scale_type(0); autodetectGlExtensions(); gl_target = use_rectangle == 1 ? GL_TEXTURE_RECTANGLE : GL_TEXTURE_2D; yuvconvtype = SET_YUV_CONVERSION(use_yuv) | SET_YUV_LUM_SCALER(lscale) | SET_YUV_CHROM_SCALER(cscale); texSize(image_width, image_height, &texture_width, &texture_height); mpglDisable(GL_BLEND); mpglDisable(GL_DEPTH_TEST); mpglDepthMask(GL_FALSE); mpglDisable(GL_CULL_FACE); mpglEnable(gl_target); mpglDrawBuffer(vo_doublebuffering?GL_BACK:GL_FRONT); mpglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); mp_msg(MSGT_VO, MSGL_V, "[gl] Creating %dx%d texture...\n", texture_width, texture_height); glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, scale_type, texture_width, texture_height, 0); if (mipmap_gen) mpglTexParameteri(gl_target, GL_GENERATE_MIPMAP, GL_TRUE); if (is_yuv) { int i; int xs, ys; scale_type = get_scale_type(1); mp_get_chroma_shift(image_format, &xs, &ys); mpglGenTextures(21, default_texs); default_texs[21] = 0; for (i = 0; i < 7; i++) { mpglActiveTexture(GL_TEXTURE1 + i); mpglBindTexture(GL_TEXTURE_2D, default_texs[i]); mpglBindTexture(GL_TEXTURE_RECTANGLE, default_texs[i + 7]); mpglBindTexture(GL_TEXTURE_3D, default_texs[i + 14]); } mpglActiveTexture(GL_TEXTURE1); glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, scale_type, texture_width >> xs, texture_height >> ys, 128); if (mipmap_gen) mpglTexParameteri(gl_target, GL_GENERATE_MIPMAP, GL_TRUE); mpglActiveTexture(GL_TEXTURE2); glCreateClearTex(gl_target, gl_texfmt, gl_format, gl_type, scale_type, texture_width >> xs, texture_height >> ys, 128); if (mipmap_gen) mpglTexParameteri(gl_target, GL_GENERATE_MIPMAP, GL_TRUE); mpglActiveTexture(GL_TEXTURE0); mpglBindTexture(gl_target, 0); } if (is_yuv || custom_prog) { if ((MASK_NOT_COMBINERS & (1 << use_yuv)) || custom_prog) { if (!mpglGenPrograms || !mpglBindProgram) { mp_msg(MSGT_VO, MSGL_ERR, "[gl] fragment program functions missing!\n"); } else { mpglGenPrograms(1, &fragprog); mpglBindProgram(GL_FRAGMENT_PROGRAM, fragprog); } } update_yuvconv(); } resize(d_width, d_height); mpglClearColor( 0.0f,0.0f,0.0f,0.0f ); mpglClear( GL_COLOR_BUFFER_BIT ); if (mpglSwapInterval && swap_interval >= 0) mpglSwapInterval(swap_interval); return 1; }