Last active
July 4, 2018 09:57
-
-
Save Pikaurd/cfa52356e30f851ca2fdc29947bf836d to your computer and use it in GitHub Desktop.
Resize nv12 raw data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] nv12ScaleDown(byte[] bytes, int width, int height) { | |
int newWidth = width >> 1; | |
int newHeight = height >> 1; | |
byte []result = new byte[bytes.length >> 2]; | |
final int sourceOffset = width * height; | |
final int destOffset = newWidth * newHeight; | |
for (int h = 0; h < newHeight; h++) { | |
for (int w = 0; w < newWidth; w++) { | |
// manipulate y | |
byte sourceY = bytes[(w << 1) + h * (width << 1)]; | |
result[w + h * newWidth] = sourceY; | |
// manipulate uv | |
if ((w & 0x1) == 0 && (h & 0x1) == 0) { | |
int indexSourceU = (w << 1) + h * width + sourceOffset; | |
int indexSourceV = indexSourceU + 1; | |
int indexDestU = w + (h >> 1) * newWidth + destOffset; | |
result[indexDestU] = bytes[indexSourceU]; | |
result[indexDestU + 1] = bytes[indexSourceV]; | |
} | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment