vo_pnm.c
来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 599 行 · 第 1/2 页
C
599 行
static void pnm_write_pnm(FILE *outfile, mp_image_t *mpi){ uint32_t w = mpi->w; uint32_t h = mpi->h; uint8_t *rgbimage = mpi->planes[0]; uint8_t *planeY = mpi->planes[0]; uint8_t *planeU = mpi->planes[1]; uint8_t *planeV = mpi->planes[2]; uint8_t *curline; uint32_t strideY = mpi->stride[0]; uint32_t strideU = mpi->stride[1]; uint32_t strideV = mpi->stride[2]; unsigned int i, j; if (pnm_mode == PNM_RAW_MODE) { if (pnm_type == PNM_TYPE_PPM) { if ( fprintf(outfile, "P6\n%d %d\n255\n", w, h) < 0 ) pnm_write_error(); if ( fwrite(rgbimage, w * 3, h, outfile) < h ) pnm_write_error(); } else if (pnm_type == PNM_TYPE_PGM) { if ( fprintf(outfile, "P5\n%d %d\n255\n", w, h) < 0 ) pnm_write_error(); for (i=0; i<h; i++) { if ( fwrite(planeY + i * strideY, w, 1, outfile) < 1 ) pnm_write_error(); } } else if (pnm_type == PNM_TYPE_PGMYUV) { if ( fprintf(outfile, "P5\n%d %d\n255\n", w, h*3/2) < 0 ) pnm_write_error(); for (i=0; i<h; i++) { if ( fwrite(planeY + i * strideY, w, 1, outfile) < 1 ) pnm_write_error(); } w = w / 2; h = h / 2; for (i=0; i<h; i++) { if ( fwrite(planeU + i * strideU, w, 1, outfile) < 1 ) pnm_write_error(); if ( fwrite(planeV + i * strideV, w, 1, outfile) < 1 ) pnm_write_error(); } } /* end if pnm_type */ } else if (pnm_mode == PNM_ASCII_MODE) { if (pnm_type == PNM_TYPE_PPM) { if ( fprintf(outfile, "P3\n%d %d\n255\n", w, h) < 0 ) pnm_write_error(); for (i=0; i <= w * h * 3 - 16 ; i += 15) { if ( fprintf(outfile, PNM_LINE_OF_ASCII, PNM_LINE15(rgbimage,i) ) < 0 ) pnm_write_error(); } while (i < (w * h * 3) ) { if ( fprintf(outfile, "%03d ", rgbimage[i]) < 0 ) pnm_write_error(); i++; } if ( fputc('\n', outfile) < 0 ) pnm_write_error(); } else if ( (pnm_type == PNM_TYPE_PGM) || (pnm_type == PNM_TYPE_PGMYUV) ) { /* different header for pgm and pgmyuv. pgmyuv is 'higher' */ if (pnm_type == PNM_TYPE_PGM) { if ( fprintf(outfile, "P2\n%d %d\n255\n", w, h) < 0 ) pnm_write_error(); } else { /* PNM_TYPE_PGMYUV */ if ( fprintf(outfile, "P2\n%d %d\n255\n", w, h*3/2) < 0 ) pnm_write_error(); } /* output Y plane for both PGM and PGMYUV */ for (j=0; j<h; j++) { curline = planeY + strideY * j; for (i=0; i <= w - 16; i+=15) { if ( fprintf(outfile, PNM_LINE_OF_ASCII, PNM_LINE15(curline,i) ) < 0 ) pnm_write_error(); } while (i < w ) { if ( fprintf(outfile, "%03d ", curline[i]) < 0 ) pnm_write_error(); i++; } if ( fputc('\n', outfile) < 0 ) pnm_write_error(); } /* also output U and V planes fpr PGMYUV */ if (pnm_type == PNM_TYPE_PGMYUV) { w = w / 2; h = h / 2; for (j=0; j<h; j++) { curline = planeU + strideU * j; for (i=0; i<= w-16; i+=15) { if ( fprintf(outfile, PNM_LINE_OF_ASCII, PNM_LINE15(curline,i) ) < 0 ) pnm_write_error(); } while (i < w ) { if ( fprintf(outfile, "%03d ", curline[i]) < 0 ) pnm_write_error(); i++; } if ( fputc('\n', outfile) < 0 ) pnm_write_error(); curline = planeV + strideV * j; for (i=0; i<= w-16; i+=15) { if ( fprintf(outfile, PNM_LINE_OF_ASCII, PNM_LINE15(curline,i) ) < 0 ) pnm_write_error(); } while (i < w ) { if ( fprintf(outfile, "%03d ", curline[i]) < 0 ) pnm_write_error(); i++; } if ( fputc('\n', outfile) < 0 ) pnm_write_error(); } } } /* end if pnm_type */ } /* end if pnm_mode */}/* ------------------------------------------------------------------------- *//** \brief Write a PNM image. * * This function gets called first if a PNM image has to be written to disk. * It contains the subdirectory framework and it calls pnm_write_pnm() to * actually write the image to disk. * * \param mpi The image to write. * * \return none The player will exit if anything goes wrong. */static void pnm_write_image(mp_image_t *mpi){ static int framenum = 0, framecounter = 0, subdircounter = 0; char buf[BUFLENGTH]; static char subdirname[BUFLENGTH] = ""; FILE *outfile; if (!mpi) { mp_msg(MSGT_VO, MSGL_ERR, "%s: No image data suplied to video output driver\n", info.short_name ); exit_player(MSGTR_Exit_error); } /* Start writing to new subdirectory after a certain amount of frames */ if ( framecounter == pnm_maxfiles ) { framecounter = 0; } /* If framecounter is zero (or reset to zero), increment subdirectory * number and create the subdirectory. * If pnm_subdirs is not set, do nothing. */ if ( !framecounter && pnm_subdirs ) { subdircounter++; snprintf(subdirname, BUFLENGTH, "%s%08d", pnm_subdirs, subdircounter); snprintf(buf, BUFLENGTH, "%s/%s", pnm_outdir, subdirname); pnm_mkdir(buf, 0); /* This function only returns if creation was successful. If not, the player will exit. */ } framenum++; framecounter++; /* snprintf the full pathname of the outputfile */ snprintf(buf, BUFLENGTH, "%s/%s/%08d.%s", pnm_outdir, subdirname, framenum, pnm_file_extension); if ( (outfile = fopen(buf, "wb") ) == NULL ) { mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s\n", info.short_name, MSGTR_VO_CantCreateFile); mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, MSGTR_VO_GenericError, strerror(errno) ); exit_player(MSGTR_Exit_error); } pnm_write_pnm(outfile, mpi); fclose(outfile);}/* ------------------------------------------------------------------------- */static uint32_t draw_image(mp_image_t *mpi){ if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */ if (mpi->flags & MP_IMGFLAG_YUV) { /* Planar YUV */ pnm_write_image(mpi); return VO_TRUE; } else { /* Planar RGB */ return VO_FALSE; } } else { /* Packed */ if (mpi->flags & MP_IMGFLAG_YUV) { /* Packed YUV */ return VO_FALSE; } else { /* Packed RGB */ pnm_write_image(mpi); return VO_TRUE; } } return VO_FALSE;}/* ------------------------------------------------------------------------- */static int draw_frame(uint8_t *src[]){ mp_msg(MSGT_VO, MSGL_V, "%s: draw_frame() is called!\n", info.short_name); return -1;}/* ------------------------------------------------------------------------- */static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y){ return 0;}/* ------------------------------------------------------------------------- */static int query_format(uint32_t format){ /* Ensure that for PPM we get Packed RGB and for PGM(YUV) we get * Planar YUV */ if (pnm_type == PNM_TYPE_PPM) { if (format == IMGFMT_RGB24) { return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; } } else if ( (pnm_type == PNM_TYPE_PGM) || (pnm_type == PNM_TYPE_PGMYUV) ) { if (format == IMGFMT_YV12) { return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; } } return 0;}/* ------------------------------------------------------------------------- */static int control(uint32_t request, void *data, ...){ switch (request) { case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); case VOCTRL_DRAW_IMAGE: return draw_image(data); } return VO_NOTIMPL;}/* ------------------------------------------------------------------------- */static void uninit(void){ if (pnm_subdirs) { free(pnm_subdirs); pnm_subdirs = NULL; } if (pnm_outdir) { free(pnm_outdir); pnm_outdir = NULL; }}/* ------------------------------------------------------------------------- */static void check_events(void){}/* ------------------------------------------------------------------------- */static void draw_osd(void){}/* ------------------------------------------------------------------------- */static void flip_page (void){}/* ------------------------------------------------------------------------- */#undef BUFLENGTH#undef PNM_RAW_MODE#undef PNM_ASCII_MODE#undef PNM_TYPE_PPM#undef PNM_TYPE_PGM#undef PNM_TYPE_PGMYUV/* ------------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?