1 /*****************************************************************************
2 * Copyright (C) 2014 x265 project
4 * Authors: Steve Borho <steve@borho.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
28 #include "primitives.h"
36 /* A Yuv instance holds pixels for a square CU (64x64 down to 8x8) for all three planes
37 * these are typically used to hold fenc, predictions, or reconstructed blocks */
46 int m_part
; // cached partition enum size
54 bool create(uint32_t size
, int csp
);
57 // Copy YUV buffer to picture buffer
58 void copyToPicYuv(PicYuv
& destPicYuv
, uint32_t cuAddr
, uint32_t absPartIdx
) const;
60 // Copy YUV buffer from picture buffer
61 void copyFromPicYuv(const PicYuv
& srcPicYuv
, uint32_t cuAddr
, uint32_t absPartIdx
);
63 // Copy from same size YUV buffer
64 void copyFromYuv(const Yuv
& srcYuv
);
66 // Copy portion of srcYuv into ME prediction buffer
67 void copyPUFromYuv(const Yuv
& srcYuv
, uint32_t absPartIdx
, int partEnum
, bool bChroma
);
69 // Copy Small YUV buffer to the part of other Big YUV buffer
70 void copyToPartYuv(Yuv
& dstYuv
, uint32_t absPartIdx
) const;
72 // Copy the part of Big YUV buffer to other Small YUV buffer
73 void copyPartToYuv(Yuv
& dstYuv
, uint32_t absPartIdx
) const;
75 // Clip(srcYuv0 + srcYuv1) -> m_buf .. aka recon = clip(pred + residual)
76 void addClip(const Yuv
& srcYuv0
, const ShortYuv
& srcYuv1
, uint32_t log2SizeL
);
78 // (srcYuv0 + srcYuv1)/2 for YUV partition (bidir averaging)
79 void addAvg(const ShortYuv
& srcYuv0
, const ShortYuv
& srcYuv1
, uint32_t absPartIdx
, uint32_t width
, uint32_t height
, bool bLuma
, bool bChroma
);
81 void copyPartToPartLuma(Yuv
& dstYuv
, uint32_t absPartIdx
, uint32_t log2Size
) const;
82 void copyPartToPartChroma(Yuv
& dstYuv
, uint32_t absPartIdx
, uint32_t log2SizeL
) const;
84 pixel
* getLumaAddr(uint32_t absPartIdx
) { return m_buf
[0] + getAddrOffset(absPartIdx
, m_size
); }
85 pixel
* getCbAddr(uint32_t absPartIdx
) { return m_buf
[1] + getChromaAddrOffset(absPartIdx
); }
86 pixel
* getCrAddr(uint32_t absPartIdx
) { return m_buf
[2] + getChromaAddrOffset(absPartIdx
); }
87 pixel
* getChromaAddr(uint32_t chromaId
, uint32_t absPartIdx
) { return m_buf
[chromaId
] + getChromaAddrOffset(absPartIdx
); }
89 const pixel
* getLumaAddr(uint32_t absPartIdx
) const { return m_buf
[0] + getAddrOffset(absPartIdx
, m_size
); }
90 const pixel
* getCbAddr(uint32_t absPartIdx
) const { return m_buf
[1] + getChromaAddrOffset(absPartIdx
); }
91 const pixel
* getCrAddr(uint32_t absPartIdx
) const { return m_buf
[2] + getChromaAddrOffset(absPartIdx
); }
92 const pixel
* getChromaAddr(uint32_t chromaId
, uint32_t absPartIdx
) const { return m_buf
[chromaId
] + getChromaAddrOffset(absPartIdx
); }
94 int getChromaAddrOffset(uint32_t absPartIdx
) const
96 int blkX
= g_zscanToPelX
[absPartIdx
] >> m_hChromaShift
;
97 int blkY
= g_zscanToPelY
[absPartIdx
] >> m_vChromaShift
;
99 return blkX
+ blkY
* m_csize
;
102 static int getAddrOffset(uint32_t absPartIdx
, uint32_t width
)
104 int blkX
= g_zscanToPelX
[absPartIdx
];
105 int blkY
= g_zscanToPelY
[absPartIdx
];
107 return blkX
+ blkY
* width
;