📄 getpic.c.bak
字号:
int clipped; if (x > 2047) clipped = 2047; else if (x < 0) clipped = 0; else clipped = x; return clipped;}/********************************************************************** * * Name: EdgeFilter * Description: performs in the loop edge-filtering on * reconstructed frames * * Input: pointers to reconstructed frame and difference * image * Returns: * Side effects: since neither the algorithm nor the routines * have been optimized for speed, the use of the * edge-filter slows down decoding speed * * Date: 951129 Author: Gisle.Bjontegaard@fou.telenor.no * Karl.Lillevold@nta.no * Date: 970820 Author: guyc@ee.ubc.ca * modified to implement annex J of H.263+ * ***********************************************************************/void edge_filter (unsigned char *lum, unsigned char *Cb, unsigned char *Cr, int width, int height){ /* Luma */ horiz_edge_filter (lum, width, height, 0); vert_edge_filter (lum, width, height, 0); /* Chroma */ horiz_edge_filter (Cb, width / 2, height / 2, 1); vert_edge_filter (Cb, width / 2, height / 2, 1); horiz_edge_filter (Cr, width / 2, height / 2, 1); vert_edge_filter (Cr, width / 2, height / 2, 1); /* that's it */ return;}/***********************************************************************/void horiz_edge_filter (unsigned char *rec, int width, int height, int chr){ int i, j; int delta, d1, d2; int mbc, mbr, do_filter; int QP; int mbr_above; /* horizontal edges */ for (j = 8; j < height; j += 8) { for (i = 0; i < width; i++) { if (!chr) { mbr = j >> 4; mbc = i >> 4; mbr_above = (j - 8) >> 4; } else { mbr = j >> 3; mbc = i >> 3; mbr_above = mbr - 1; } do_filter = coded_map[mbr + 1][mbc + 1] || coded_map[mbr_above + 1][mbc + 1]; if (do_filter) { if (pb_frame) { QP = coded_map[mbr + 1][mbc + 1] ? mmax (1, mmin (31, bquant_tab[bquant] * quant_map[mbr + 1][mbc + 1] / 4)) : mmax (1, mmin (31, bquant_tab[bquant] * quant_map[mbr_above + 1][mbc + 1] / 4)); } else QP = coded_map[mbr + 1][mbc + 1] ? quant_map[mbr + 1][mbc + 1] : quant_map[mbr_above + 1][mbc + 1]; if (chr && modified_quantization_mode) { QP = MQ_chroma_QP_table[QP]; } delta = (int) (((int) (*(rec + i + (j - 2) * width)) + (int) (*(rec + i + (j - 1) * width) * (-4)) + (int) (*(rec + i + (j) * width) * (4)) + (int) (*(rec + i + (j + 1) * width) * (-1))) / 8.0); d1 = sign (delta) * mmax (0, abs (delta) - mmax (0, 2 * (abs (delta) - STRENGTH[QP - 1]))); d2 = mmin (abs (d1 / 2), mmax (-abs (d1 / 2), (int) (((*(rec + i + (j - 2) * width) - *(rec + i + (j + 1) * width))) / 4))); *(rec + i + (j + 1) * width) += d2; /* D */ *(rec + i + (j) * width) = mmin (255, mmax (0, (int) (*(rec + i + (j) * width)) - d1)); /* C */ *(rec + i + (j - 1) * width) = mmin (255, mmax (0, (int) (*(rec + i + (j - 1) * width)) + d1)); /* B */ *(rec + i + (j - 2) * width) -= d2; /* A */ } } } return;}void vert_edge_filter (unsigned char *rec, int width, int height, int chr){ int i, j; int delta, d1, d2; int mbc, mbr; int do_filter; int QP; int mbc_left; /* vertical edges */ for (i = 8; i < width; i += 8) { for (j = 0; j < height; j++) { if (!chr) { mbr = j >> 4; mbc = i >> 4; mbc_left = (i - 8) >> 4; } else { mbr = j >> 3; mbc = i >> 3; mbc_left = mbc - 1; } do_filter = coded_map[mbr + 1][mbc + 1] || coded_map[mbr + 1][mbc_left + 1]; if (do_filter) { if (pb_frame) { QP = coded_map[mbr + 1][mbc + 1] ? mmax (1, mmin (31, bquant_tab[bquant] * quant_map[mbr + 1][mbc + 1] / 4)) : mmax (1, mmin (31, bquant_tab[bquant] * quant_map[mbr + 1][mbc_left + 1] / 4)); } else QP = coded_map[mbr + 1][mbc + 1] ? quant_map[mbr + 1][mbc + 1] : quant_map[mbr + 1][mbc_left + 1]; if (chr && modified_quantization_mode) { QP = MQ_chroma_QP_table[QP]; } delta = (int) (((int) (*(rec + i - 2 + j * width)) + (int) (*(rec + i - 1 + j * width) * (-4)) + (int) (*(rec + i + j * width) * (4)) + (int) (*(rec + i + 1 + j * width) * (-1))) / 8.0); d1 = sign (delta) * mmax (0, abs (delta) - mmax (0, 2 * (abs (delta) - STRENGTH[QP - 1]))); d2 = mmin (abs (d1 / 2), mmax (-abs (d1 / 2), (int) ((*(rec + i - 2 + j * width) - *(rec + i + 1 + j * width)) / 4))); *(rec + i + 1 + j * width) += d2; /* D */ *(rec + i + j * width) = mmin (255, mmax (0, (int) (*(rec + i + j * width)) - d1)); /* C */ *(rec + i - 1 + j * width) = mmin (255, mmax (0, (int) (*(rec + i - 1 + j * width)) + d1)); /* B */ *(rec + i - 2 + j * width) -= d2; /* A */ } } } return;}void horiz_post_filter (unsigned char *rec, int width, int height, int chr){ int i, j; int delta, d1; int mbc, mbr; int QP; int mbr_above; /* horizontal edges */ for (j = 8; j < height; j += 8) { for (i = 0; i < width; i++) { if (!chr) { mbr = j >> 4; mbc = i >> 4; mbr_above = (j - 8) >> 4; } else { mbr = j >> 3; mbc = i >> 3; mbr_above = mbr - 1; } if (pb_frame) { QP = coded_map[mbr + 1][mbc + 1] ? mmax (1, mmin (31, bquant_tab[bquant] * quant_map[mbr + 1][mbc + 1] / 4)) : mmax (1, mmin (31, bquant_tab[bquant] * quant_map[mbr_above + 1][mbc + 1] / 4)); } else QP = coded_map[mbr + 1][mbc + 1] ? quant_map[mbr + 1][mbc + 1] : quant_map[mbr_above + 1][mbc + 1]; delta = (int) (((int) (*(rec + i + (j - 3) * width)) + (int) (*(rec + i + (j - 2) * width)) + (int) (*(rec + i + (j - 1) * width)) + (int) (*(rec + i + (j) * width) * (-6)) + (int) (*(rec + i + (j + 1) * width)) + (int) (*(rec + i + (j + 2) * width)) + (int) (*(rec + i + (j + 3) * width))) / 8.0); d1 = sign (delta) * mmax (0, abs (delta) - mmax (0, 2 * (abs (delta) - STRENGTH1[QP - 1]))); /* Filter D */ *(rec + i + (j) * width) += d1; } } return;}void vert_post_filter (unsigned char *rec, int width, int height, int chr){ int i, j; int delta, d1; int mbc, mbr; int QP; int mbc_left; /* vertical edges */ for (i = 8; i < width; i += 8) { for (j = 0; j < height; j++) { if (!chr) { mbr = j >> 4; mbc = i >> 4; mbc_left = (i - 8) >> 4; } else { mbr = j >> 3; mbc = i >> 3; mbc_left = mbc - 1; } if (pb_frame) { QP = coded_map[mbr + 1][mbc + 1] ? mmax (1, mmin (31, bquant_tab[bquant] * quant_map[mbr + 1][mbc + 1] / 4)) : mmax (1, mmin (31, bquant_tab[bquant] * quant_map[mbr + 1][mbc_left + 1] / 4)); } else QP = coded_map[mbr + 1][mbc + 1] ? quant_map[mbr + 1][mbc + 1] : quant_map[mbr + 1][mbc_left + 1]; delta = (int) (((int) (*(rec + i - 3 + j * width)) + (int) (*(rec + i - 2 + j * width)) + (int) (*(rec + i - 1 + j * width)) + (int) (*(rec + i + j * width) * (-6)) + (int) (*(rec + i + 1 + j * width)) + (int) (*(rec + i + 2 + j * width)) + (int) (*(rec + i + 3 + j * width))) / 8.0); d1 = sign (delta) * mmax (0, abs (delta) - mmax (0, 2 * (abs (delta) - STRENGTH2[QP - 1]))); /* Post Filter D */ *(rec + i + j * width) += d1; } } return;}/********************************************************************** * * Name: DisplayPicture * Description: manages a one frame buffer for re-ordering frames prior * to displaying or writing to a file. * Input: frame number * Returns: * Side effects: * * Date: 971102 Author: mikeg@ee.ubc.ca * ***********************************************************************/void PictureDisplay(int *framenum){ unsigned char *frame_to_display[3]; static int last_frame_disposable = 0, display_buffer_empty = 1; static int buffered_frame_temp_ref = 0, display_framenum = 0; int cc, size, update_buffered_frame; if (display_buffer_empty) { /* Store current (initial) frame. */ update_buffered_frame = ON; } else { if ( (temp_ref < buffered_frame_temp_ref) && (PCT_B == pict_type) ) { /* Do not store current frame. */ update_buffered_frame = OFF; /* Display current frame. */ display_framenum = *framenum; frame_to_display[0] = current_frame[0]; frame_to_display[1] = current_frame[1]; frame_to_display[2] = current_frame[2]; } else if ( (PCT_INTRA == pict_type) && (temp_ref < buffered_frame_temp_ref) ) { /* INTRA refresh with temp_ref reset has occurred, * display frame in buffer and start over */ display_framenum = buffered_framenum; frame_to_display[0] = buffered_frame[0]; frame_to_display[1] = buffered_frame[1]; frame_to_display[2] = buffered_frame[2]; /* Store current frame. */ update_buffered_frame = ON; } else { /* Diplay frame in storage. */ display_framenum = buffered_framenum; frame_to_display[0] = buffered_frame[0]; frame_to_display[1] = buffered_frame[1]; frame_to_display[2] = buffered_frame[2]; /* Store current frame. */ update_buffered_frame = ON; } } if (!display_buffer_empty) { //20070702 /* Post Filter */// if (expand && outtype == T_X11)// {// /* display this image and keep frame already in storage where it is. */// interpolate_image (frame_to_display[0], exnewframe[0],// coded_picture_width, coded_picture_height);// interpolate_image (frame_to_display[1], exnewframe[1], chrom_width, chrom_height);// interpolate_image (frame_to_display[2], exnewframe[2], chrom_width, chrom_height);// storeframe (exnewframe, *framenum);// if (pb_frame)// {//// (*framenum)++;// interpolate_image (bframe[0], exnewframe[0], coded_picture_width, coded_picture_height);// interpolate_image (bframe[1], exnewframe[1], chrom_width, chrom_height);// interpolate_image (bframe[2], exnewframe[2], chrom_width, chrom_height);// storeframe (exnewframe, *framenum);// }// } // else// { storeframe (frame_to_display, *framenum); if (pb_frame) { (*framenum)++; storeframe (bframe, *framenum); }// } } /* After first decoded frame, the buffer is never again empty, until * flushed. */ if (display_buffer_empty) { display_buffer_empty = 0; } if (update_buffered_frame) { buffered_frame_temp_ref += ( (temp_ref-buffered_frame_temp_ref) < 0 ) ? (temp_ref-buffered_frame_temp_ref+256) : (temp_ref-buffered_frame_temp_ref); buffered_framenum = *framenum; for (cc = 0; cc < 3; cc++) { if (cc == 0) size = coded_picture_width * coded_picture_height; else size = chrom_width * chrom_height; memcpy (buffered_frame[cc], current_frame[cc], size); } }}void conceal_missing_gobs(int start_mb_row_missing, int number_of_mb_rows_missing){ /* counters */ int xpos, ypos; int bx,by; int end = start_mb_row_missing + number_of_mb_rows_missing; for (ypos = start_mb_row_missing; ypos < end; ypos++) { for (xpos = 0; xpos < mb_width; xpos++) { bx = 16 * xpos; by = 16 * ypos; /* Assume mode was Inter */ modemap[ypos+1][xpos+1] = MODE_INTER; /* copy the motion vectors from the GOB above if present */ /* (at ypos = 0, just use 0 MVs */ if(!start_mb_row_missing) { MV[0][0][ypos + 1][xpos + 1] = 0; MV[1][0][ypos + 1][xpos + 1] = 0; } else { MV[0][0][ypos + 1][xpos + 1] = MV[0][0][start_mb_row_missing][xpos + 1]; MV[1][0][ypos + 1][xpos + 1] = MV[1][0][start_mb_row_missing][xpos + 1]; } /* motion compensation for P-frame */ /* Always assume MBs were INTER coded */ reconstruct (bx, by, 1, 0, 0, 0, 1); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -