21 #ifndef DE265_INTRAPRED_H
22 #define DE265_INTRAPRED_H
35 int x,
int y,
int PUidx,
98 pixel_t* dst,
int nT,
int cIdx);
107 static const int MAX_INTRA_PRED_BLOCK_SIZE = 64;
110 template <
class pixel_t>
141 void init(pixel_t* _out_border,
142 const de265_image* _img,
int _nT,
int _cIdx,
int _xB,
int _yB) {
146 assert(
nT <= MAX_INTRA_PRED_BLOCK_SIZE);
160 #ifdef DE265_LOG_TRACE
161 template <
class pixel_t>
162 void print_border(pixel_t* data, uint8_t* available,
int nT)
164 for (
int i=-2*nT ; i<=2*nT ; i++) {
165 if (i==0 || i==1 || i==-nT || i==nT+1) {
171 if (available==NULL || available[i]) {
180 #define print_border(data, available, nT)
185 template <
class pixel_t>
195 if (intraPredMode==
INTRA_DC || nT==4) {
205 case 8: filterFlag = (minDistVerHor>7) ? 1 : 0;
break;
206 case 16: filterFlag = (minDistVerHor>1) ? 1 : 0;
break;
207 case 32: filterFlag = (minDistVerHor>0) ? 1 : 0;
break;
210 case 64: filterFlag = 0;
break;
211 default: filterFlag = -1; assert(
false);
break;
224 pixel_t pF_mem[4*32+1];
225 pixel_t* pF = &pF_mem[2*32];
228 pF[-2*nT] = p[-2*nT];
229 pF[ 2*nT] = p[ 2*nT];
232 for (
int i=1;i<=63;i++) {
233 pF[-i] = p[0] + ((i*(p[-64]-p[0])+32)>>6);
234 pF[ i] = p[0] + ((i*(p[ 64]-p[0])+32)>>6);
237 pF[-2*nT] = p[-2*nT];
238 pF[ 2*nT] = p[ 2*nT];
240 for (
int i=-(2*nT-1) ; i<=2*nT-1 ; i++)
242 pF[i] = (p[i+1] + 2*p[i] + p[i-1] + 2) >> 2;
249 memcpy(p-2*nT, pF-2*nT, (4*nT+1) *
sizeof(pixel_t));
262 template <
class pixel_t>
267 int Log2_nT = Log2(nT);
269 for (
int y=0;y<nT;y++)
270 for (
int x=0;x<nT;x++)
272 dst[x+y*dstStride] = ((nT-1-x)*border[-1-y] + (x+1)*border[ 1+nT] +
273 (nT-1-y)*border[ 1+x] + (y+1)*border[-1-nT] + nT) >> (Log2_nT+1);
279 for (
int y=0;y<nT;y++)
281 for (
int x=0;x<nT;x++)
289 template <
class pixel_t>
294 int Log2_nT = Log2(nT);
297 for (
int i=0;i<nT;i++)
299 dcVal += border[ i+1];
300 dcVal += border[-i-1];
306 if (cIdx==0 && nT<32) {
307 dst[0] = (border[-1] + 2*dcVal + border[1] +2) >> 2;
309 for (
int x=1;x<nT;x++) { dst[x] = (border[ x+1] + 3*dcVal+2)>>2; }
310 for (
int y=1;y<nT;y++) { dst[y*dstStride] = (border[-y-1] + 3*dcVal+2)>>2; }
311 for (
int y=1;y<nT;y++)
312 for (
int x=1;x<nT;x++)
314 dst[x+y*dstStride] = dcVal;
317 for (
int y=0;y<nT;y++)
318 for (
int x=0;x<nT;x++)
320 dst[x+y*dstStride] = dcVal;
331 template <
class pixel_t>
333 int bit_depth,
bool disableIntraBoundaryFilter,
339 pixel_t ref_mem[4*MAX_INTRA_PRED_BLOCK_SIZE+1];
340 pixel_t* ref=&ref_mem[2*MAX_INTRA_PRED_BLOCK_SIZE];
342 assert(intraPredMode<35);
343 assert(intraPredMode>=2);
347 if (intraPredMode >= 18) {
349 for (
int x=0;x<=nT;x++)
350 { ref[x] = border[x]; }
352 if (intraPredAngle<0) {
355 if ((nT*intraPredAngle)>>5 < -1) {
356 for (
int x=(nT*intraPredAngle)>>5; x<=-1; x++) {
357 ref[x] = border[0-((x*invAngle+128)>>8)];
361 for (
int x=nT+1; x<=2*nT;x++) {
366 for (
int y=0;y<nT;y++)
367 for (
int x=0;x<nT;x++)
369 int iIdx = ((y+1)*intraPredAngle)>>5;
370 int iFact= ((y+1)*intraPredAngle)&31;
373 dst[x+y*dstStride] = ((32-iFact)*ref[x+iIdx+1] + iFact*ref[x+iIdx+2] + 16)>>5;
375 dst[x+y*dstStride] = ref[x+iIdx+1];
379 if (intraPredMode==26 && cIdx==0 && nT<32 && !disableIntraBoundaryFilter) {
380 for (
int y=0;y<nT;y++) {
381 dst[0+y*dstStride] =
Clip_BitDepth(border[1] + ((border[-1-y] - border[0])>>1), bit_depth);
387 for (
int x=0;x<=nT;x++)
388 { ref[x] = border[-x]; }
390 if (intraPredAngle<0) {
393 if ((nT*intraPredAngle)>>5 < -1) {
394 for (
int x=(nT*intraPredAngle)>>5; x<=-1; x++) {
395 ref[x] = border[((x*invAngle+128)>>8)];
399 for (
int x=nT+1; x<=2*nT;x++) {
404 for (
int y=0;y<nT;y++)
405 for (
int x=0;x<nT;x++)
407 int iIdx = ((x+1)*intraPredAngle)>>5;
408 int iFact= ((x+1)*intraPredAngle)&31;
411 dst[x+y*dstStride] = ((32-iFact)*ref[y+iIdx+1] + iFact*ref[y+iIdx+2] + 16)>>5;
413 dst[x+y*dstStride] = ref[y+iIdx+1];
417 if (intraPredMode==10 && cIdx==0 && nT<32 && !disableIntraBoundaryFilter) {
418 for (
int x=0;x<nT;x++) {
419 dst[x] =
Clip_BitDepth(border[-1] + ((border[1+x] - border[0])>>1), bit_depth);
427 for (
int y=0;y<nT;y++)
429 for (
int x=0;x<nT;x++)
437 template <
class pixel_t>
440 sps = &img->get_sps();
441 pps = &img->get_pps();
443 SubWidth = (cIdx==0) ? 1 : sps->SubWidthC;
444 SubHeight = (cIdx==0) ? 1 : sps->SubHeightC;
448 int xBLuma = xB * SubWidth;
449 int yBLuma = yB * SubHeight;
451 int log2CtbSize = sps->Log2CtbSizeY;
452 int picWidthInCtbs = sps->PicWidthInCtbsY;
460 availableLeft =
false;
461 availableTopLeft =
false;
469 availableTop =
false;
470 availableTopLeft =
false;
471 availableTopRight =
false;
475 if (xBLuma+nT*SubWidth >= sps->pic_width_in_luma_samples) {
476 availableTopRight=
false;
481 int xCurrCtb = xBLuma >> log2CtbSize;
482 int yCurrCtb = yBLuma >> log2CtbSize;
483 int xLeftCtb = (xBLuma-1) >> log2CtbSize;
484 int xRightCtb = (xBLuma+nT*SubWidth) >> log2CtbSize;
485 int yTopCtb = (yBLuma-1) >> log2CtbSize;
487 int currCTBSlice = img->get_SliceAddrRS(xCurrCtb,yCurrCtb);
488 int leftCTBSlice = availableLeft ? img->get_SliceAddrRS(xLeftCtb, yCurrCtb) : -1;
489 int topCTBSlice = availableTop ? img->get_SliceAddrRS(xCurrCtb, yTopCtb) : -1;
490 int toprightCTBSlice = availableTopRight ? img->get_SliceAddrRS(xRightCtb, yTopCtb) : -1;
491 int topleftCTBSlice = availableTopLeft ? img->get_SliceAddrRS(xLeftCtb, yTopCtb) : -1;
500 int currCTBTileID = pps->TileIdRS[xCurrCtb+yCurrCtb*picWidthInCtbs];
501 int leftCTBTileID = availableLeft ? pps->TileIdRS[xLeftCtb+yCurrCtb*picWidthInCtbs] : -1;
502 int topCTBTileID = availableTop ? pps->TileIdRS[xCurrCtb+yTopCtb*picWidthInCtbs] : -1;
503 int topleftCTBTileID = availableTopLeft ? pps->TileIdRS[xLeftCtb+yTopCtb*picWidthInCtbs] : -1;
504 int toprightCTBTileID= availableTopRight? pps->TileIdRS[xRightCtb+yTopCtb*picWidthInCtbs] : -1;
506 if (leftCTBSlice != currCTBSlice || leftCTBTileID != currCTBTileID ) availableLeft =
false;
507 if (topCTBSlice != currCTBSlice || topCTBTileID != currCTBTileID ) availableTop =
false;
508 if (topleftCTBSlice !=currCTBSlice||topleftCTBTileID!=currCTBTileID ) availableTopLeft =
false;
509 if (toprightCTBSlice!=currCTBSlice||toprightCTBTileID!=currCTBTileID) availableTopRight=
false;
514 nBottom = sps->pic_height_in_luma_samples - yB*SubHeight;
515 nBottom=(nBottom+SubHeight-1)/SubHeight;
516 if (nBottom>2*nT) nBottom=2*nT;
518 nRight = sps->pic_width_in_luma_samples - xB*SubWidth;
519 nRight =(nRight +SubWidth-1)/SubWidth;
520 if (nRight >2*nT) nRight=2*nT;
524 available = &available_data[2*MAX_INTRA_PRED_BLOCK_SIZE];
526 memset(available-2*nT, 0, 4*nT+1);
530 template <
class pixel_t>
537 image = (pixel_t*)img->get_image_plane(cIdx);
538 stride = img->get_image_stride(cIdx);
540 int xBLuma = xB * SubWidth;
541 int yBLuma = yB * SubHeight;
543 int currBlockAddr = pps->MinTbAddrZS[ (xBLuma>>sps->Log2MinTrafoSize) +
544 (yBLuma>>sps->Log2MinTrafoSize) * sps->PicWidthInTbsY ];
549 for (
int y=nBottom-1 ; y>=0 ; y-=4)
552 int NBlockAddr = pps->MinTbAddrZS[ (((xB-1)*SubWidth )>>sps->Log2MinTrafoSize) +
553 (((yB+y)*SubHeight)>>sps->Log2MinTrafoSize)
554 * sps->PicWidthInTbsY ];
556 bool availableN = NBlockAddr <= currBlockAddr;
558 if (pps->constrained_intra_pred_flag) {
559 if (img->get_pred_mode((xB-1)*SubWidth,(yB+y)*SubHeight)!=
MODE_INTRA)
564 if (!nAvail) firstValue = image[xB-1 + (yB+y)*stride];
566 for (
int i=0;i<4;i++) {
567 available[-y+i-1] = availableN;
568 out_border[-y+i-1] = image[xB-1 + (yB+y-i)*stride];
577 if (availableTopLeft)
579 int NBlockAddr = pps->MinTbAddrZS[ (((xB-1)*SubWidth )>>sps->Log2MinTrafoSize) +
580 (((yB-1)*SubHeight)>>sps->Log2MinTrafoSize)
581 * sps->PicWidthInTbsY ];
583 bool availableN = NBlockAddr <= currBlockAddr;
585 if (pps->constrained_intra_pred_flag) {
586 if (img->get_pred_mode((xB-1)*SubWidth,(yB-1)*SubHeight)!=
MODE_INTRA) {
592 if (!nAvail) firstValue = image[xB-1 + (yB-1)*stride];
594 out_border[0] = image[xB-1 + (yB-1)*stride];
595 available[0] = availableN;
602 for (
int x=0 ; x<nRight ; x+=4) {
603 bool borderAvailable;
604 if (x<nT) borderAvailable=availableTop;
605 else borderAvailable=availableTopRight;
609 int NBlockAddr = pps->MinTbAddrZS[ (((xB+x)*SubWidth )>>sps->Log2MinTrafoSize) +
610 (((yB-1)*SubHeight)>>sps->Log2MinTrafoSize)
611 * sps->PicWidthInTbsY ];
613 bool availableN = NBlockAddr <= currBlockAddr;
615 if (pps->constrained_intra_pred_flag) {
616 if (img->get_pred_mode((xB+x)*SubWidth,(yB-1)*SubHeight)!=
MODE_INTRA) {
623 if (!nAvail) firstValue = image[xB+x + (yB-1)*stride];
625 for (
int i=0;i<4;i++) {
626 out_border[x+i+1] = image[xB+x+i + (yB-1)*stride];
627 available[x+i+1] = availableN;
638 template <
class pixel_t>
643 const int bit_depth = img->get_bit_depth(cIdx);
645 if (nAvail!=4*nT+1) {
647 if (
sizeof(pixel_t)==1) {
648 memset(out_border-2*nT, 1<<(bit_depth-1), 4*nT+1);
651 for (
int i = -2*nT; i <= 2*nT ; i++) {
652 out_border[i] = 1<<(bit_depth-1);
657 if (!available[-2*nT]) {
658 out_border[-2*nT] = firstValue;
661 for (
int i=-2*nT+1; i<=2*nT; i++)
663 out_border[i]=out_border[i-1];
Definition: intrapred.h:112
const pic_parameter_set * pps
Definition: intrapred.h:123
void fill_from_image()
Definition: intrapred.h:531
bool availableTop
Definition: intrapred.h:132
uint8_t available_data[4 *MAX_INTRA_PRED_BLOCK_SIZE+1]
Definition: intrapred.h:125
const de265_image * img
Definition: intrapred.h:116
bool availableTopRight
Definition: intrapred.h:133
int cIdx
Definition: intrapred.h:118
void preproc()
Definition: intrapred.h:438
pixel_t * out_border
Definition: intrapred.h:114
const seq_parameter_set * sps
Definition: intrapred.h:122
int xB
Definition: intrapred.h:120
void reference_sample_substitution()
Definition: intrapred.h:639
bool availableLeft
Definition: intrapred.h:131
int nT
Definition: intrapred.h:117
bool availableTopLeft
Definition: intrapred.h:134
int nBottom
Definition: intrapred.h:136
void init(pixel_t *_out_border, const de265_image *_img, int _nT, int _cIdx, int _xB, int _yB)
Definition: intrapred.h:141
int yB
Definition: intrapred.h:120
int SubWidth
Definition: intrapred.h:128
int nAvail
Definition: intrapred.h:138
uint8_t * available
Definition: intrapred.h:126
int nRight
Definition: intrapred.h:137
pixel_t firstValue
Definition: intrapred.h:139
int SubHeight
Definition: intrapred.h:129
char strong_intra_smoothing_enable_flag
Definition: sps.h:167
int bit_depth_luma
Definition: sps.h:123
int getPUIndexRS(int pixelX, int pixelY) const
Definition: sps.h:239
void intra_prediction_angular(pixel_t *dst, int dstStride, int bit_depth, bool disableIntraBoundaryFilter, int xB0, int yB0, enum IntraPredMode intraPredMode, int nT, int cIdx, pixel_t *border)
Definition: intrapred.h:332
int get_intra_scan_idx(int log2TrafoSize, enum IntraPredMode intraPredMode, int cIdx, const seq_parameter_set *sps)
const int intraPredAngle_table[1+34]
Definition: intrapred.h:326
const int invAngle_table[25-10]
void intra_prediction_planar(pixel_t *dst, int dstStride, int nT, int cIdx, pixel_t *border)
Definition: intrapred.h:263
int get_intra_scan_idx_chroma(int log2TrafoSize, enum IntraPredMode intraPredMode)
void list_chroma_pred_candidates(enum IntraPredMode chroma_mode[5], enum IntraPredMode luma_mode)
#define print_border(data, available, nT)
Definition: intrapred.h:180
int find_intra_pred_mode(enum IntraPredMode mode, enum IntraPredMode candModeList[3])
void fillIntraPredModeCandidates(enum IntraPredMode candModeList[3], int x, int y, int PUidx, bool availableA, bool availableB, const de265_image *img)
void intra_prediction_DC(pixel_t *dst, int dstStride, int nT, int cIdx, pixel_t *border)
Definition: intrapred.h:290
void intra_prediction_sample_filtering(const seq_parameter_set &sps, pixel_t *p, int nT, int cIdx, enum IntraPredMode intraPredMode)
Definition: intrapred.h:186
void decode_intra_prediction(de265_image *img, int xB0, int yB0, enum IntraPredMode intraPredMode, int nT, int cIdx)
int get_intra_scan_idx_luma(int log2TrafoSize, enum IntraPredMode intraPredMode)
enum IntraPredMode lumaPredMode_to_chromaPredMode(enum IntraPredMode luma, enum IntraChromaPredMode chroma)
@ MODE_INTRA
Definition: slice.h:91
IntraPredMode
Definition: slice.h:95
@ INTRA_DC
Definition: slice.h:97
IntraChromaPredMode
Definition: slice.h:111
const seq_parameter_set & get_sps() const
Definition: image.h:387
#define libde265_min(a, b)
Definition: util.h:116
#define logtrace(a, b,...)
Definition: util.h:216
@ LogIntraPred
Definition: util.h:168
#define abs_value(a)
Definition: util.h:115
#define Clip_BitDepth(value, bit_depth)
Definition: util.h:112