pull/1/head
parent
c429a99972
commit
9c912e925b
@ -1,54 +0,0 @@ |
||||
package com.flurgle.camerakit; |
||||
|
||||
import android.graphics.YuvImage; |
||||
import android.hardware.Camera; |
||||
|
||||
class ProcessStillTask implements Runnable { |
||||
|
||||
private byte[] data; |
||||
private Camera camera; |
||||
private int rotation; |
||||
private OnStillProcessedListener onStillProcessedListener; |
||||
|
||||
public ProcessStillTask(byte[] data, Camera camera, int rotation, OnStillProcessedListener onStillProcessedListener) { |
||||
this.data = data; |
||||
this.camera = camera; |
||||
this.rotation = rotation; |
||||
this.onStillProcessedListener = onStillProcessedListener; |
||||
} |
||||
|
||||
@Override |
||||
public void run() { |
||||
Camera.Parameters parameters = camera.getParameters(); |
||||
int width = parameters.getPreviewSize().width; |
||||
int height = parameters.getPreviewSize().height; |
||||
byte[] rotatedData = new Rotation(data, width, height, rotation).getYuv(); |
||||
|
||||
int postWidth; |
||||
int postHeight; |
||||
|
||||
switch (rotation) { |
||||
case 90: |
||||
case 270: |
||||
postWidth = height; |
||||
postHeight = width; |
||||
break; |
||||
|
||||
case 0: |
||||
case 180: |
||||
default: |
||||
postWidth = width; |
||||
postHeight = height; |
||||
break; |
||||
} |
||||
|
||||
YuvImage yuv = new YuvImage(rotatedData, parameters.getPreviewFormat(), postWidth, postHeight, null); |
||||
|
||||
onStillProcessedListener.onStillProcessed(yuv); |
||||
} |
||||
|
||||
interface OnStillProcessedListener { |
||||
void onStillProcessed(YuvImage yuv); |
||||
} |
||||
|
||||
} |
@ -1,50 +0,0 @@ |
||||
package com.flurgle.camerakit; |
||||
|
||||
public class Rotation { |
||||
|
||||
private byte[] rotatedYuv; |
||||
|
||||
public Rotation(final byte[] yuv, final int width, final int height, final int rotation) { |
||||
if (rotation == 0) this.rotatedYuv = yuv; |
||||
if (rotation % 90 != 0 || rotation < 0 || rotation > 270) { |
||||
throw new IllegalArgumentException("0 <= rotation < 360, rotation % 90 == 0"); |
||||
} |
||||
|
||||
final byte[] output = new byte[yuv.length]; |
||||
final int frameSize = width * height; |
||||
final boolean swap = rotation % 180 != 0; |
||||
final boolean xflip = rotation % 270 != 0; |
||||
final boolean yflip = rotation >= 180; |
||||
|
||||
for (int j = 0; j < height; j++) { |
||||
for (int i = 0; i < width; i++) { |
||||
final int yIn = j * width + i; |
||||
final int uIn = frameSize + (j >> 1) * width + (i & ~1); |
||||
final int vIn = uIn + 1; |
||||
|
||||
final int wOut = swap ? height : width; |
||||
final int hOut = swap ? width : height; |
||||
final int iSwapped = swap ? j : i; |
||||
final int jSwapped = swap ? i : j; |
||||
final int iOut = xflip ? wOut - iSwapped - 1 : iSwapped; |
||||
final int jOut = yflip ? hOut - jSwapped - 1 : jSwapped; |
||||
|
||||
final int yOut = jOut * wOut + iOut; |
||||
final int uOut = frameSize + (jOut >> 1) * wOut + (iOut & ~1); |
||||
final int vOut = uOut + 1; |
||||
|
||||
output[yOut] = (byte) (0xff & yuv[yIn]); |
||||
output[uOut] = (byte) (0xff & yuv[uIn]); |
||||
output[vOut] = (byte) (0xff & yuv[vIn]); |
||||
} |
||||
} |
||||
|
||||
this.rotatedYuv = output; |
||||
} |
||||
|
||||
public byte[] getYuv() { |
||||
return this.rotatedYuv; |
||||
} |
||||
|
||||
} |
||||
|
Loading…
Reference in new issue