digiKam
image.h
Go to the documentation of this file.
1 /*
2  * H.265 video codec.
3  * Copyright (c) 2013-2014 struktur AG, Dirk Farin <farin@struktur.de>
4  *
5  * This file is part of libde265.
6  *
7  * libde265 is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * libde265 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
15  * GNU Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with libde265. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef DE265_IMAGE_H
22 #define DE265_IMAGE_H
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include <assert.h>
29 #include <stdint.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <memory>
33 #ifdef HAVE_STDBOOL_H
34 #include <stdbool.h>
35 #endif
36 
37 #include "libde265/de265.h"
38 #include "libde265/sps.h"
39 #include "libde265/pps.h"
40 #include "libde265/motion.h"
41 #include "libde265/threads.h"
42 #include "libde265/slice.h"
43 #include "libde265/nal.h"
44 
45 struct en265_encoder_context;
46 
51 };
52 
53 
54 /* TODO:
55  At INTEGRITY_DERIVED_FROM_FAULTY_REFERENCE images, we can check the SEI hash, whether
56  the output image is correct despite the faulty reference, and set the state back to correct.
57 */
58 #define INTEGRITY_CORRECT 0
59 #define INTEGRITY_UNAVAILABLE_REFERENCE 1
60 #define INTEGRITY_NOT_DECODED 2
61 #define INTEGRITY_DECODING_ERRORS 3
62 #define INTEGRITY_DERIVED_FROM_FAULTY_REFERENCE 4
63 
64 #define SEI_HASH_UNCHECKED 0
65 #define SEI_HASH_CORRECT 1
66 #define SEI_HASH_INCORRECT 2
67 
68 #define TU_FLAG_NONZERO_COEFF (1<<7)
69 #define TU_FLAG_SPLIT_TRANSFORM_MASK 0x1F
70 
71 #define DEBLOCK_FLAG_VERTI (1<<4)
72 #define DEBLOCK_FLAG_HORIZ (1<<5)
73 #define DEBLOCK_PB_EDGE_VERTI (1<<6)
74 #define DEBLOCK_PB_EDGE_HORIZ (1<<7)
75 #define DEBLOCK_BS_MASK 0x03
76 
77 
78 #define CTB_PROGRESS_NONE 0
79 #define CTB_PROGRESS_PREFILTER 1
80 #define CTB_PROGRESS_DEBLK_V 2
81 #define CTB_PROGRESS_DEBLK_H 3
82 #define CTB_PROGRESS_SAO 4
83 
84 class decoder_context;
85 
86 template <class DataUnit> class MetaDataArray
87 {
88  public:
90  ~MetaDataArray() { free(data); }
91 
92  LIBDE265_CHECK_RESULT bool alloc(int w,int h, int _log2unitSize) {
93  int size = w*h;
94 
95  if (size != data_size) {
96  free(data);
97  data = (DataUnit*)malloc(size * sizeof(DataUnit));
98  if (data == NULL) {
99  data_size = 0;
100  return false;
101  }
102  data_size = size;
103  }
104 
105  width_in_units = w;
106  height_in_units = h;
107 
108  log2unitSize = _log2unitSize;
109 
110  return data != NULL;
111  }
112 
113  void clear() {
114  if (data) memset(data, 0, sizeof(DataUnit) * data_size);
115  }
116 
117  const DataUnit& get(int x,int y) const {
118  int unitX = x>>log2unitSize;
119  int unitY = y>>log2unitSize;
120 
121  assert(unitX >= 0 && unitX < width_in_units);
122  assert(unitY >= 0 && unitY < height_in_units);
123 
124  return data[ unitX + unitY*width_in_units ];
125  }
126 
127  DataUnit& get(int x,int y) {
128  int unitX = x>>log2unitSize;
129  int unitY = y>>log2unitSize;
130 
131  assert(unitX >= 0 && unitX < width_in_units);
132  assert(unitY >= 0 && unitY < height_in_units);
133 
134  return data[ unitX + unitY*width_in_units ];
135  }
136 
137  void set(int x,int y, const DataUnit& d) {
138  int unitX = x>>log2unitSize;
139  int unitY = y>>log2unitSize;
140 
141  assert(unitX >= 0 && unitX < width_in_units);
142  assert(unitY >= 0 && unitY < height_in_units);
143 
144  data[ unitX + unitY*width_in_units ] = d;
145  }
146 
147  DataUnit& operator[](int idx) { return data[idx]; }
148  const DataUnit& operator[](int idx) const { return data[idx]; }
149 
150  int size() const { return data_size; }
151 
152  // private:
153  DataUnit* data;
158 };
159 
160 #define SET_CB_BLK(x,y,log2BlkWidth, Field,value) \
161  int cbX = x >> cb_info.log2unitSize; \
162  int cbY = y >> cb_info.log2unitSize; \
163  int width = 1 << (log2BlkWidth - cb_info.log2unitSize); \
164  for (int cby=cbY;cby<cbY+width;cby++) \
165  for (int cbx=cbX;cbx<cbX+width;cbx++) \
166  { \
167  cb_info[ cbx + cby*cb_info.width_in_units ].Field = value; \
168  }
169 
170 #define CLEAR_TB_BLK(x,y,log2BlkWidth) \
171  int tuX = x >> tu_info.log2unitSize; \
172  int tuY = y >> tu_info.log2unitSize; \
173  int width = 1 << (log2BlkWidth - tu_info.log2unitSize); \
174  for (int tuy=tuY;tuy<tuY+width;tuy++) \
175  for (int tux=tuX;tux<tuX+width;tux++) \
176  { \
177  tu_info[ tux + tuy*tu_info.width_in_units ] = 0; \
178  }
179 
180 
181 typedef struct {
182  uint16_t SliceAddrRS;
183  uint16_t SliceHeaderIndex; // index into array to slice header for this CTB
184 
186  bool deblock; // this CTB has to be deblocked
187 
188  // The following flag helps to quickly check whether we have to
189  // check all conditions in the SAO filter or whether we can skip them.
190  bool has_pcm_or_cu_transquant_bypass; // pcm or transquant_bypass is used in this CTB
191 } CTB_info;
192 
193 
194 typedef struct {
195  uint8_t log2CbSize : 3; /* [0;6] (1<<log2CbSize) = 64
196  This is only set in the top-left corner of the CB.
197  The other values should be zero.
198  TODO: in the encoder, we have to clear to zero.
199  Used in deblocking and QP-scale decoding */
200  uint8_t PartMode : 3; // (enum PartMode) [0;7] set only in top-left of CB
201  // Used for spatial merging candidates in current frame
202  // and for deriving interSplitFlag in decoding.
203 
204  uint8_t ctDepth : 2; // [0:3]? (for CTB size 64: 0:64, 1:32, 2:16, 3:8)
205  // Used for decoding/encoding split_cu flag.
206 
207  // --- byte boundary ---
208  uint8_t PredMode : 2; // (enum PredMode) [0;2] must be saved for past images
209  // Used in motion decoding.
210  uint8_t pcm_flag : 1; // Stored for intra-prediction / SAO
211  uint8_t cu_transquant_bypass : 1; // Stored for SAO
212  // note: 4 bits left
213 
214  // --- byte boundary ---
215  int8_t QP_Y; // Stored for QP prediction
216 
217 } CB_ref_info;
218 
219 
220 
221 
222 struct de265_image {
225 
226 
227  de265_error alloc_image(int w,int h, enum de265_chroma c,
228  std::shared_ptr<const seq_parameter_set> sps,
229  bool allocMetadata,
230  decoder_context* dctx,
231  //class encoder_context* ectx,
232  de265_PTS pts, void* user_data,
233  bool useCustomAllocFunctions);
234 
235  //de265_error alloc_encoder_data(const seq_parameter_set* sps);
236 
237  bool is_allocated() const { return pixels[0] != NULL; }
238 
239  void release();
240 
241  void set_headers(std::shared_ptr<video_parameter_set> _vps,
242  std::shared_ptr<seq_parameter_set> _sps,
243  std::shared_ptr<pic_parameter_set> _pps) {
244  vps = _vps;
245  sps = _sps;
246  pps = _pps;
247  }
248 
249  void fill_image(int y,int u,int v);
251  void copy_lines_from(const de265_image* src, int first, int end);
253 
254  uint32_t get_ID() const { return ID; }
255 
256 
257  /* */ uint8_t* get_image_plane(int cIdx) { return pixels[cIdx]; }
258  const uint8_t* get_image_plane(int cIdx) const { return pixels[cIdx]; }
259 
260  void set_image_plane(int cIdx, uint8_t* mem, int stride, void *userdata);
261 
262  uint8_t* get_image_plane_at_pos(int cIdx, int xpos,int ypos)
263  {
264  int stride = get_image_stride(cIdx);
265  return pixels[cIdx] + xpos + ypos*stride;
266  }
267 
268 
270  template <class pixel_t>
271  pixel_t* get_image_plane_at_pos_NEW(int cIdx, int xpos,int ypos)
272  {
273  int stride = get_image_stride(cIdx);
274  return (pixel_t*)(pixels[cIdx] + (xpos + ypos*stride)*sizeof(pixel_t));
275  }
276 
277  const uint8_t* get_image_plane_at_pos(int cIdx, int xpos,int ypos) const
278  {
279  int stride = get_image_stride(cIdx);
280  return pixels[cIdx] + xpos + ypos*stride;
281  }
282 
283  void* get_image_plane_at_pos_any_depth(int cIdx, int xpos,int ypos)
284  {
285  int stride = get_image_stride(cIdx);
286  return pixels[cIdx] + ((xpos + ypos*stride) << bpp_shift[cIdx]);
287  }
288 
289  const void* get_image_plane_at_pos_any_depth(int cIdx, int xpos,int ypos) const
290  {
291  int stride = get_image_stride(cIdx);
292  return pixels[cIdx] + ((xpos + ypos*stride) << bpp_shift[cIdx]);
293  }
294 
295  /* Number of pixels in one row (not number of bytes).
296  */
297  int get_image_stride(int cIdx) const
298  {
299  if (cIdx==0) return stride;
300  else return chroma_stride;
301  }
302 
303  int get_luma_stride() const { return stride; }
304  int get_chroma_stride() const { return chroma_stride; }
305 
306  int get_width (int cIdx=0) const { return cIdx==0 ? width : chroma_width; }
307  int get_height(int cIdx=0) const { return cIdx==0 ? height : chroma_height; }
308 
309  enum de265_chroma get_chroma_format() const { return chroma_format; }
310 
311  int get_bit_depth(int cIdx) const {
312  if (cIdx==0) return sps->BitDepth_Y;
313  else return sps->BitDepth_C;
314  }
315 
316  int get_bytes_per_pixel(int cIdx) const {
317  return (get_bit_depth(cIdx)+7)/8;
318  }
319 
320  bool high_bit_depth(int cIdx) const {
321  return get_bit_depth(cIdx)>8;
322  }
323 
324  bool can_be_released() const { return PicOutputFlag==false && PicState==UnusedForReference; }
325 
326 
328  shdr->slice_index = slices.size();
329  slices.push_back(shdr);
330  }
331 
332 
333  bool available_zscan(int xCurr,int yCurr, int xN,int yN) const;
334 
335  bool available_pred_blk(int xC,int yC, int nCbS,
336  int xP, int yP, int nPbW, int nPbH, int partIdx,
337  int xN,int yN) const;
338 
339 
341 
342  void printBlk(const char* title, int x0,int y0,int blkSize,int cIdx) const {
343  ::printBlk(title, get_image_plane_at_pos(cIdx,x0,y0),
344  blkSize, get_image_stride(cIdx));
345  }
346 
347 private:
348  uint32_t ID;
349  static uint32_t s_next_image_ID;
350 
351  uint8_t* pixels[3];
352  uint8_t bpp_shift[3]; // 0 for 8 bit, 1 for 16 bit
353 
354  enum de265_chroma chroma_format;
355 
356  int width, height; // size in luma pixels
357 
358  int chroma_width, chroma_height;
359  int stride, chroma_stride;
360 
361 public:
364  std::vector<slice_segment_header*> slices;
365 
366 public:
367 
368  // --- conformance cropping window ---
369 
370  uint8_t* pixels_confwin[3]; // pointer to pixels in the conformance window
371 
374 
375  // --- decoding info ---
376 
377  // If PicOutputFlag==false && PicState==UnusedForReference, image buffer is free.
378 
381  enum PictureState PicState;
383 
385 
386  const video_parameter_set& get_vps() const { return *vps; }
387  const seq_parameter_set& get_sps() const { return *sps; }
388  const pic_parameter_set& get_pps() const { return *pps; }
389 
390  bool has_vps() const { return (bool)vps; }
391  bool has_sps() const { return (bool)sps; }
392  bool has_pps() const { return (bool)pps; }
393 
394  std::shared_ptr<const seq_parameter_set> get_shared_sps() { return sps; }
395 
396  //std::shared_ptr<const seq_parameter_set> get_shared_sps() const { return sps; }
397  //std::shared_ptr<const pic_parameter_set> get_shared_pps() const { return pps; }
398 
400  //class encoder_context* encctx;
401 
402  int number_of_ctbs() const { return ctb_info.size(); }
403 
404 private:
405  // The image also keeps a reference to VPS/SPS/PPS, because when decoding is delayed,
406  // the currently active parameter sets in the decctx might already have been replaced
407  // with new parameters.
408  std::shared_ptr<const video_parameter_set> vps;
409  std::shared_ptr<const seq_parameter_set> sps; // the SPS used for decoding this image
410  std::shared_ptr<const pic_parameter_set> pps; // the PPS used for decoding this image
411 
412  MetaDataArray<CTB_info> ctb_info;
414  MetaDataArray<PBMotion> pb_info;
415  MetaDataArray<uint8_t> intraPredMode;
416  MetaDataArray<uint8_t> intraPredModeC;
417  MetaDataArray<uint8_t> tu_info;
418  MetaDataArray<uint8_t> deblk_info;
419 
420 public:
421  // --- meta information ---
422 
424  void* user_data;
425  void* plane_user_data[3]; // this is logically attached to the pixel data pointers
426  de265_image_allocation image_allocation_functions; // the functions used for memory allocation
427 
428  /*
429  void (*encoder_image_release_func)(en265_encoder_context*,
430  de265_image*,
431  void* userdata);
432  */
433 
434  uint8_t integrity; /* Whether an error occured while the image was decoded.
435  When generated, this is initialized to INTEGRITY_CORRECT,
436  and changed on decoding errors.
437  */
439 
441 
442  // --- multi core ---
443 
445 
446  void mark_all_CTB_progress(int progress) {
447  for (int i=0;i<ctb_info.data_size;i++) {
448  ctb_progress[i].set_progress(progress);
449  }
450  }
451 
452 
453  void thread_start(int nThreads);
454  void thread_run(const thread_task*);
457  /* NOTE: you should not access any data in the thread_task after
458  calling this, as this function may unlock other threads that
459  will push this image to the output queue and free all decoder data. */
461 
462  void wait_for_progress(thread_task* task, int ctbx,int ctby, int progress);
463  void wait_for_progress(thread_task* task, int ctbAddrRS, int progress);
464 
465  void wait_for_completion(); // block until image is decoded by background threads
466  bool debug_is_completed() const;
467  int num_threads_active() const { return nThreadsRunning + nThreadsBlocked; } // for debug only
468 
469  //private:
475 
476  // ALIGNED_8(de265_sync_int tasks_pending); // number of tasks pending to complete decoding
479 
480 public:
481 
482  /* Clear all CTB/CB/PB decoding data of this image.
483  All CTB's processing states are set to 'unprocessed'.
484  */
486 
487 
488  // --- CB metadata access ---
489 
490  void set_pred_mode(int x,int y, int log2BlkWidth, enum PredMode mode)
491  {
492  SET_CB_BLK(x,y,log2BlkWidth, PredMode, mode);
493  }
494 
495  void fill_pred_mode(enum PredMode mode)
496  {
497  for (int i=0;i<cb_info.data_size;i++)
498  { cb_info[i].PredMode = MODE_INTRA; }
499  }
500 
501  enum PredMode get_pred_mode(int x,int y) const
502  {
503  return (enum PredMode)cb_info.get(x,y).PredMode;
504  }
505 
506  uint8_t get_cu_skip_flag(int x,int y) const
507  {
508  return get_pred_mode(x,y)==MODE_SKIP;
509  }
510 
511  void set_pcm_flag(int x,int y, int log2BlkWidth, uint8_t value=1)
512  {
513  SET_CB_BLK(x,y,log2BlkWidth, pcm_flag, value);
514 
515  // TODO: in the encoder, we somewhere have to clear this
516  ctb_info.get(x,y).has_pcm_or_cu_transquant_bypass = true;
517  }
518 
519  int get_pcm_flag(int x,int y) const
520  {
521  return cb_info.get(x,y).pcm_flag;
522  }
523 
524  void set_cu_transquant_bypass(int x,int y, int log2BlkWidth, uint8_t value=1)
525  {
526  SET_CB_BLK(x,y,log2BlkWidth, cu_transquant_bypass, value);
527 
528  // TODO: in the encoder, we somewhere have to clear this
529  ctb_info.get(x,y).has_pcm_or_cu_transquant_bypass = true;
530  }
531 
532  int get_cu_transquant_bypass(int x,int y) const
533  {
534  return cb_info.get(x,y).cu_transquant_bypass;
535  }
536 
537  void set_log2CbSize(int x0, int y0, int log2CbSize, bool fill)
538  {
539  // In theory, we could assume that remaining cb_info blocks are initialized to zero.
540  // But in corrupted streams, slices may overlap and set contradicting log2CbSizes.
541  // We also need this for encoding.
542  if (fill) {
543  SET_CB_BLK(x0,y0,log2CbSize, log2CbSize, 0);
544  }
545 
546  cb_info.get(x0,y0).log2CbSize = log2CbSize;
547  }
548 
549  int get_log2CbSize(int x0, int y0) const
550  {
551  return (enum PredMode)cb_info.get(x0,y0).log2CbSize;
552  }
553 
554  // coordinates in CB units
555  int get_log2CbSize_cbUnits(int xCb, int yCb) const
556  {
557  return (enum PredMode)cb_info[ xCb + yCb*cb_info.width_in_units ].log2CbSize;
558  }
559 
560  void set_PartMode(int x,int y, enum PartMode mode)
561  {
562  cb_info.get(x,y).PartMode = mode;
563  }
564 
565  enum PartMode get_PartMode(int x,int y) const
566  {
567  return (enum PartMode)cb_info.get(x,y).PartMode;
568  }
569 
570  void set_ctDepth(int x,int y, int log2BlkWidth, int depth)
571  {
572  SET_CB_BLK(x,y,log2BlkWidth, ctDepth, depth);
573  }
574 
575  int get_ctDepth(int x,int y) const
576  {
577  return cb_info.get(x,y).ctDepth;
578  }
579 
580  void set_QPY(int x,int y, int log2BlkWidth, int QP_Y)
581  {
582  SET_CB_BLK (x, y, log2BlkWidth, QP_Y, QP_Y);
583  }
584 
585  int get_QPY(int x0,int y0) const
586  {
587  return cb_info.get(x0,y0).QP_Y;
588  }
589 
590  // --- TU metadata access ---
591 
592  void set_split_transform_flag(int x0,int y0,int trafoDepth)
593  {
594  tu_info.get(x0,y0) |= (1<<trafoDepth);
595  }
596 
597  void clear_split_transform_flags(int x0,int y0,int log2CbSize)
598  {
599  CLEAR_TB_BLK (x0,y0, log2CbSize);
600  }
601 
602  int get_split_transform_flag(int x0,int y0,int trafoDepth) const
603  {
604  return (tu_info.get(x0,y0) & (1<<trafoDepth));
605  }
606 
607  void set_nonzero_coefficient(int x,int y, int log2TrafoSize)
608  {
609  const int tuX = x >> tu_info.log2unitSize;
610  const int tuY = y >> tu_info.log2unitSize;
611  const int width = 1 << (log2TrafoSize - tu_info.log2unitSize);
612 
613  for (int tuy=tuY;tuy<tuY+width;tuy++)
614  for (int tux=tuX;tux<tuX+width;tux++)
615  {
616  tu_info[ tux + tuy*tu_info.width_in_units ] |= TU_FLAG_NONZERO_COEFF;
617  }
618  }
619 
620  int get_nonzero_coefficient(int x,int y) const
621  {
622  return tu_info.get(x,y) & TU_FLAG_NONZERO_COEFF;
623  }
624 
625 
626  // --- intraPredMode metadata access ---
627 
628  enum IntraPredMode get_IntraPredMode(int x,int y) const
629  {
630  return (enum IntraPredMode)intraPredMode.get(x,y);
631  }
632 
633  enum IntraPredMode get_IntraPredMode_atIndex(int idx) const
634  {
635  return (enum IntraPredMode)intraPredMode[idx];
636  }
637 
638  void set_IntraPredMode(int PUidx,int log2blkSize, enum IntraPredMode mode)
639  {
640  int pbSize = 1<<(log2blkSize - intraPredMode.log2unitSize);
641 
642  for (int y=0;y<pbSize;y++)
643  for (int x=0;x<pbSize;x++)
644  intraPredMode[PUidx + x + y*intraPredMode.width_in_units] = mode;
645  }
646 
647  void set_IntraPredMode(int x0,int y0,int log2blkSize,
648  enum IntraPredMode mode)
649  {
650  int pbSize = 1<<(log2blkSize - intraPredMode.log2unitSize);
651  int PUidx = (x0>>sps->Log2MinPUSize) + (y0>>sps->Log2MinPUSize)*sps->PicWidthInMinPUs;
652 
653  for (int y=0;y<pbSize;y++)
654  for (int x=0;x<pbSize;x++) {
655  assert(x < sps->PicWidthInMinPUs);
656  assert(y < sps->PicHeightInMinPUs);
657 
658  int idx = PUidx + x + y*intraPredMode.width_in_units;
659  assert(idx<intraPredMode.data_size);
660  intraPredMode[idx] = mode;
661  }
662  }
663 
664 
665  enum IntraPredMode get_IntraPredModeC(int x,int y) const
666  {
667  return (enum IntraPredMode)(intraPredModeC.get(x,y) & 0x3f);
668  }
669 
670  bool is_IntraPredModeC_Mode4(int x,int y) const
671  {
672  return intraPredModeC.get(x,y) & 0x80;
673  }
674 
675  void set_IntraPredModeC(int x0,int y0,int log2blkSize, enum IntraPredMode mode,
676  bool is_mode4)
677  {
678  uint8_t combinedValue = mode;
679  if (is_mode4) combinedValue |= 0x80;
680 
681  int pbSize = 1<<(log2blkSize - intraPredMode.log2unitSize);
682  int PUidx = (x0>>sps->Log2MinPUSize) + (y0>>sps->Log2MinPUSize)*sps->PicWidthInMinPUs;
683 
684  for (int y=0;y<pbSize;y++)
685  for (int x=0;x<pbSize;x++) {
686  assert(x<sps->PicWidthInMinPUs);
687  assert(y<sps->PicHeightInMinPUs);
688 
689  int idx = PUidx + x + y*intraPredModeC.width_in_units;
690  assert(idx<intraPredModeC.data_size);
691  intraPredModeC[idx] = combinedValue;
692  }
693  }
694 
695 
696  /*
697  // NOTE: encoder only
698  void set_ChromaIntraPredMode(int x,int y,int log2BlkWidth, enum IntraChromaPredMode mode)
699  {
700  SET_CB_BLK (x, y, log2BlkWidth, intra_chroma_pred_mode, mode);
701  }
702 
703  // NOTE: encoder only
704  enum IntraChromaPredMode get_ChromaIntraPredMode(int x,int y) const
705  {
706  return (enum IntraChromaPredMode)(cb_info.get(x,y).intra_chroma_pred_mode);
707  }
708  */
709 
710  // --- CTB metadata access ---
711 
712  // address of first CTB in slice
713  void set_SliceAddrRS(int ctbX, int ctbY, int SliceAddrRS)
714  {
715  int idx = ctbX + ctbY*ctb_info.width_in_units;
716  ctb_info[idx].SliceAddrRS = SliceAddrRS;
717  }
718 
719  int get_SliceAddrRS(int ctbX, int ctbY) const
720  {
721  return ctb_info[ctbX + ctbY*ctb_info.width_in_units].SliceAddrRS;
722  }
723 
724  int get_SliceAddrRS_atCtbRS(int ctbRS) const
725  {
726  return ctb_info[ctbRS].SliceAddrRS;
727  }
728 
729 
730  void set_SliceHeaderIndex(int x, int y, int SliceHeaderIndex)
731  {
732  ctb_info.get(x,y).SliceHeaderIndex = SliceHeaderIndex;
733  }
734 
735  int get_SliceHeaderIndex(int x, int y) const
736  {
737  return ctb_info.get(x,y).SliceHeaderIndex;
738  }
739 
740  int get_SliceHeaderIndexCtb(int ctbX, int ctbY) const
741  {
742  return ctb_info[ctbX + ctbY*ctb_info.width_in_units].SliceHeaderIndex;
743  }
744 
745  int get_SliceHeaderIndex_atIndex(int ctb) const
746  {
747  return ctb_info[ctb].SliceHeaderIndex;
748  }
749 
750  bool is_SliceHeader_available(int x,int y) const
751  {
752  int idx = ctb_info.get(x,y).SliceHeaderIndex;
753  return idx >= 0 && idx < slices.size();
754  }
755 
757  {
758  int idx = get_SliceHeaderIndex(x,y);
759  if (idx >= slices.size()) { return NULL; }
760  return slices[idx];
761  }
762 
764  {
765  int idx = get_SliceHeaderIndexCtb(ctbX,ctbY);
766  if (idx >= slices.size()) { return NULL; }
767  return slices[idx];
768  }
769 
770  const slice_segment_header* get_SliceHeaderCtb(int ctbX, int ctbY) const
771  {
772  int idx = get_SliceHeaderIndexCtb(ctbX,ctbY);
773  if (idx >= slices.size()) { return NULL; }
774  return slices[idx];
775  }
776 
777  void set_sao_info(int ctbX,int ctbY,const sao_info* saoinfo)
778  {
779  sao_info* sao = &ctb_info[ctbX + ctbY*ctb_info.width_in_units].saoInfo;
780 
781  memcpy(sao,
782  saoinfo,
783  sizeof(sao_info));
784  }
785 
786  const sao_info* get_sao_info(int ctbX,int ctbY) const
787  {
788  return &ctb_info[ctbX + ctbY*ctb_info.width_in_units].saoInfo;
789  }
790 
791 
792  void set_CtbDeblockFlag(int ctbX, int ctbY, bool flag)
793  {
794  int idx = ctbX + ctbY*ctb_info.width_in_units;
795  ctb_info[idx].deblock = flag;
796  }
797 
798  bool get_CtbDeblockFlag(int ctbX, int ctbY) const
799  {
800  return ctb_info[ctbX + ctbY*ctb_info.width_in_units].deblock;
801  }
802 
803 
804  bool get_CTB_has_pcm_or_cu_transquant_bypass(int ctbX,int ctbY) const
805  {
806  int idx = ctbX + ctbY*ctb_info.width_in_units;
807  return ctb_info[idx].has_pcm_or_cu_transquant_bypass;
808  }
809 
810 
811 
812  // --- DEBLK metadata access ---
813 
814  int get_deblk_width() const { return deblk_info.width_in_units; }
815  int get_deblk_height() const { return deblk_info.height_in_units; }
816 
817  void set_deblk_flags(int x0,int y0, uint8_t flags)
818  {
819  const int xd = x0/4;
820  const int yd = y0/4;
821 
822  if (xd<deblk_info.width_in_units &&
823  yd<deblk_info.height_in_units) {
824  deblk_info[xd + yd*deblk_info.width_in_units] |= flags;
825  }
826  }
827 
828  uint8_t get_deblk_flags(int x0,int y0) const
829  {
830  const int xd = x0/4;
831  const int yd = y0/4;
832 
833  return deblk_info[xd + yd*deblk_info.width_in_units];
834  }
835 
836  void set_deblk_bS(int x0,int y0, uint8_t bS)
837  {
838  uint8_t* data = &deblk_info[x0/4 + y0/4*deblk_info.width_in_units];
839  *data &= ~DEBLOCK_BS_MASK;
840  *data |= bS;
841  }
842 
843  uint8_t get_deblk_bS(int x0,int y0) const
844  {
845  return deblk_info[x0/4 + y0/4*deblk_info.width_in_units] & DEBLOCK_BS_MASK;
846  }
847 
848 
849  // --- PB metadata access ---
850 
851  const PBMotion& get_mv_info(int x,int y) const
852  {
853  return pb_info.get(x,y);
854  }
855 
856  void set_mv_info(int x,int y, int nPbW,int nPbH, const PBMotion& mv);
857 
858  // --- value logging ---
859 
860  void printBlk(int x0,int y0, int cIdx, int log2BlkSize);
861 };
862 
863 
864 #endif
Definition: image.h:87
MetaDataArray()
Definition: image.h:89
const DataUnit & operator[](int idx) const
Definition: image.h:148
void set(int x, int y, const DataUnit &d)
Definition: image.h:137
DataUnit & get(int x, int y)
Definition: image.h:127
DataUnit & operator[](int idx)
Definition: image.h:147
int log2unitSize
Definition: image.h:155
int height_in_units
Definition: image.h:157
const DataUnit & get(int x, int y) const
Definition: image.h:117
int width_in_units
Definition: image.h:156
int data_size
Definition: image.h:154
LIBDE265_CHECK_RESULT bool alloc(int w, int h, int _log2unitSize)
Definition: image.h:92
int size() const
Definition: image.h:150
DataUnit * data
Definition: image.h:153
~MetaDataArray()
Definition: image.h:90
void clear()
Definition: image.h:113
Definition: motion.h:38
Definition: threads.h:79
void set_progress(int progress)
Definition: decctx.h:291
Definition: pps.h:59
Definition: sps.h:86
Definition: slice.h:130
int slice_index
Definition: slice.h:148
Definition: threads.h:102
Definition: vps.h:130
int64_t de265_PTS
Definition: de265.h:166
de265_chroma
Definition: de265.h:159
de265_error
Definition: de265.h:82
PictureState
Definition: image.h:47
@ UnusedForReference
Definition: image.h:48
@ UsedForLongTermReference
Definition: image.h:50
@ UsedForShortTermReference
Definition: image.h:49
#define TU_FLAG_NONZERO_COEFF
Definition: image.h:68
#define DEBLOCK_BS_MASK
Definition: image.h:75
#define CLEAR_TB_BLK(x, y, log2BlkWidth)
Definition: image.h:170
#define SET_CB_BLK(x, y, log2BlkWidth, Field, value)
Definition: image.h:160
qulonglong value
Definition: itemviewutilities.cpp:592
PredMode
Definition: slice.h:90
@ MODE_INTRA
Definition: slice.h:91
@ MODE_SKIP
Definition: slice.h:91
PartMode
Definition: slice.h:75
IntraPredMode
Definition: slice.h:95
Definition: image.h:194
uint8_t pcm_flag
Definition: image.h:210
uint8_t ctDepth
Definition: image.h:204
uint8_t PredMode
Definition: image.h:208
uint8_t PartMode
Definition: image.h:200
uint8_t log2CbSize
Definition: image.h:195
int8_t QP_Y
Definition: image.h:215
uint8_t cu_transquant_bypass
Definition: image.h:211
Definition: image.h:181
uint16_t SliceAddrRS
Definition: image.h:182
uint16_t SliceHeaderIndex
Definition: image.h:183
sao_info saoInfo
Definition: image.h:185
bool deblock
Definition: image.h:186
bool has_pcm_or_cu_transquant_bypass
Definition: image.h:190
Definition: de265.h:326
Definition: image.h:222
enum IntraPredMode get_IntraPredMode_atIndex(int idx) const
Definition: image.h:633
enum PartMode get_PartMode(int x, int y) const
Definition: image.h:565
int get_SliceHeaderIndex(int x, int y) const
Definition: image.h:735
enum PredMode get_pred_mode(int x, int y) const
Definition: image.h:501
int get_cu_transquant_bypass(int x, int y) const
Definition: image.h:532
uint8_t SubWidthC
Definition: image.h:363
const video_parameter_set & get_vps() const
Definition: image.h:386
const seq_parameter_set & get_sps() const
Definition: image.h:387
bool PicOutputFlag
Definition: image.h:382
bool available_zscan(int xCurr, int yCurr, int xN, int yN) const
void set_CtbDeblockFlag(int ctbX, int ctbY, bool flag)
Definition: image.h:792
int get_log2CbSize_cbUnits(int xCb, int yCb) const
Definition: image.h:555
int get_bytes_per_pixel(int cIdx) const
Definition: image.h:316
void set_IntraPredMode(int PUidx, int log2blkSize, enum IntraPredMode mode)
Definition: image.h:638
int height_confwin
Definition: image.h:372
std::vector< slice_segment_header * > slices
Definition: image.h:364
bool get_CtbDeblockFlag(int ctbX, int ctbY) const
Definition: image.h:798
int get_height(int cIdx=0) const
Definition: image.h:307
de265_mutex mutex
Definition: image.h:477
bool available_pred_blk(int xC, int yC, int nCbS, int xP, int yP, int nPbW, int nPbH, int partIdx, int xN, int yN) const
void set_pred_mode(int x, int y, int log2BlkWidth, enum PredMode mode)
Definition: image.h:490
void set_IntraPredModeC(int x0, int y0, int log2blkSize, enum IntraPredMode mode, bool is_mode4)
Definition: image.h:675
nal_header nal_hdr
Definition: image.h:440
int get_SliceHeaderIndexCtb(int ctbX, int ctbY) const
Definition: image.h:740
int PicOrderCntVal
Definition: image.h:380
uint32_t get_ID() const
Definition: image.h:254
void set_pcm_flag(int x, int y, int log2BlkWidth, uint8_t value=1)
Definition: image.h:511
int get_split_transform_flag(int x0, int y0, int trafoDepth) const
Definition: image.h:602
const PBMotion & get_mv_info(int x, int y) const
Definition: image.h:851
void * user_data
Definition: image.h:424
int get_deblk_width() const
Definition: image.h:814
void thread_unblocks()
int get_ctDepth(int x, int y) const
Definition: image.h:575
void set_deblk_bS(int x0, int y0, uint8_t bS)
Definition: image.h:836
slice_segment_header * get_SliceHeaderCtb(int ctbX, int ctbY)
Definition: image.h:763
void printBlk(int x0, int y0, int cIdx, int log2BlkSize)
int chroma_height_confwin
Definition: image.h:373
int width_confwin
Definition: image.h:372
void set_mv_info(int x, int y, int nPbW, int nPbH, const PBMotion &mv)
void fill_image(int y, int u, int v)
bool is_IntraPredModeC_Mode4(int x, int y) const
Definition: image.h:670
decoder_context * decctx
Definition: image.h:399
enum de265_chroma get_chroma_format() const
Definition: image.h:309
de265_error alloc_image(int w, int h, enum de265_chroma c, std::shared_ptr< const seq_parameter_set > sps, bool allocMetadata, decoder_context *dctx, de265_PTS pts, void *user_data, bool useCustomAllocFunctions)
int nThreadsQueued
Definition: image.h:470
int nThreadsTotal
Definition: image.h:474
void printBlk(const char *title, int x0, int y0, int blkSize, int cIdx) const
Definition: image.h:342
int get_image_stride(int cIdx) const
Definition: image.h:297
void mark_all_CTB_progress(int progress)
Definition: image.h:446
int get_SliceAddrRS_atCtbRS(int ctbRS) const
Definition: image.h:724
void clear_metadata()
int get_chroma_stride() const
Definition: image.h:304
de265_PTS pts
Definition: image.h:423
bool sei_hash_check_result
Definition: image.h:438
void set_ctDepth(int x, int y, int log2BlkWidth, int depth)
Definition: image.h:570
int get_nonzero_coefficient(int x, int y) const
Definition: image.h:620
enum PictureState PicState
Definition: image.h:381
void set_image_plane(int cIdx, uint8_t *mem, int stride, void *userdata)
de265_progress_lock * ctb_progress
Definition: image.h:444
void wait_for_completion()
const uint8_t * get_image_plane(int cIdx) const
Definition: image.h:258
void thread_finishes(const thread_task *)
void copy_lines_from(const de265_image *src, int first, int end)
void * get_image_plane_at_pos_any_depth(int cIdx, int xpos, int ypos)
Definition: image.h:283
uint8_t get_cu_skip_flag(int x, int y) const
Definition: image.h:506
int get_deblk_height() const
Definition: image.h:815
uint8_t get_deblk_flags(int x0, int y0) const
Definition: image.h:828
int32_t removed_at_picture_id
Definition: image.h:384
void set_SliceAddrRS(int ctbX, int ctbY, int SliceAddrRS)
Definition: image.h:713
int nThreadsBlocked
Definition: image.h:472
const void * get_image_plane_at_pos_any_depth(int cIdx, int xpos, int ypos) const
Definition: image.h:289
int get_SliceHeaderIndex_atIndex(int ctb) const
Definition: image.h:745
void set_cu_transquant_bypass(int x, int y, int log2BlkWidth, uint8_t value=1)
Definition: image.h:524
const uint8_t * get_image_plane_at_pos(int cIdx, int xpos, int ypos) const
Definition: image.h:277
int get_width(int cIdx=0) const
Definition: image.h:306
enum IntraPredMode get_IntraPredModeC(int x, int y) const
Definition: image.h:665
void set_nonzero_coefficient(int x, int y, int log2TrafoSize)
Definition: image.h:607
void thread_run(const thread_task *)
de265_cond finished_cond
Definition: image.h:478
const sao_info * get_sao_info(int ctbX, int ctbY) const
Definition: image.h:786
pixel_t * get_image_plane_at_pos_NEW(int cIdx, int xpos, int ypos)
xpos;ypos in actual plane resolution
Definition: image.h:271
int number_of_ctbs() const
Definition: image.h:402
int get_log2CbSize(int x0, int y0) const
Definition: image.h:549
void thread_start(int nThreads)
bool debug_is_completed() const
bool get_CTB_has_pcm_or_cu_transquant_bypass(int ctbX, int ctbY) const
Definition: image.h:804
int num_threads_active() const
Definition: image.h:467
void set_SliceHeaderIndex(int x, int y, int SliceHeaderIndex)
Definition: image.h:730
int nThreadsRunning
Definition: image.h:471
int get_SliceAddrRS(int ctbX, int ctbY) const
Definition: image.h:719
bool high_bit_depth(int cIdx) const
Definition: image.h:320
const pic_parameter_set & get_pps() const
Definition: image.h:388
void * plane_user_data[3]
Definition: image.h:425
slice_segment_header * get_SliceHeader(int x, int y)
Definition: image.h:756
bool is_allocated() const
Definition: image.h:237
void clear_split_transform_flags(int x0, int y0, int log2CbSize)
Definition: image.h:597
int get_bit_depth(int cIdx) const
Definition: image.h:311
int picture_order_cnt_lsb
Definition: image.h:379
bool has_vps() const
Definition: image.h:390
int chroma_width_confwin
Definition: image.h:373
de265_error copy_image(const de265_image *src)
void set_headers(std::shared_ptr< video_parameter_set > _vps, std::shared_ptr< seq_parameter_set > _sps, std::shared_ptr< pic_parameter_set > _pps)
Definition: image.h:241
int get_QPY(int x0, int y0) const
Definition: image.h:585
uint8_t BitDepth_Y
Definition: image.h:362
const slice_segment_header * get_SliceHeaderCtb(int ctbX, int ctbY) const
Definition: image.h:770
void exchange_pixel_data_with(de265_image &)
void set_split_transform_flag(int x0, int y0, int trafoDepth)
Definition: image.h:592
void set_log2CbSize(int x0, int y0, int log2CbSize, bool fill)
Definition: image.h:537
uint8_t get_deblk_bS(int x0, int y0) const
Definition: image.h:843
int get_pcm_flag(int x, int y) const
Definition: image.h:519
uint8_t SubHeightC
Definition: image.h:363
void set_PartMode(int x, int y, enum PartMode mode)
Definition: image.h:560
de265_image_allocation image_allocation_functions
Definition: image.h:426
void release()
bool has_pps() const
Definition: image.h:392
void wait_for_progress(thread_task *task, int ctbAddrRS, int progress)
bool has_sps() const
Definition: image.h:391
uint8_t integrity
Definition: image.h:434
void thread_blocks()
static de265_image_allocation default_image_allocation
Definition: image.h:340
uint8_t * get_image_plane_at_pos(int cIdx, int xpos, int ypos)
Definition: image.h:262
void fill_pred_mode(enum PredMode mode)
Definition: image.h:495
int nThreadsFinished
Definition: image.h:473
void set_QPY(int x, int y, int log2BlkWidth, int QP_Y)
Definition: image.h:580
void set_deblk_flags(int x0, int y0, uint8_t flags)
Definition: image.h:817
uint8_t * get_image_plane(int cIdx)
Definition: image.h:257
uint8_t BitDepth_C
Definition: image.h:362
void wait_for_progress(thread_task *task, int ctbx, int ctby, int progress)
std::shared_ptr< const seq_parameter_set > get_shared_sps()
Definition: image.h:394
bool can_be_released() const
Definition: image.h:324
bool is_SliceHeader_available(int x, int y) const
Definition: image.h:750
int get_luma_stride() const
Definition: image.h:303
uint8_t * pixels_confwin[3]
Definition: image.h:370
void add_slice_segment_header(slice_segment_header *shdr)
Definition: image.h:327
enum IntraPredMode get_IntraPredMode(int x, int y) const
Definition: image.h:628
void set_sao_info(int ctbX, int ctbY, const sao_info *saoinfo)
Definition: image.h:777
Definition: nal.h:36
Definition: slice.h:268
pthread_mutex_t de265_mutex
Definition: threads.h:42
pthread_cond_t de265_cond
Definition: threads.h:43
#define LIBDE265_CHECK_RESULT
Definition: util.h:56