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.

130 lines
4.2KB

  1. /*
  2. * Copyright (C) 2003 the ffmpeg project
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  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. bptr = ri->current_frame->data[1] + boffs;
  49. bptr[0 ] =
  50. bptr[1 ] =
  51. bptr[stride ] =
  52. bptr[stride+1] = cell->u;
  53. bptr = ri->current_frame->data[2] + boffs;
  54. bptr[0 ] =
  55. bptr[1 ] =
  56. bptr[stride ] =
  57. bptr[stride+1] = cell->v;
  58. }
  59. void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell)
  60. {
  61. unsigned char *bptr;
  62. int boffs,stride;
  63. stride = ri->y_stride;
  64. boffs = (y * stride) + x;
  65. bptr = ri->current_frame->data[0] + boffs;
  66. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = cell->y[0];
  67. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = cell->y[1];
  68. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = cell->y[2];
  69. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3];
  70. bptr = ri->current_frame->data[1] + boffs;
  71. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
  72. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
  73. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
  74. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->u;
  75. bptr = ri->current_frame->data[2] + boffs;
  76. bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] =
  77. bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] =
  78. bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] =
  79. bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->v;
  80. }
  81. static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax,
  82. int deltay, int sz)
  83. {
  84. int mx, my, cp;
  85. mx = x + deltax;
  86. my = y + deltay;
  87. /* check MV against frame boundaries */
  88. if ((mx < 0) || (mx > ri->avctx->width - sz) ||
  89. (my < 0) || (my > ri->avctx->height - sz)) {
  90. av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n",
  91. mx, my, ri->avctx->width, ri->avctx->height);
  92. return;
  93. }
  94. for(cp = 0; cp < 3; cp++)
  95. block_copy(ri->current_frame->data[cp] + (y * ri->y_stride) + x,
  96. ri->last_frame->data[cp] + (my * ri->y_stride) + mx,
  97. ri->y_stride, ri->y_stride, sz);
  98. }
  99. void ff_apply_motion_4x4(RoqContext *ri, int x, int y,
  100. int deltax, int deltay)
  101. {
  102. apply_motion_generic(ri, x, y, deltax, deltay, 4);
  103. }
  104. void ff_apply_motion_8x8(RoqContext *ri, int x, int y,
  105. int deltax, int deltay)
  106. {
  107. apply_motion_generic(ri, x, y, deltax, deltay, 8);
  108. }