# HG changeset patch # User michaelni # Date 1030864778 0 # Node ID b4ee42142ad1773973612578c2a043f916b67c35 # Parent f65040bf435720a22bcf1eb751be94a7203ff589 croping patch by (talus25 at speakeasy dot net) with fixes from atmos & me diff -r f65040bf4357 -r b4ee42142ad1 avcodec.h --- a/avcodec.h Sat Aug 31 14:17:51 2002 +0000 +++ b/avcodec.h Sun Sep 01 07:19:38 2002 +0000 @@ -463,6 +463,12 @@ ImgReSampleContext *img_resample_init(int output_width, int output_height, int input_width, int input_height); + +ImgReSampleContext *img_resample_full_init(int owidth, int oheight, + int iwidth, int iheight, + int topBand, int bottomBand, + int leftBand, int rightBand); + void img_resample(ImgReSampleContext *s, AVPicture *output, AVPicture *input); diff -r f65040bf4357 -r b4ee42142ad1 imgresample.c --- a/imgresample.c Sat Aug 31 14:17:51 2002 +0000 +++ b/imgresample.c Sun Sep 01 07:19:38 2002 +0000 @@ -30,6 +30,7 @@ #define NB_PHASES (1 << PHASE_BITS) #define NB_TAPS 4 #define FCENTER 1 /* index of the center of the filter */ +//#define TEST 1 /* Test it */ #define POS_FRAC_BITS 16 #define POS_FRAC (1 << POS_FRAC_BITS) @@ -39,7 +40,7 @@ #define LINE_BUF_HEIGHT (NB_TAPS * 4) struct ImgReSampleContext { - int iwidth, iheight, owidth, oheight; + int iwidth, iheight, owidth, oheight, topBand, bottomBand, leftBand, rightBand; int h_incr, v_incr; INT16 h_filters[NB_PHASES][NB_TAPS] __align8; /* horizontal filters */ INT16 v_filters[NB_PHASES][NB_TAPS] __align8; /* vertical filters */ @@ -353,8 +354,8 @@ if (++ring_y >= LINE_BUF_HEIGHT + NB_TAPS) ring_y = NB_TAPS; last_src_y++; - /* handle limit conditions : replicate line (slighly - inefficient because we filter multiple times */ + /* handle limit conditions : replicate line (slightly + inefficient because we filter multiple times) */ y1 = last_src_y; if (y1 < 0) { y1 = 0; @@ -428,6 +429,14 @@ ImgReSampleContext *img_resample_init(int owidth, int oheight, int iwidth, int iheight) { + return img_resample_full_init(owidth, oheight, iwidth, iheight, 0, 0, 0, 0); +} + +ImgReSampleContext *img_resample_full_init(int owidth, int oheight, + int iwidth, int iheight, + int topBand, int bottomBand, + int leftBand, int rightBand) +{ ImgReSampleContext *s; s = av_mallocz(sizeof(ImgReSampleContext)); @@ -441,12 +450,16 @@ s->oheight = oheight; s->iwidth = iwidth; s->iheight = iheight; + s->topBand = topBand; + s->bottomBand = bottomBand; + s->leftBand = leftBand; + s->rightBand = rightBand; - s->h_incr = (iwidth * POS_FRAC) / owidth; - s->v_incr = (iheight * POS_FRAC) / oheight; + s->h_incr = ((iwidth - leftBand - rightBand) * POS_FRAC) / owidth; + s->v_incr = ((iheight - topBand - bottomBand) * POS_FRAC) / oheight; - build_filter(&s->h_filters[0][0], (float)owidth / (float)iwidth); - build_filter(&s->v_filters[0][0], (float)oheight / (float)iheight); + build_filter(&s->h_filters[0][0], (float) owidth / (float) (iwidth - leftBand - rightBand)); + build_filter(&s->v_filters[0][0], (float) oheight / (float) (iheight - topBand - bottomBand)); return s; fail: @@ -463,8 +476,9 @@ shift = (i == 0) ? 0 : 1; component_resample(s, output->data[i], output->linesize[i], s->owidth >> shift, s->oheight >> shift, - input->data[i], input->linesize[i], - s->iwidth >> shift, s->iheight >> shift); + input->data[i] + (input->linesize[i] * (s->topBand >> shift)) + (s->leftBand >> shift), + input->linesize[i], ((s->iwidth - s->leftBand - s->rightBand) >> shift), + (s->iheight - s->topBand - s->bottomBand) >> shift); } } @@ -484,6 +498,13 @@ return ptr; } +void av_free(void *ptr) +{ + /* XXX: this test should not be needed on most libcs */ + if (ptr) + free(ptr); +} + /* input */ #define XSIZE 256 #define YSIZE 256 @@ -569,19 +590,19 @@ } else { v = ((x + y - XSIZE) * 255) / XSIZE; } - img[y * XSIZE + x] = v; + img[(YSIZE - y) * XSIZE + (XSIZE - x)] = v; } } save_pgm("/tmp/in.pgm", img, XSIZE, YSIZE); for(i=0;ih_filters[0][0]); component_resample(s, img1, xsize, xsize, ysize, - img, XSIZE, XSIZE, YSIZE); + img + 50 * XSIZE, XSIZE, XSIZE, YSIZE - 100); img_resample_close(s); sprintf(buf, "/tmp/out%d.pgm", i);