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

📄 frame.c

📁 linux下将各类格式图片转换工具
💻 C
📖 第 1 页 / 共 2 页
字号:
        frameMemory[idx]->y_blocks = NULL;         frameMemory[idx]->decoded_y = NULL;        frameMemory[idx]->halfX = NULL;        frameMemory[idx]->next = NULL;    }}/*===========================================================================* * * Frame_Exit * *  frees the memory associated with frames * * RETURNS: nothing * * SIDE EFFECTS:    frameMemory * *===========================================================================*/voidFrame_Exit() {    int idx;    for (idx = 0; idx < numOfFrames; ++idx) {        FreeFrame(frameMemory[idx]);    }}/*===========================================================================* * * Frame_Free * *  frees the given frame -- allows it to be re-used * * RETURNS: nothing * * SIDE EFFECTS:    none * *===========================================================================*/voidFrame_Free(frame)    MpegFrame *frame;{    frame->inUse = FALSE;}/*===========================================================================* * * Frame_New * *  finds a frame that isn't currently being used and resets it * * RETURNS: the frame * * SIDE EFFECTS:    none * *===========================================================================*/MpegFrame *Frame_New(id, type)    int id;    int type;{    MpegFrame *frame;    frame = GetUnusedFrame();    ResetFrame(id, type, frame);    return frame;}/*===========================================================================* * * Frame_AllocBlocks * *  allocate memory for blocks for the given frame, if required * * RETURNS: nothing * * SIDE EFFECTS:    none * *===========================================================================*/voidFrame_AllocBlocks(frame)    MpegFrame *frame;{    int dctx, dcty;    int i;    if ( frame->y_blocks != NULL ) {        /* already allocated */    return;    }    dctx = Fsize_x / DCTSIZE;    dcty = Fsize_y / DCTSIZE;    frame->y_blocks = (Block **) malloc(sizeof(Block *) * dcty);    ERRCHK(frame->y_blocks, "malloc");    for (i = 0; i < dcty; i++) {    frame->y_blocks[i] = (Block *) malloc(sizeof(Block) * dctx);    ERRCHK(frame->y_blocks[i], "malloc");    }    frame->cr_blocks = (Block **) malloc(sizeof(Block *) * (dcty >> 1));    frame->cb_blocks = (Block **) malloc(sizeof(Block *) * (dcty >> 1));    ERRCHK(frame->cr_blocks, "malloc");    ERRCHK(frame->cb_blocks, "malloc");    for (i = 0; i < (dcty >> 1); i++) {    frame->cr_blocks[i] = (Block *) malloc(sizeof(Block) * (dctx >> 1));    frame->cb_blocks[i] = (Block *) malloc(sizeof(Block) * (dctx >> 1));    ERRCHK(frame->cr_blocks[i], "malloc");    ERRCHK(frame->cb_blocks[i], "malloc");    }}/*===========================================================================* * * Frame_AllocYCC * *  allocate memory for YCC info for the given frame, if required * * RETURNS: nothing * * SIDE EFFECTS:    none * *===========================================================================*/voidFrame_AllocYCC(frame)    MpegFrame *frame;{    register int y;    if ( frame->orig_y != NULL ) {  /* already allocated */    return /* nothing */ ;    }    DBG_PRINT(("ycc_calc:\n"));    /*     * first, allocate tons of memory     */    frame->orig_y = (uint8 **) malloc(sizeof(uint8 *) * Fsize_y);    ERRCHK(frame->orig_y, "malloc");    for (y = 0; y < Fsize_y; y++) {    frame->orig_y[y] = (uint8 *) malloc(sizeof(uint8) * Fsize_x);    ERRCHK(frame->orig_y[y], "malloc");    }    frame->orig_cr = (uint8 **) malloc(sizeof(int8 *) * (Fsize_y >> 1));    ERRCHK(frame->orig_cr, "malloc");    for (y = 0; y < (Fsize_y >> 1); y++) {    frame->orig_cr[y] = (uint8 *) malloc(sizeof(int8) * (Fsize_x >> 1));    ERRCHK(frame->orig_cr[y], "malloc");    }    frame->orig_cb = (uint8 **) malloc(sizeof(int8 *) * (Fsize_y >> 1));    ERRCHK(frame->orig_cb, "malloc");    for (y = 0; y < (Fsize_y >> 1); y++) {    frame->orig_cb[y] = (uint8 *) malloc(sizeof(int8) * (Fsize_x >> 1));    ERRCHK(frame->orig_cb[y], "malloc");    }    if ( referenceFrame == ORIGINAL_FRAME ) {    frame->ref_y = frame->orig_y;    frame->ref_cr = frame->orig_cr;    frame->ref_cb = frame->orig_cb;    }}/*===========================================================================* * * Frame_AllocHalf * *  allocate memory for half-pixel values for the given frame, if required * * RETURNS: nothing * * SIDE EFFECTS:    none * *===========================================================================*/voidFrame_AllocHalf(frame)    MpegFrame *frame;{    register int y;    if ( frame->halfX != NULL ) {        return;    }    frame->halfX = (uint8 **) malloc(Fsize_y*sizeof(uint8 *));    ERRCHK(frame->halfX, "malloc");    frame->halfY = (uint8 **) malloc((Fsize_y-1)*sizeof(uint8 *));    ERRCHK(frame->halfY, "malloc");    frame->halfBoth = (uint8 **) malloc((Fsize_y-1)*sizeof(uint8 *));    ERRCHK(frame->halfBoth, "malloc");    for ( y = 0; y < Fsize_y; y++ ) {        frame->halfX[y] = (uint8 *) malloc((Fsize_x-1)*sizeof(uint8));        ERRCHK(frame->halfX[y], "malloc");    }    for ( y = 0; y < Fsize_y-1; y++ ) {        frame->halfY[y] = (uint8 *) malloc(Fsize_x*sizeof(uint8));        ERRCHK(frame->halfY[y], "malloc");    }    for ( y = 0; y < Fsize_y-1; y++ ) {        frame->halfBoth[y] = (uint8 *) malloc((Fsize_x-1)*sizeof(uint8));        ERRCHK(frame->halfBoth[y], "malloc");    }}/*===========================================================================* * * Frame_AllocDecoded * *  allocate memory for decoded frame for the given frame, if required *  if makeReference == TRUE, then makes it reference frame *  * RETURNS: nothing * * SIDE EFFECTS:    none * *===========================================================================*/voidFrame_AllocDecoded(frame, makeReference)    MpegFrame *frame;    boolean makeReference;{    register int y;    if ( frame->decoded_y != NULL) {    /* already allocated */    return;    }    /* allocate memory for decoded image */    /* can probably reuse original image memory, but may decide to use       it for some reason, so do it this way at least for now -- more       flexible     */    frame->decoded_y = (uint8 **) malloc(sizeof(uint8 *) * Fsize_y);    ERRCHK(frame->decoded_y, "malloc");    for (y = 0; y < Fsize_y; y++) {    frame->decoded_y[y] = (uint8 *) malloc(sizeof(uint8) * Fsize_x);    ERRCHK(frame->decoded_y[y], "malloc");    }    frame->decoded_cr = (uint8 **) malloc(sizeof(int8 *) * (Fsize_y >> 1));    ERRCHK(frame->decoded_cr, "malloc");    for (y = 0; y < (Fsize_y >> 1); y++) {    frame->decoded_cr[y] = (uint8 *) malloc(sizeof(uint8) * (Fsize_x >> 1));    ERRCHK(frame->decoded_cr[y], "malloc");    }    frame->decoded_cb = (uint8 **) malloc(sizeof(int8 *) * (Fsize_y >> 1));    ERRCHK(frame->decoded_cb, "malloc");    for (y = 0; y < (Fsize_y >> 1); y++) {    frame->decoded_cb[y] = (uint8 *) malloc(sizeof(uint8) * (Fsize_x >> 1));    ERRCHK(frame->decoded_cb[y], "malloc");    }    if ( makeReference ) {    frame->ref_y = frame->decoded_y;    frame->ref_cr = frame->decoded_cr;    frame->ref_cb = frame->decoded_cb;    }}/*=====================* * INTERNAL PROCEDURES * *=====================*//*===========================================================================* * * GetUnusedFrame * *  return an unused frame * * RETURNS: the frame * * SIDE EFFECTS:    none * *===========================================================================*/static MpegFrame *GetUnusedFrame() {    int idx;    for (idx = 0; idx < numOfFrames; ++idx) {        if (!frameMemory[idx]->inUse) {            frameMemory[idx]->inUse = TRUE;            break;        }    }    if (idx >= numOfFrames) {        fprintf(stderr, "ERROR:  No unused frames!!!\n");        fprintf(stderr, "        If you are using stdin for input, "                "it is likely that you have too many\n");        fprintf(stderr, "        B-frames between two reference frames.  "                "See the man page for help.\n");        exit(1);    }    return frameMemory[idx]; }/*===========================================================================* * * ResetFrame * *  reset a frame to the given id and type * * RETURNS: nothing * * SIDE EFFECTS:    none * *===========================================================================*/static voidResetFrame(id, type, frame)    int id;    int type;    MpegFrame *frame;{    switch (type) {    case 'i':    frame->type = TYPE_IFRAME;    break;    case 'p':    frame->type = TYPE_PFRAME;    break;    case 'b':    frame->type = TYPE_BFRAME;    break;    default:    fprintf(stderr, "frame type %c: not supported\n", type);    exit(1);    }    frame->id = id;    frame->halfComputed = FALSE;    frame->next = NULL;}/*===========================================================================* * * FreeFrame * *  frees the memory associated with the given frame * * RETURNS: nothing * * SIDE EFFECTS:    none * *===========================================================================*/static voidFreeFrame(MpegFrame * const frameP) {    if (frameP) {        if (frameP->orig_y) {            unsigned int i;            for (i = 0; i < Fsize_y; ++i)                free(frameP->orig_y[i]);            free(frameP->orig_y);            for (i = 0; i < (Fsize_y >> 1); ++i)                free(frameP->orig_cr[i]);            free(frameP->orig_cr);            for (i = 0; i < (Fsize_y >> 1); ++i)                free(frameP->orig_cb[i]);            free(frameP->orig_cb);        }        if (frameP->decoded_y) {            unsigned int i;            for (i = 0; i < Fsize_y; ++i)                free(frameP->decoded_y[i]);            free(frameP->decoded_y);            for (i = 0; i < (Fsize_y >> 1); ++i)                free(frameP->decoded_cr[i]);            free(frameP->decoded_cr);            for (i = 0; i < (Fsize_y >> 1); ++i)                free(frameP->decoded_cb[i]);            free(frameP->decoded_cb);        }        if (frameP->y_blocks) {            unsigned int i;            for (i = 0; i < Fsize_y / DCTSIZE; ++i)                free(frameP->y_blocks[i]);            free(frameP->y_blocks);            for (i = 0; i < Fsize_y / (2 * DCTSIZE); ++i)                free(frameP->cr_blocks[i]);            free(frameP->cr_blocks);            for (i = 0; i < Fsize_y / (2 * DCTSIZE); ++i)                free(frameP->cb_blocks[i]);            free(frameP->cb_blocks);        }        if (frameP->halfX) {            unsigned int i;            for ( i = 0; i < Fsize_y; ++i )                free(frameP->halfX[i]);            free(frameP->halfX);                        for (i = 0; i < Fsize_y-1; ++i)                free(frameP->halfY[i]);            free(frameP->halfY);                        for (i = 0; i < Fsize_y-1; ++i)                free(frameP->halfBoth[i]);            free(frameP->halfBoth);        }        free(frameP);    }}

⌨️ 快捷键说明

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