Mercurial > libavcodec.hg
comparison roqvideoenc.c @ 5191:4870b71fe348 libavcodec
use the right stride
patch by Vitor: [vitor1001 gmail com]
author | benoit |
---|---|
date | Wed, 27 Jun 2007 06:57:31 +0000 |
parents | f3873cd7f473 |
children | 579c01dbb5a1 |
comparison
equal
deleted
inserted
replaced
5190:c356e14774cb | 5191:4870b71fe348 |
---|---|
123 } | 123 } |
124 | 124 |
125 // FIXME Could use DSPContext.sse, but it is not so speed critical (used | 125 // FIXME Could use DSPContext.sse, but it is not so speed critical (used |
126 // just for motion estimation). | 126 // just for motion estimation). |
127 static int block_sse(uint8_t **buf1, uint8_t **buf2, int x1, int y1, int x2, | 127 static int block_sse(uint8_t **buf1, uint8_t **buf2, int x1, int y1, int x2, |
128 int y2, int stride, int size) | 128 int y2, int *stride, int size) |
129 { | 129 { |
130 int i, k; | 130 int i, k; |
131 int sse=0; | 131 int sse=0; |
132 | 132 |
133 for (k=0; k<3; k++) { | 133 for (k=0; k<3; k++) { |
134 int bias = (k ? CHROMA_BIAS : 4); | 134 int bias = (k ? CHROMA_BIAS : 4); |
135 for (i=0; i<size; i++) | 135 for (i=0; i<size; i++) |
136 sse += bias*eval_sse(buf1[k] + (y1+i)*stride + x1, | 136 sse += bias*eval_sse(buf1[k] + (y1+i)*stride[k] + x1, |
137 buf2[k] + (y2+i)*stride + x2, size); | 137 buf2[k] + (y2+i)*stride[k] + x2, size); |
138 } | 138 } |
139 | 139 |
140 return sse; | 140 return sse; |
141 } | 141 } |
142 | 142 |
157 | 157 |
158 if ((unsigned) mx > enc->width-size || (unsigned) my > enc->height-size) | 158 if ((unsigned) mx > enc->width-size || (unsigned) my > enc->height-size) |
159 return INT_MAX; | 159 return INT_MAX; |
160 | 160 |
161 return block_sse(enc->frame_to_enc->data, enc->last_frame->data, x, y, | 161 return block_sse(enc->frame_to_enc->data, enc->last_frame->data, x, y, |
162 mx, my, enc->y_stride, size); | 162 mx, my, enc->frame_to_enc->linesize, size); |
163 } | 163 } |
164 | 164 |
165 /** | 165 /** |
166 * Returns distortion between two macroblocks | 166 * Returns distortion between two macroblocks |
167 */ | 167 */ |
259 * Get macroblocks from parts of the image | 259 * Get macroblocks from parts of the image |
260 */ | 260 */ |
261 static void get_frame_mb(AVFrame *frame, int x, int y, uint8_t mb[], int dim) | 261 static void get_frame_mb(AVFrame *frame, int x, int y, uint8_t mb[], int dim) |
262 { | 262 { |
263 int i, j, cp; | 263 int i, j, cp; |
264 int stride = frame->linesize[0]; | 264 |
265 | 265 for (cp=0; cp<3; cp++) { |
266 for (cp=0; cp<3; cp++) | 266 int stride = frame->linesize[cp]; |
267 for (i=0; i<dim; i++) | 267 for (i=0; i<dim; i++) |
268 for (j=0; j<dim; j++) | 268 for (j=0; j<dim; j++) |
269 *mb++ = frame->data[cp][(y+i)*stride + x + j]; | 269 *mb++ = frame->data[cp][(y+i)*stride + x + j]; |
270 } | |
270 } | 271 } |
271 | 272 |
272 /** | 273 /** |
273 * Find the codebook with the lowest distortion from an image | 274 * Find the codebook with the lowest distortion from an image |
274 */ | 275 */ |
412 subcel->eval_dist[RoQ_ID_FCC] = INT_MAX; | 413 subcel->eval_dist[RoQ_ID_FCC] = INT_MAX; |
413 | 414 |
414 if (enc->framesSinceKeyframe >= 2) | 415 if (enc->framesSinceKeyframe >= 2) |
415 subcel->eval_dist[RoQ_ID_MOT] = block_sse(enc->frame_to_enc->data, | 416 subcel->eval_dist[RoQ_ID_MOT] = block_sse(enc->frame_to_enc->data, |
416 enc->current_frame->data, x, | 417 enc->current_frame->data, x, |
417 y, x, y, enc->y_stride, 4); | 418 y, x, y, |
419 enc->frame_to_enc->linesize, | |
420 4); | |
418 else | 421 else |
419 subcel->eval_dist[RoQ_ID_MOT] = INT_MAX; | 422 subcel->eval_dist[RoQ_ID_MOT] = INT_MAX; |
420 | 423 |
421 cluster_index = y*enc->width/16 + x/4; | 424 cluster_index = y*enc->width/16 + x/4; |
422 | 425 |
474 if (enc->framesSinceKeyframe >= 2) | 477 if (enc->framesSinceKeyframe >= 2) |
475 cel->eval_dist[RoQ_ID_MOT] = block_sse(enc->frame_to_enc->data, | 478 cel->eval_dist[RoQ_ID_MOT] = block_sse(enc->frame_to_enc->data, |
476 enc->current_frame->data, | 479 enc->current_frame->data, |
477 cel->sourceX, cel->sourceY, | 480 cel->sourceX, cel->sourceY, |
478 cel->sourceX, cel->sourceY, | 481 cel->sourceX, cel->sourceY, |
479 enc->y_stride, 8); | 482 enc->frame_to_enc->linesize, 8); |
480 else | 483 else |
481 cel->eval_dist[RoQ_ID_MOT] = INT_MAX; | 484 cel->eval_dist[RoQ_ID_MOT] = INT_MAX; |
482 | 485 |
483 get_frame_mb(enc->frame_to_enc, cel->sourceX, cel->sourceY, mb8, 8); | 486 get_frame_mb(enc->frame_to_enc, cel->sourceX, cel->sourceY, mb8, 8); |
484 | 487 |
735 enc->current_frame->data[1], | 738 enc->current_frame->data[1], |
736 enc->current_frame->data[2]}; | 739 enc->current_frame->data[2]}; |
737 av_log(enc->avctx, AV_LOG_ERROR, "Expected distortion: %i Actual: %i\n", | 740 av_log(enc->avctx, AV_LOG_ERROR, "Expected distortion: %i Actual: %i\n", |
738 dist, | 741 dist, |
739 block_sse(fdata, cdata, 0, 0, 0, 0, | 742 block_sse(fdata, cdata, 0, 0, 0, 0, |
740 enc->y_stride, enc->width)); //WARNING: Square dimensions implied... | 743 enc->frame_to_enc->linesize, enc->width)); //WARNING: Square dimensions implied... |
741 #endif | 744 #endif |
742 } | 745 } |
743 | 746 |
744 | 747 |
745 /** | 748 /** |
752 | 755 |
753 for (i=0; i<2; i++) | 756 for (i=0; i<2; i++) |
754 for (j=0; j<2; j++) { | 757 for (j=0; j<2; j++) { |
755 int x = (top+i)*stride[0] + left + j; | 758 int x = (top+i)*stride[0] + left + j; |
756 *block++ = data[0][x]; | 759 *block++ = data[0][x]; |
760 x = (top+i)*stride[1] + left + j; | |
757 u += data[1][x]; | 761 u += data[1][x]; |
758 v += data[2][x]; | 762 v += data[2][x]; |
759 } | 763 } |
760 | 764 |
761 *block++ = (u+2)/4; | 765 *block++ = (u+2)/4; |