You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.3KB

  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 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->y_stride;
  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->c_stride;
  49. bptr = ri->current_frame->data[1] + boffs;
  50. bptr[0 ] =
  51. bptr[1 ] =
  52. bptr[stride ] =
  53. bptr[stride+1] = cell->u;
  54. bptr = ri->current_frame->data[2] + boffs;
  55. bptr[0 ] =
  56. bptr[1 ] =
  57. bptr[stride ] =
  58. bptr[stride+1] = cell->v;
  59. }
  60. void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
  61. {
  62. unsigned char *bptr;
  63. int boffs,stride;
  64. stride = ri->y_stride;
  65. boffs = (y * stride) + x;
  66. bptr = ri->current_frame->data[0] + boffs;
  67. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = cell->y[0];
  68. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = cell->y[1];
  69. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = cell->y[2];
  70. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3];
  71. stride = ri->c_stride;
  72. bptr = ri->current_frame->data[1] + boffs;
  73. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
  74. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
  75. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
  76. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->u;
  77. bptr = ri->current_frame->data[2] + boffs;
  78. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
  79. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
  80. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
  81. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->v;
  82. }
  83. static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
  84. int deltay, int sz)
  85. {
  86. int mx, my, cp;
  87. mx = x + deltax;
  88. my = y + deltay;
  89. /* check MV against frame boundaries */
  90. if ((mx < 0) || (mx > ri->width - sz) ||
  91. (my < 0) || (my > ri->height - sz)) {
  92. av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
  93. mx, my, ri->width, ri->height);
  94. return;
  95. }
  96. for(cp = 0; cp < 3; cp++) {
  97. int stride = ri->current_frame->linesize[cp];
  98. block_copy(ri->current_frame->data[cp] + (y*stride) + x,
  99. ri->last_frame->data[cp] + (my*stride) + mx,
  100. stride, stride, sz);
  101. }
  102. }
  103. void ff_apply_motion_4x4(RoqContext *ri, int x, int y,
  104. int deltax, int deltay)
  105. {
  106. apply_motion_generic(ri, x, y, deltax, deltay, 4);
  107. }
  108. void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
  109. int deltax, int deltay)
  110. {
  111. apply_motion_generic(ri, x, y, deltax, deltay, 8);
  112. }