@@ -61,11 +61,11 @@ public YuvConverter(HeicImageFrame picture)
6161 public final byte [][][] getRgbaByteArray ()
6262 {
6363 /*UInt32*/
64- long width = picture .hvcConfig .getSPS ().pic_width_in_luma_samples ;
64+ int width = ( int ) ( picture .hvcConfig .getSPS ().pic_width_in_luma_samples & 0xFFFFFFFFL ) ;
6565 /*UInt32*/
66- long height = picture .hvcConfig .getSPS ().pic_height_in_luma_samples ;
66+ int height = ( int ) ( picture .hvcConfig .getSPS ().pic_height_in_luma_samples & 0xFFFFFFFFL ) ;
6767
68- byte [][][] pixels = new byte [( int ) ( width & 0xFFFFFFFFL )][( int ) ( height & 0xFFFFFFFFL ) ][4 ];
68+ byte [][][] pixels = new byte [width ][ height ][4 ];
6969
7070 if (picture .rawPixels == null )
7171 return pixels ;
@@ -82,10 +82,16 @@ public final byte[][][] getRgbaByteArray()
8282 // conversion to 8 bit
8383 double BitKoefY = 256.0 / (1 << (picture .hvcConfig .getSPS ().getBitDepthY () & 0xFF ));
8484 double BitKoefC = 256.0 / (1 << (picture .hvcConfig .getSPS ().getBitDepthC () & 0xFF ));
85-
86- for (int row = 0 ; row < (height & 0xFFFFFFFFL ); row ++)
85+ final boolean isNotChroma = (picture .hvcConfig .getSPS ()
86+ .getChromaArrayType () & 0xFFFFFFFFL ) == 0 ;
87+ final int configSpsSubWidthC = picture .hvcConfig .getSPS ()
88+ .getSubWidthC () & 0xFF ;
89+ final int configSpsSubHeightC = picture .hvcConfig .getSPS ()
90+ .getSubHeightC () & 0xFF ;
91+
92+ for (int row = 0 ; row < height ; row ++)
8793 {
88- for (int col = 0 ; col < ( width & 0xFFFFFFFFL ) ; col ++)
94+ for (int col = 0 ; col < width ; col ++)
8995 {
9096 Y = picture .rawPixels [0 ][col ][row ] & 0xFFFF ;
9197
@@ -94,16 +100,16 @@ public final byte[][][] getRgbaByteArray()
94100 Y = tvRangeCoeffLuma * (Y - lumaOffset );
95101 }
96102
97- if (( picture . hvcConfig . getSPS (). getChromaArrayType () & 0xFFFFFFFFL ) == 0 )
103+ if (isNotChroma )
98104 {
99105 R = Y ;
100106 G = Y ;
101107 B = Y ;
102108 }
103109 else
104110 {
105- Cb = (picture .rawPixels [1 ][col / ( picture . hvcConfig . getSPS (). getSubWidthC () & 0xFF ) ][row / ( picture . hvcConfig . getSPS (). getSubHeightC () & 0xFF ) ] & 0xFFFF ) - chromaHalfRange ;
106- Cr = (picture .rawPixels [2 ][col / ( picture . hvcConfig . getSPS (). getSubWidthC () & 0xFF ) ][row / ( picture . hvcConfig . getSPS (). getSubHeightC () & 0xFF ) ] & 0xFFFF ) - chromaHalfRange ;
111+ Cb = (picture .rawPixels [1 ][col / configSpsSubWidthC ][row / configSpsSubHeightC ] & 0xFFFF ) - chromaHalfRange ;
112+ Cr = (picture .rawPixels [2 ][col / configSpsSubWidthC ][row / configSpsSubHeightC ] & 0xFFFF ) - chromaHalfRange ;
107113
108114 if (!fullRangeFlag )
109115 {
@@ -191,12 +197,14 @@ private void defineCoefficients(vui_parameters vui_parameters)
191197 double zB = 1 - (p .xB + p .yB );
192198 double zW = 1 - (p .xW + p .yW );
193199
194- double denom = p .yW * (p .xR * (p .yG * zB - p .yB * zG ) + p .xG * (p .yB * zR - p .yR * zB ) + p .xB * (p .yR * zG - p .yG * zR ));
200+ final double tmpGmB_BmG = p .yG * zB - p .yB * zG ;
201+ final double tmpRmG_GmR = p .yR * zG - p .yG * zR ;
202+ double denom = p .yW * (p .xR * tmpGmB_BmG + p .xG * (p .yB * zR - p .yR * zB ) + p .xB * tmpRmG_GmR );
195203
196204 try
197205 {
198- kr = (p .yR * (p .xW * ( p . yG * zB - p . yB * zG ) + p .yW * (p .xB * zG - p .xG * zB ) + zW * (p .xG * p .yB - p .xB * p .yG ))) / denom ;
199- kb = (p .yB * (p .xW * ( p . yR * zG - p . yG * zR ) + p .yW * (p .xG * zR - p .xR * zG ) + zW * (p .xR * p .yG - p .xG * p .yR ))) / denom ;
206+ kr = (p .yR * (p .xW * tmpGmB_BmG + p .yW * (p .xB * zG - p .xG * zB ) + zW * (p .xG * p .yB - p .xB * p .yG ))) / denom ;
207+ kb = (p .yB * (p .xW * tmpRmG_GmR + p .yW * (p .xG * zR - p .xR * zG ) + zW * (p .xR * p .yG - p .xG * p .yR ))) / denom ;
200208 }
201209 catch (java .lang .RuntimeException e )
202210 {
0 commit comments