• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 #include <string.h>
33 #include "expand_pic.h"
34 #include "cpu_core.h"
35 
MBPadTopLeftLuma_c(uint8_t * & pDst,const int32_t & kiStride)36 static inline void MBPadTopLeftLuma_c (uint8_t*& pDst, const int32_t& kiStride) {
37   const uint8_t kuiTL = pDst[0];
38   int32_t i = 0;
39   uint8_t* pTopLeft = pDst;
40   do {
41     pTopLeft -= kiStride;
42     // pad pTop
43     memcpy (pTopLeft, pDst, 16);           // confirmed_safe_unsafe_usage
44     memset (pTopLeft - PADDING_LENGTH, kuiTL, PADDING_LENGTH); //pTop left
45   } while (++i < PADDING_LENGTH);
46 }
47 
MBPadTopLuma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiMbX)48 static inline void MBPadTopLuma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiMbX) {
49   uint8_t* pTopLine = pDst + (kiMbX << 4);
50   int32_t i = 0;
51   uint8_t* pTop = pTopLine;
52   do {
53     pTop -= kiStride;
54     // pad pTop
55     memcpy (pTop, pTopLine, 16);          // confirmed_safe_unsafe_usage
56   } while (++i < PADDING_LENGTH);
57 }
58 
MBPadBottomLuma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiMbX,const int32_t & kiPicH)59 static inline void MBPadBottomLuma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiMbX,
60                                       const int32_t& kiPicH) {
61   uint8_t* pBottomLine = pDst + (kiPicH - 1) * kiStride + (kiMbX << 4);
62   int32_t i = 0;
63   uint8_t* pBottom = pBottomLine;
64   do {
65     pBottom += kiStride;
66     // pad pBottom
67     memcpy (pBottom, pBottomLine, 16);       // confirmed_safe_unsafe_usage
68   } while (++i < PADDING_LENGTH);
69 }
70 
MBPadTopRightLuma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiPicW)71 static inline void MBPadTopRightLuma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiPicW) {
72   uint8_t* pTopRight = pDst + kiPicW;
73   const uint8_t kuiTR = pTopRight[-1];
74   int32_t i = 0;
75   uint8_t* pTop = pTopRight;
76   do {
77     pTop -= kiStride;
78     // pad pTop
79     memcpy (pTop - 16, pTopRight - 16, 16);          // confirmed_safe_unsafe_usage
80     memset (pTop, kuiTR, PADDING_LENGTH); //pTop Right
81   } while (++i < PADDING_LENGTH);
82 }
83 
MBPadBottomLeftLuma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiPicH)84 static inline void MBPadBottomLeftLuma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiPicH) {
85   uint8_t* pDstLastLine = pDst + (kiPicH - 1) * kiStride;
86   const uint8_t kuiBL = pDstLastLine[0];
87   int32_t i = 0;
88   uint8_t* pBottom = pDstLastLine;
89   do {
90     pBottom += kiStride;
91     // pad pBottom
92     memcpy (pBottom, pDstLastLine, 16);          // confirmed_safe_unsafe_usage
93     memset (pBottom - PADDING_LENGTH, kuiBL, PADDING_LENGTH); //pBottom left
94   } while (++i < PADDING_LENGTH);
95 }
96 
MBPadBottomRightLuma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiPicW,const int32_t & kiPicH)97 static inline void MBPadBottomRightLuma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiPicW,
98     const int32_t& kiPicH) {
99   uint8_t* pDstLastLine = pDst + (kiPicH - 1) * kiStride + kiPicW;
100   const uint8_t kuiBR = pDstLastLine[-1];
101   int32_t i = 0;
102   uint8_t* pBottom = pDstLastLine;
103   do {
104     pBottom += kiStride;
105     // pad pBottom
106     memcpy (pBottom - 16, pDstLastLine - 16, 16);         // confirmed_safe_unsafe_usage
107     memset (pBottom, kuiBR, PADDING_LENGTH); //pBottom Right
108   } while (++i < PADDING_LENGTH);
109 }
110 
MBPadLeftLuma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiMbY)111 static inline void MBPadLeftLuma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiMbY) {
112   uint8_t* pTmp = pDst + (kiMbY << 4) * kiStride;
113   for (int32_t i = 0; i < 16; ++i) {
114     // pad left
115     memset (pTmp - PADDING_LENGTH, pTmp[0], PADDING_LENGTH);
116     pTmp += kiStride;
117   }
118 }
119 
MBPadRightLuma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiMbY,const int32_t & kiPicW)120 static inline void MBPadRightLuma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiMbY,
121                                      const int32_t& kiPicW) {
122   uint8_t* pTmp = pDst + (kiMbY << 4) * kiStride + kiPicW;
123   for (int32_t i = 0; i < 16; ++i) {
124     // pad right
125     memset (pTmp, pTmp[-1], PADDING_LENGTH);
126     pTmp += kiStride;
127   }
128 }
129 
MBPadTopChroma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiMbX)130 static inline void MBPadTopChroma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiMbX) {
131   uint8_t* pTopLine = pDst + (kiMbX << 3);
132   int32_t i = 0;
133   uint8_t* pTop = pTopLine;
134   do {
135     pTop -= kiStride;
136     // pad pTop
137     memcpy (pTop, pTopLine, 8);         // confirmed_safe_unsafe_usage
138   } while (++i < CHROMA_PADDING_LENGTH);
139 }
140 
MBPadBottomChroma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiMbX,const int32_t & kiPicH)141 static inline void MBPadBottomChroma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiMbX,
142                                         const int32_t& kiPicH) {
143   uint8_t* pBottomLine = pDst + (kiPicH - 1) * kiStride + (kiMbX << 3);
144   int32_t i = 0;
145   uint8_t* pBottom = pBottomLine;
146   do {
147     pBottom += kiStride;
148     // pad pBottom
149     memcpy (pBottom, pBottomLine, 8);        // confirmed_safe_unsafe_usage
150   } while (++i < CHROMA_PADDING_LENGTH);
151 }
152 
MBPadTopLeftChroma_c(uint8_t * & pDst,const int32_t & kiStride)153 static inline void MBPadTopLeftChroma_c (uint8_t*& pDst, const int32_t& kiStride) {
154   const uint8_t kuiTL = pDst[0];
155   int32_t i = 0;
156   uint8_t* pTopLeft = pDst;
157   do {
158     pTopLeft -= kiStride;
159     // pad pTop
160     memcpy (pTopLeft, pDst, 8);          // confirmed_safe_unsafe_usage
161     memset (pTopLeft - CHROMA_PADDING_LENGTH, kuiTL, CHROMA_PADDING_LENGTH); //pTop left
162   } while (++i < CHROMA_PADDING_LENGTH);
163 }
164 
MBPadTopRightChroma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiPicW)165 static inline void MBPadTopRightChroma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiPicW) {
166   uint8_t* pTopRight = pDst + kiPicW;
167   const uint8_t kuiTR = pTopRight[-1];
168   int32_t i = 0;
169   uint8_t* pTop = pTopRight;
170   do {
171     pTop -= kiStride;
172     // pad pTop
173     memcpy (pTop - 8, pTopRight - 8, 8);         // confirmed_safe_unsafe_usage
174     memset (pTop, kuiTR, CHROMA_PADDING_LENGTH); //pTop Right
175   } while (++i < CHROMA_PADDING_LENGTH);
176 }
177 
MBPadBottomLeftChroma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiPicH)178 static inline void MBPadBottomLeftChroma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiPicH) {
179   uint8_t* pDstLastLine = pDst + (kiPicH - 1) * kiStride;
180   const uint8_t kuiBL = pDstLastLine[0];
181   int32_t i = 0;
182   uint8_t* pBottom = pDstLastLine;
183   do {
184     pBottom += kiStride;
185     // pad pBottom
186     memcpy (pBottom, pDstLastLine, 8);         // confirmed_safe_unsafe_usage
187     memset (pBottom - CHROMA_PADDING_LENGTH, kuiBL, CHROMA_PADDING_LENGTH); //pBottom left
188   } while (++i < CHROMA_PADDING_LENGTH);
189 }
190 
MBPadBottomRightChroma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiPicW,const int32_t kiPicH)191 static inline void MBPadBottomRightChroma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiPicW,
192     const int32_t kiPicH) {
193   uint8_t* pDstLastLine = pDst + (kiPicH - 1) * kiStride + kiPicW;
194   const uint8_t kuiBR = pDstLastLine[-1];
195   int32_t i = 0;
196   uint8_t* pBottom = pDstLastLine;
197   do {
198     pBottom += kiStride;
199     // pad pBottom
200     memcpy (pBottom - 8, pDstLastLine - 8, 8);       // confirmed_safe_unsafe_usage
201     memset (pBottom, kuiBR, CHROMA_PADDING_LENGTH); //pBottom Right
202   } while (++i < CHROMA_PADDING_LENGTH);
203 }
204 
MBPadLeftChroma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiMbY)205 static inline void MBPadLeftChroma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiMbY) {
206   uint8_t* pTmp = pDst + (kiMbY << 3) * kiStride;
207   for (int32_t i = 0; i < 8; ++i) {
208     // pad left
209     memset (pTmp - CHROMA_PADDING_LENGTH, pTmp[0], CHROMA_PADDING_LENGTH);
210     pTmp += kiStride;
211   }
212 }
213 
MBPadRightChroma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiMbY,const int32_t & kiPicW)214 static inline void MBPadRightChroma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiMbY,
215                                        const int32_t& kiPicW) {
216   uint8_t* pTmp = pDst + (kiMbY << 3) * kiStride + kiPicW;
217   for (int32_t i = 0; i < 8; ++i) {
218     // pad right
219     memset (pTmp, pTmp[-1], CHROMA_PADDING_LENGTH);
220     pTmp += kiStride;
221   }
222 }
223 
PadMBLuma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiPicW,const int32_t & kiPicH,const int32_t & kiMbX,const int32_t & kiMbY,const int32_t & kiMBWidth,const int32_t & kiMBHeight)224 void PadMBLuma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiPicW, const int32_t& kiPicH,
225                   const int32_t& kiMbX, const int32_t& kiMbY, const int32_t& kiMBWidth, const int32_t& kiMBHeight) {
226   if (kiMbX == 0 && kiMbY == 0) {
227     MBPadTopLeftLuma_c (pDst, kiStride);
228   } else if (kiMbY == 0 && kiMbX == kiMBWidth - 1) {
229     MBPadTopRightLuma_c (pDst, kiStride, kiPicW);
230   } else if (kiMbY == kiMBHeight - 1 && kiMbX == 0) {
231     MBPadBottomLeftLuma_c (pDst, kiStride, kiPicH);
232   } else if (kiMbY == kiMBHeight - 1 && kiMbX == kiMBWidth - 1) {
233     MBPadBottomRightLuma_c (pDst, kiStride, kiPicW, kiPicH);
234   }
235   if (kiMbX == 0) {
236     MBPadLeftLuma_c (pDst, kiStride, kiMbY);
237   } else if (kiMbX == kiMBWidth - 1) {
238     MBPadRightLuma_c (pDst, kiStride, kiMbY, kiPicW);
239   }
240   if (kiMbY == 0 && kiMbX > 0 && kiMbX < kiMBWidth - 1) {
241     MBPadTopLuma_c (pDst, kiStride, kiMbX);
242   } else if (kiMbY == kiMBHeight - 1 && kiMbX > 0 && kiMbX < kiMBWidth - 1) {
243     MBPadBottomLuma_c (pDst, kiStride, kiMbX, kiPicH);
244   }
245 }
246 
PadMBChroma_c(uint8_t * & pDst,const int32_t & kiStride,const int32_t & kiPicW,const int32_t & kiPicH,const int32_t & kiMbX,const int32_t & kiMbY,const int32_t & kiMBWidth,const int32_t & kiMBHeight)247 void PadMBChroma_c (uint8_t*& pDst, const int32_t& kiStride, const int32_t& kiPicW, const int32_t& kiPicH,
248                     const int32_t& kiMbX, const int32_t& kiMbY, const int32_t& kiMBWidth, const int32_t& kiMBHeight) {
249   if (kiMbX == 0 && kiMbY == 0) {
250     MBPadTopLeftChroma_c (pDst, kiStride);
251   } else if (kiMbY == 0 && kiMbX == kiMBWidth - 1) {
252     MBPadTopRightChroma_c (pDst, kiStride, kiPicW);
253   } else if (kiMbY == kiMBHeight - 1 && kiMbX == 0) {
254     MBPadBottomLeftChroma_c (pDst, kiStride, kiPicH);
255   } else if (kiMbY == kiMBHeight - 1 && kiMbX == kiMBWidth - 1) {
256     MBPadBottomRightChroma_c (pDst, kiStride, kiPicW, kiPicH);
257   }
258   if (kiMbX == 0) {
259     MBPadLeftChroma_c (pDst, kiStride, kiMbY);
260   } else if (kiMbX == kiMBWidth - 1) {
261     MBPadRightChroma_c (pDst, kiStride, kiMbY, kiPicW);
262   }
263   if (kiMbY == 0 && kiMbX > 0 && kiMbX < kiMBWidth - 1) {
264     MBPadTopChroma_c (pDst, kiStride, kiMbX);
265   } else if (kiMbY == kiMBHeight - 1 && kiMbX > 0 && kiMbX < kiMBWidth - 1) {
266     MBPadBottomChroma_c (pDst, kiStride, kiMbX, kiPicH);
267   }
268 }
269 
270 // rewrite it (split into luma & chroma) that is helpful for mmx/sse2 optimization perform, 9/27/2009
ExpandPictureLuma_c(uint8_t * pDst,const int32_t kiStride,const int32_t kiPicW,const int32_t kiPicH)271 static inline void ExpandPictureLuma_c (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicW,
272                                         const int32_t kiPicH) {
273   uint8_t* pTmp              = pDst;
274   uint8_t* pDstLastLine      = pTmp + (kiPicH - 1) * kiStride;
275   const int32_t kiPaddingLen = PADDING_LENGTH;
276   const uint8_t kuiTL        = pTmp[0];
277   const uint8_t kuiTR        = pTmp[kiPicW - 1];
278   const uint8_t kuiBL        = pDstLastLine[0];
279   const uint8_t kuiBR        = pDstLastLine[kiPicW - 1];
280   int32_t i                  = 0;
281 
282   do {
283     const int32_t kiStrides = (1 + i) * kiStride;
284     uint8_t* pTop           = pTmp - kiStrides;
285     uint8_t* pBottom        = pDstLastLine + kiStrides;
286 
287     // pad pTop and pBottom
288     memcpy (pTop, pTmp, kiPicW);                // confirmed_safe_unsafe_usage
289     memcpy (pBottom, pDstLastLine, kiPicW);     // confirmed_safe_unsafe_usage
290 
291     // pad corners
292     memset (pTop - kiPaddingLen, kuiTL, kiPaddingLen); //pTop left
293     memset (pTop + kiPicW, kuiTR, kiPaddingLen); //pTop right
294     memset (pBottom - kiPaddingLen, kuiBL, kiPaddingLen); //pBottom left
295     memset (pBottom + kiPicW, kuiBR, kiPaddingLen); //pBottom right
296 
297     ++ i;
298   } while (i < kiPaddingLen);
299 
300   // pad left and right
301   i = 0;
302   do {
303     memset (pTmp - kiPaddingLen, pTmp[0], kiPaddingLen);
304     memset (pTmp + kiPicW, pTmp[kiPicW - 1], kiPaddingLen);
305 
306     pTmp += kiStride;
307     ++ i;
308   } while (i < kiPicH);
309 }
310 
ExpandPictureChroma_c(uint8_t * pDst,const int32_t kiStride,const int32_t kiPicW,const int32_t kiPicH)311 static inline void ExpandPictureChroma_c (uint8_t* pDst, const int32_t kiStride, const int32_t kiPicW,
312     const int32_t kiPicH) {
313   uint8_t* pTmp                 = pDst;
314   uint8_t* pDstLastLine         = pTmp + (kiPicH - 1) * kiStride;
315   const int32_t kiPaddingLen    = (PADDING_LENGTH >> 1);
316   const uint8_t kuiTL           = pTmp[0];
317   const uint8_t kuiTR           = pTmp[kiPicW - 1];
318   const uint8_t kuiBL           = pDstLastLine[0];
319   const uint8_t kuiBR           = pDstLastLine[kiPicW - 1];
320   int32_t i                     = 0;
321 
322   do {
323     const int32_t kiStrides = (1 + i) * kiStride;
324     uint8_t* pTop           = pTmp - kiStrides;
325     uint8_t* pBottom        = pDstLastLine + kiStrides;
326 
327     // pad pTop and pBottom
328     memcpy (pTop, pTmp, kiPicW);                // confirmed_safe_unsafe_usage
329     memcpy (pBottom, pDstLastLine, kiPicW);     // confirmed_safe_unsafe_usage
330 
331     // pad corners
332     memset (pTop - kiPaddingLen, kuiTL, kiPaddingLen); //pTop left
333     memset (pTop + kiPicW, kuiTR, kiPaddingLen); //pTop right
334     memset (pBottom - kiPaddingLen, kuiBL, kiPaddingLen); //pBottom left
335     memset (pBottom + kiPicW, kuiBR, kiPaddingLen); //pBottom right
336 
337     ++ i;
338   } while (i < kiPaddingLen);
339 
340   // pad left and right
341   i = 0;
342   do {
343     memset (pTmp - kiPaddingLen, pTmp[0], kiPaddingLen);
344     memset (pTmp + kiPicW, pTmp[kiPicW - 1], kiPaddingLen);
345 
346     pTmp += kiStride;
347     ++ i;
348   } while (i < kiPicH);
349 }
350 
InitExpandPictureFunc(SExpandPicFunc * pExpandPicFunc,const uint32_t kuiCPUFlag)351 void InitExpandPictureFunc (SExpandPicFunc* pExpandPicFunc, const uint32_t kuiCPUFlag) {
352   pExpandPicFunc->pfExpandLumaPicture        = ExpandPictureLuma_c;
353   pExpandPicFunc->pfExpandChromaPicture[0]   = ExpandPictureChroma_c;
354   pExpandPicFunc->pfExpandChromaPicture[1]   = ExpandPictureChroma_c;
355 
356 #if defined(X86_ASM)
357   if ((kuiCPUFlag & WELS_CPU_SSE2) == WELS_CPU_SSE2) {
358     pExpandPicFunc->pfExpandLumaPicture      = ExpandPictureLuma_sse2;
359     pExpandPicFunc->pfExpandChromaPicture[0] = ExpandPictureChromaUnalign_sse2;
360     pExpandPicFunc->pfExpandChromaPicture[1] = ExpandPictureChromaAlign_sse2;
361   }
362 #endif//X86_ASM
363 #if defined(HAVE_NEON)
364   if (kuiCPUFlag & WELS_CPU_NEON) {
365     pExpandPicFunc->pfExpandLumaPicture      = ExpandPictureLuma_neon;
366     pExpandPicFunc->pfExpandChromaPicture[0] = ExpandPictureChroma_neon;
367     pExpandPicFunc->pfExpandChromaPicture[1] = ExpandPictureChroma_neon;
368   }
369 #endif//HAVE_NEON
370 #if defined(HAVE_NEON_AARCH64)
371   if (kuiCPUFlag & WELS_CPU_NEON) {
372     pExpandPicFunc->pfExpandLumaPicture      = ExpandPictureLuma_AArch64_neon;
373     pExpandPicFunc->pfExpandChromaPicture[0] = ExpandPictureChroma_AArch64_neon;
374     pExpandPicFunc->pfExpandChromaPicture[1] = ExpandPictureChroma_AArch64_neon;
375   }
376 #endif//HAVE_NEON_AARCH64
377 #if defined(HAVE_MMI)
378   if (kuiCPUFlag & WELS_CPU_MMI) {
379     pExpandPicFunc->pfExpandLumaPicture      = ExpandPictureLuma_mmi;
380     pExpandPicFunc->pfExpandChromaPicture[0] = ExpandPictureChromaUnalign_mmi;
381     pExpandPicFunc->pfExpandChromaPicture[1] = ExpandPictureChromaAlign_mmi;
382   }
383 #endif//HAVE_MMI
384 }
385 
386 
387 //void ExpandReferencingPicture (SPicture* pPic, PExpandPictureFunc pExpLuma, PExpandPictureFunc pExpChrom[2]) {
ExpandReferencingPicture(uint8_t * pData[3],int32_t iWidth,int32_t iHeight,int32_t iStride[3],PExpandPictureFunc pExpLuma,PExpandPictureFunc pExpChrom[2])388 void ExpandReferencingPicture (uint8_t* pData[3], int32_t iWidth, int32_t iHeight, int32_t iStride[3],
389                                PExpandPictureFunc pExpLuma, PExpandPictureFunc pExpChrom[2]) {
390   /*local variable*/
391   uint8_t* pPicY  = pData[0];
392   uint8_t* pPicCb = pData[1];
393   uint8_t* pPicCr = pData[2];
394   const int32_t kiWidthY    = iWidth;
395   const int32_t kiHeightY   = iHeight;
396   const int32_t kiWidthUV   = kiWidthY >> 1;
397   const int32_t kiHeightUV  = kiHeightY >> 1;
398 
399 
400 
401   pExpLuma (pPicY, iStride[0], kiWidthY, kiHeightY);
402   if (kiWidthUV >= 16) {
403     // fix coding picture size as 16x16
404     const bool kbChrAligned = /*(iWidthUV >= 16) && */ ((kiWidthUV & 0x0F) == 0); // chroma planes: (16+iWidthUV) & 15
405     pExpChrom[kbChrAligned] (pPicCb, iStride[1], kiWidthUV, kiHeightUV);
406     pExpChrom[kbChrAligned] (pPicCr, iStride[2], kiWidthUV, kiHeightUV);
407   } else {
408     // fix coding picture size as 16x16
409     ExpandPictureChroma_c (pPicCb, iStride[1], kiWidthUV, kiHeightUV);
410     ExpandPictureChroma_c (pPicCr, iStride[2], kiWidthUV, kiHeightUV);
411   }
412 
413 
414 
415 }
416