mp_image.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * This file is part of MPlayer.
  3. *
  4. * MPlayer is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * MPlayer is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with MPlayer; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #ifndef MPLAYER_MP_IMAGE_H
  19. #define MPLAYER_MP_IMAGE_H
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #undef printf //FIXME
  24. #undef fprintf //FIXME
  25. #include "mp_msg.h"
  26. #include "libavutil/avutil.h"
  27. #include "libavutil/avassert.h"
  28. #undef realloc
  29. #undef malloc
  30. #undef free
  31. #undef rand
  32. #undef srand
  33. #undef printf
  34. #undef strncpy
  35. #define ASMALIGN(ZEROBITS) ".p2align " #ZEROBITS "\n\t"
  36. #define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC).
  37. //--------- codec's requirements (filled by the codec/vf) ---------
  38. //--- buffer content restrictions:
  39. // set if buffer content shouldn't be modified:
  40. #define MP_IMGFLAG_PRESERVE 0x01
  41. // set if buffer content will be READ for next frame's MC: (I/P mpeg frames)
  42. #define MP_IMGFLAG_READABLE 0x02
  43. //--- buffer width/stride/plane restrictions: (used for direct rendering)
  44. // stride _have_to_ be aligned to MB boundary: [for DR restrictions]
  45. #define MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE 0x4
  46. // stride should be aligned to MB boundary: [for buffer allocation]
  47. #define MP_IMGFLAG_PREFER_ALIGNED_STRIDE 0x8
  48. // codec accept any stride (>=width):
  49. #define MP_IMGFLAG_ACCEPT_STRIDE 0x10
  50. // codec accept any width (width*bpp=stride -> stride%bpp==0) (>=width):
  51. #define MP_IMGFLAG_ACCEPT_WIDTH 0x20
  52. //--- for planar formats only:
  53. // uses only stride[0], and stride[1]=stride[2]=stride[0]>>mpi->chroma_x_shift
  54. #define MP_IMGFLAG_COMMON_STRIDE 0x40
  55. // uses only planes[0], and calculates planes[1,2] from width,height,imgfmt
  56. #define MP_IMGFLAG_COMMON_PLANE 0x80
  57. #define MP_IMGFLAGMASK_RESTRICTIONS 0xFF
  58. //--------- color info (filled by mp_image_setfmt() ) -----------
  59. // set if number of planes > 1
  60. #define MP_IMGFLAG_PLANAR 0x100
  61. // set if it's YUV colorspace
  62. #define MP_IMGFLAG_YUV 0x200
  63. // set if it's swapped (BGR or YVU) plane/byteorder
  64. #define MP_IMGFLAG_SWAPPED 0x400
  65. // set if you want memory for palette allocated and managed by vf_get_image etc.
  66. #define MP_IMGFLAG_RGB_PALETTE 0x800
  67. #define MP_IMGFLAGMASK_COLORS 0xF00
  68. // codec uses drawing/rendering callbacks (draw_slice()-like thing, DR method 2)
  69. // [the codec will set this flag if it supports callbacks, and the vo _may_
  70. // clear it in get_image() if draw_slice() not implemented]
  71. #define MP_IMGFLAG_DRAW_CALLBACK 0x1000
  72. // set if it's in video buffer/memory: [set by vo/vf's get_image() !!!]
  73. #define MP_IMGFLAG_DIRECT 0x2000
  74. // set if buffer is allocated (used in destination images):
  75. #define MP_IMGFLAG_ALLOCATED 0x4000
  76. // buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!)
  77. #define MP_IMGFLAG_TYPE_DISPLAYED 0x8000
  78. // codec doesn't support any form of direct rendering - it has own buffer
  79. // allocation. so we just export its buffer pointers:
  80. #define MP_IMGTYPE_EXPORT 0
  81. // codec requires a static WO buffer, but it does only partial updates later:
  82. #define MP_IMGTYPE_STATIC 1
  83. // codec just needs some WO memory, where it writes/copies the whole frame to:
  84. #define MP_IMGTYPE_TEMP 2
  85. // I+P type, requires 2+ independent static R/W buffers
  86. #define MP_IMGTYPE_IP 3
  87. // I+P+B type, requires 2+ independent static R/W and 1+ temp WO buffers
  88. #define MP_IMGTYPE_IPB 4
  89. // Upper 16 bits give desired buffer number, -1 means get next available
  90. #define MP_IMGTYPE_NUMBERED 5
  91. // Doesn't need any buffer, incomplete image (probably a first field only)
  92. // we need this type to be able to differentiate between half frames and
  93. // all other cases
  94. #define MP_IMGTYPE_INCOMPLETE 6
  95. #define MP_MAX_PLANES 4
  96. #define MP_IMGFIELD_ORDERED 0x01
  97. #define MP_IMGFIELD_TOP_FIRST 0x02
  98. #define MP_IMGFIELD_REPEAT_FIRST 0x04
  99. #define MP_IMGFIELD_TOP 0x08
  100. #define MP_IMGFIELD_BOTTOM 0x10
  101. #define MP_IMGFIELD_INTERLACED 0x20
  102. typedef struct mp_image {
  103. unsigned int flags;
  104. unsigned char type;
  105. int number;
  106. unsigned char bpp; // bits/pixel. NOT depth! for RGB it will be n*8
  107. unsigned int imgfmt;
  108. int width,height; // stored dimensions
  109. int x,y,w,h; // visible dimensions
  110. unsigned char* planes[MP_MAX_PLANES];
  111. int stride[MP_MAX_PLANES];
  112. char * qscale;
  113. int qstride;
  114. int pict_type; // 0->unknown, 1->I, 2->P, 3->B
  115. int fields;
  116. int qscale_type; // 0->mpeg1/4/h263, 1->mpeg2
  117. int num_planes;
  118. /* these are only used by planar formats Y,U(Cb),V(Cr) */
  119. int chroma_width;
  120. int chroma_height;
  121. int chroma_x_shift; // horizontal
  122. int chroma_y_shift; // vertical
  123. int usage_count;
  124. /* for private use by filter or vo driver (to store buffer id or dmpi) */
  125. void* priv;
  126. } mp_image_t;
  127. void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt);
  128. mp_image_t* new_mp_image(int w,int h);
  129. void free_mp_image(mp_image_t* mpi);
  130. mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt);
  131. void mp_image_alloc_planes(mp_image_t *mpi);
  132. void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi);
  133. #endif /* MPLAYER_MP_IMAGE_H */