for一:
private byte[] cropYUV420SemiPlannerFrame(byte[] input, int iw, int ih, byte[] output, int ow, int oh) {
int iFrameSize = iw * ih;
int oFrameSize = ow * oh;
int i = 0;
for (int row = (ih - oh) / 2; row < oh + (ih - oh) / 2; row++) {
for (int col = (iw - ow) / 2; col < ow + (iw - ow) / 2; col++) {
output[i++] = input[iw * row + col]; // Y
}
}
i = 0;
for (int row = (ih - oh) / 4; row < oh / 2 + (ih - oh) / 4; row++) {
for (int col = (iw - ow) / 4; col < ow / 2 + (iw - ow) / 4; col++) {
output[oFrameSize + 2 * i] = input[iFrameSize + iw * row + 2 * col]; // U
output[oFrameSize + 2 * i + 1] = input[iFrameSize + iw * row + 2 * col + 1]; // V
i++;
}
}
return output;
}
for二:
private byte[] cropYUV420PlannerFrame(byte[] input, int iw, int ih, byte[] output, int ow, int oh) {
int iFrameSize = iw * ih;
int iQFrameSize = iFrameSize / 4;
int oFrameSize = ow * oh;
int oQFrameSize = oFrameSize / 4;
int i = 0;
for (int row = (ih - oh) / 2; row < oh + (ih - oh) / 2; row++) {
for (int col = (iw - ow) / 2; col < ow + (iw - ow) / 2; col++) {
output[i++] = input[iw * row + col]; // Y
}
}
i = 0;
for (int row = (ih - oh) / 4; row < oh / 2 + (ih - oh) / 4; row++) {
for (int col = (iw - ow) / 4; col < ow / 2 + (iw - ow) / 4; col++) {
output[oFrameSize + i] = input[iFrameSize + iw / 2 * row + col]; // U
i++;
}
}
i = 0;
for (int row = (ih - oh) / 4; row < oh / 2 + (ih - oh) / 4; row++) {
for (int col = (iw - ow) / 4; col < ow / 2 + (iw - ow) / 4; col++) {
output[oFrameSize + oQFrameSize + i] = input[iFrameSize + iQFrameSize + iw / 2 * row + col]; // V
i++;
}
}
return output;
}
for三:
private byte[] rotateYUV420SemiPlannerFrame(byte[] input, byte[] output, int width, int height) {
int frameSize = width * height;
int i = 0;
for (int col = 0; col < width; col++) {
for (int row = height - 1; row >= 0; row--) {
output[i++] = input[width * row + col]; // Y
}
}
i = 0;
for (int col = 0; col < width / 2; col++) {
for (int row = height / 2 - 1; row >= 0; row--) {
output[frameSize + i * 2 + 1] = input[frameSize + width * row + col * 2]; // Cb (U)
output[frameSize + i * 2] = input[frameSize + width * row + col * 2 + 1]; // Cr (V)
i++;
}
}
return output;
}
for四:
private byte[] rotateYUV420PlannerFrame(byte[] input, byte[] output, int width, int height) {
int frameSize = width * height;
int qFrameSize = frameSize / 4;
int i = 0;
for (int col = 0; col < width; col++) {
for (int row = height - 1; row >= 0; row--) {
output[i++] = input[width * row + col]; // Y
}
}
i = 0;
for (int col = 0; col < width / 2; col++) {
for (int row = height / 2 - 1; row >= 0; row--) {
output[frameSize + i] = input[frameSize + qFrameSize + width / 2 * row + col]; // Cb (U)
i++;
}
}
i = 0;
for (int col = 0; col < width / 2; col++) {
for (int row = height / 2 - 1; row >= 0; row--) {
output[frameSize + qFrameSize + i] = input[frameSize + width / 2 * row + col]; // Cr (V)
i++;
}
}
return output;
}
for五:
private byte[] unrotateYUV420SemiPlannerFrame(byte[] input, byte[] output, int width, int height) {
int frameSize = width * height;
int i = 0;
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
output[i++] = input[width * row + col]; // Y
}
}
i = 0;
for (int row = 0; row < height / 2; row++) {
for (int col = 0; col < width / 2; col++) {
output[frameSize + i * 2 + 1] = input[frameSize + width * row + col * 2]; // Cb (U)
output[frameSize + i * 2] = input[frameSize + width * row + col * 2 + 1]; // Cr (V)
i++;
}
}
return output;
}
for六:
private byte[] unrotateYUV420PlannerFrame(byte[] input, byte[] output, int width, int height) {
int frameSize = width * height;
int qFrameSize = frameSize / 4;
int i = 0;
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
output[i++] = input[width * row + col]; // Y
}
}
i = 0;
for (int row = 0; row < height / 2; row++) {
for (int col = 0; col < width / 2; col++) {
output[frameSize + i] = input[frameSize + qFrameSize + width / 2 * row + col]; // Cb (U)
i++;
}
}
i = 0;
for (int row = 0; row < height / 2; row++) {
for (int col = 0; col < width / 2; col++) {
output[frameSize + qFrameSize + i] = input[frameSize + width / 2 * row + col]; // Cr (V)
i++;
}
}
return output;
}
for七:
private byte[] flipYUV420SemiPlannerFrame(byte[] input, byte[] output, int width, int height) {
int frameSize = width * height;
int i = 0;
for (int row = 0; row < height; row++) {
for (int col = width - 1; col >= 0; col--) {
output[i++] = input[width * row + col]; // Y
}
}
i = 0;
for (int row = 0; row < height / 2; row++) {
for (int col = width / 2 - 1; col >= 0; col--) {
output[frameSize + i * 2] = input[frameSize + width * row + col * 2]; // Cb (U)
output[frameSize + i * 2 + 1] = input[frameSize + width * row + col * 2 + 1]; // Cr (V)
i++;
}
}
return output;
}
for八:
private byte[] flipYUV420PlannerFrame(byte[] input, byte[] output, int width, int height) {
int frameSize = width * height;
int qFrameSize = frameSize / 4;
int i = 0;
for (int row = 0; row < height; row++) {
for (int col = width - 1; col >= 0; col--) {
output[i++] = input[width * row + col]; // Y
}
}
i = 0;
for (int row = 0; row < height / 2; row++) {
for (int col = width / 2 - 1; col >= 0; col--) {
output[frameSize + i] = input[frameSize + width / 2 * row + col]; // Cr (V)
i++;
}
}
i = 0;
for (int row = 0; row < height / 2; row++) {
for (int col = width / 2 - 1; col >= 0; col--) {
output[frameSize + qFrameSize + i] = input[frameSize + qFrameSize + width / 2 * row + col]; // Cb (U)
i++;
}
}
return output;
}
本人只会把乘除法改为移位运算,但速度还是不够快,请大家帮忙,先谢谢了.
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课