roqvideo.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (C) 2003 Mike Melanson
  3. * Copyright (C) 2003 Dr. Tim Ferguson
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file libavcodec/roqvideo.c
  23. * id RoQ Video common functions based on work by Dr. Tim Ferguson
  24. */
  25. #include "avcodec.h"
  26. #include "roqvideo.h"
  27. static inline void block_copy(unsigned char *out, unsigned char *in,
  28. int outstride, int instride, int sz)
  29. {
  30. int rows = sz;
  31. while(rows--) {
  32. memcpy(out, in, sz);
  33. out += outstride;
  34. in += instride;
  35. }
  36. }
  37. void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell)
  38. {
  39. unsigned char *bptr;
  40. int boffs,stride;
  41. stride = ri->current_frame->linesize[0];
  42. boffs = y*stride + x;
  43. bptr = ri->current_frame->data[0] + boffs;
  44. bptr[0 ] = cell->y[0];
  45. bptr[1 ] = cell->y[1];
  46. bptr[stride ] = cell->y[2];
  47. bptr[stride+1] = cell->y[3];
  48. stride = ri->current_frame->linesize[1];
  49. boffs = y*stride + x;
  50. bptr = ri->current_frame->data[1] + boffs;
  51. bptr[0 ] =
  52. bptr[1 ] =
  53. bptr[stride ] =
  54. bptr[stride+1] = cell->u;
  55. bptr = ri->current_frame->data[2] + boffs;
  56. bptr[0 ] =
  57. bptr[1 ] =
  58. bptr[stride ] =
  59. bptr[stride+1] = cell->v;
  60. }
  61. void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
  62. {
  63. unsigned char *bptr;
  64. int boffs,stride;
  65. stride = ri->current_frame->linesize[0];
  66. boffs = y*stride + x;
  67. bptr = ri->current_frame->data[0] + boffs;
  68. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = cell->y[0];
  69. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = cell->y[1];
  70. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = cell->y[2];
  71. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3];
  72. stride = ri->current_frame->linesize[1];
  73. boffs = y*stride + x;
  74. bptr = ri->current_frame->data[1] + boffs;
  75. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
  76. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
  77. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
  78. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->u;
  79. bptr = ri->current_frame->data[2] + boffs;
  80. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
  81. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
  82. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
  83. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->v;
  84. }
  85. static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
  86. int deltay, int sz)
  87. {
  88. int mx, my, cp;
  89. mx = x + deltax;
  90. my = y + deltay;
  91. /* check MV against frame boundaries */
  92. if ((mx < 0) || (mx > ri->width - sz) ||
  93. (my < 0) || (my > ri->height - sz)) {
  94. av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
  95. mx, my, ri->width, ri->height);
  96. return;
  97. }
  98. for(cp = 0; cp < 3; cp++) {
  99. int outstride = ri->current_frame->linesize[cp];
  100. int instride = ri->last_frame ->linesize[cp];
  101. block_copy(ri->current_frame->data[cp] + y*outstride + x,
  102. ri->last_frame->data[cp] + my*instride + mx,
  103. outstride, instride, sz);
  104. }
  105. }
  106. void ff_apply_motion_4x4(RoqContext *ri, int x, int y,
  107. int deltax, int deltay)
  108. {
  109. apply_motion_generic(ri, x, y, deltax, deltay, 4);
  110. }
  111. void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
  112. int deltax, int deltay)
  113. {
  114. apply_motion_generic(ri, x, y, deltax, deltay, 8);
  115. }