Files
MAG160C/analysis/jadx_magcx/cn/com/magnity/magnitycx/ImageViewer.java
T

960 lines
41 KiB
Java

package cn.com.magnity.magnitycx;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import cn.com.magnity.magnitycx.FragmentMainCenter;
import cn.com.magnity.magnitycx.log.Logging;
import cn.com.magnity.magnitycx.sdk.DeviceController;
import cn.com.magnity.magnitycx.sdk.MagParameter;
import cn.com.magnity.magnitycx.sdk.SharedPreferencesManager;
import cn.com.magnity.magnitycx.sdk.State;
import cn.com.magnity.magnitycx.sdk.TimerHelper;
import cn.com.magnity.magnitycx.sdk.UsbCommunication;
import cn.com.magnity.magnitycx.sdk.WaitCondition;
import com.baidu.mobstat.Config;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/* loaded from: classes.dex */
public class ImageViewer extends SurfaceView implements SurfaceHolder.Callback, UsbCommunication.DelegateNewFrame, FragmentMainCenter.DelegateCapture {
private static final int MAX_ROI_NUM = 1;
private int aimOrientation_;
private int aimX_;
private int aimY_;
private Bitmap bmpIr_;
private Canvas cachedCanvas_;
private Bitmap cachedbmp_;
private WaitCondition condRecording_;
private int dx_;
private int dy_;
private volatile int fpaHeight_;
private volatile int fpaWidth_;
private int frameIndex_;
private int height_;
private SurfaceHolder holder_;
private volatile int imageStableCounter_;
private boolean isAimDrag_;
private volatile boolean isExitThreadRecording_;
private volatile boolean isExitThreadRender_;
private volatile boolean isTempStable_;
private ArrayList<ROIInfo> listRoi_;
private Matrix matrixVGA_;
private Matrix matrix_;
private Paint paintROIVGA_;
private Paint paintROI_;
private Paint paintVGA_;
private Paint paint_;
private PaintFlagsDrawFilter pfd_;
private AtomicLong recordingTimeElapsed_;
private volatile ThreadLocalParam threadLocalParam_;
private ThreadRecording threadRecording_;
private ThreadRender threadRender_;
private TimerHelper timerHelper_;
private WaitCondition waitCondition_;
private int width_;
private static volatile Lock lock_ = new ReentrantLock();
private static volatile long[] ticks_ = new long[20];
private static Object syncNotifyNewFrame_ = new Object();
private static ArrayList<ImageViewer> imgViewerList_ = new ArrayList<>();
private class ThreadLocalParam implements Cloneable {
int centerTemp;
State state;
private ThreadLocalParam() {
}
public Object clone() throws CloneNotSupportedException {
ThreadLocalParam param = (ThreadLocalParam) super.clone();
if (this.state != null) {
param.state = (State) this.state.clone();
}
return param;
}
}
private class OSDParam {
private Bitmap crossLogo_;
private Bitmap laserLogo_;
private Bitmap maxTrace_;
private Bitmap minTrace_;
private Bitmap moveingCrossLogo_;
private Bitmap waterMark_;
private OSDParam() {
}
public Bitmap getCrossLogo() {
return this.crossLogo_;
}
public Bitmap getWaterMark() {
return this.waterMark_;
}
public Bitmap getMinTrace() {
return this.minTrace_;
}
public Bitmap getMaxTrace() {
return this.maxTrace_;
}
public Bitmap getMovingCrossLogo() {
return this.moveingCrossLogo_;
}
public Bitmap getLaserLogo() {
return this.laserLogo_;
}
public void setCrossLogo(int id) {
this.crossLogo_ = BitmapFactory.decodeResource(ImageViewer.this.getResources(), id);
}
public void setWaterMark(int id) {
this.waterMark_ = BitmapFactory.decodeResource(ImageViewer.this.getResources(), id);
}
public void setMinTrace(int id) {
this.minTrace_ = BitmapFactory.decodeResource(ImageViewer.this.getResources(), id);
}
public void setMaxTrace(int id) {
this.maxTrace_ = BitmapFactory.decodeResource(ImageViewer.this.getResources(), id);
}
public void setMovingCrossLogo(int id) {
this.moveingCrossLogo_ = BitmapFactory.decodeResource(ImageViewer.this.getResources(), id);
}
public void setLaserLogo(int id) {
this.laserLogo_ = BitmapFactory.decodeResource(ImageViewer.this.getResources(), id);
}
/* JADX INFO: Access modifiers changed from: private */
public void reset() {
if (this.crossLogo_ != null && !this.crossLogo_.isRecycled()) {
this.crossLogo_.recycle();
this.crossLogo_ = null;
}
if (this.waterMark_ != null && !this.waterMark_.isRecycled()) {
this.waterMark_.recycle();
this.waterMark_ = null;
}
if (this.minTrace_ != null && !this.minTrace_.isRecycled()) {
this.minTrace_.recycle();
this.minTrace_ = null;
}
if (this.maxTrace_ != null && !this.maxTrace_.isRecycled()) {
this.maxTrace_.recycle();
this.maxTrace_ = null;
}
if (this.moveingCrossLogo_ != null && !this.moveingCrossLogo_.isRecycled()) {
this.moveingCrossLogo_.recycle();
this.moveingCrossLogo_ = null;
}
if (this.laserLogo_ != null && !this.laserLogo_.isRecycled()) {
this.laserLogo_.recycle();
this.laserLogo_ = null;
}
}
}
public void setTempStableFlag(boolean isStable) {
this.isTempStable_ = isStable;
}
public boolean getTempStableFlag() {
return this.isTempStable_;
}
public void setImageStableCounter(int counter) {
this.imageStableCounter_ = counter;
}
public int getImageStableCounter() {
return this.imageStableCounter_;
}
public ImageViewer(Context context, AttributeSet attrs) {
super(context, attrs);
this.waitCondition_ = new WaitCondition();
this.condRecording_ = new WaitCondition();
this.threadLocalParam_ = new ThreadLocalParam();
this.paint_ = new Paint(1);
this.matrix_ = new Matrix();
this.matrixVGA_ = new Matrix();
this.paintVGA_ = new Paint(1);
this.paintROI_ = new Paint(1);
this.paintROIVGA_ = new Paint(1);
this.listRoi_ = new ArrayList<>();
this.recordingTimeElapsed_ = new AtomicLong(0L);
this.holder_ = getHolder();
this.holder_.setFormat(-2);
this.holder_.addCallback(this);
this.timerHelper_ = new TimerHelper() { // from class: cn.com.magnity.magnitycx.ImageViewer.1
@Override // cn.com.magnity.magnitycx.sdk.TimerHelper
public void run() {
ImageViewer.this.recordingTimeElapsed_.getAndIncrement();
}
};
}
private void invalidate_() {
synchronized (this.waitCondition_.cond) {
this.waitCondition_.notified = true;
this.waitCondition_.cond.notify();
}
}
private void recordingOneFrame() {
synchronized (this.condRecording_.cond) {
this.condRecording_.notified = true;
this.condRecording_.cond.notify();
}
}
private void updateUiTemps(int fpaWidth, int fpaHeight) {
int pos;
switch (DeviceController.getPreviewOrientation()) {
case 0:
case 180:
pos = ((fpaHeight + 1) * fpaWidth) / 2;
break;
default:
pos = ((fpaWidth + 1) * fpaHeight) / 2;
break;
}
this.threadLocalParam_.centerTemp = DeviceController.getTemperature(pos, 1, false);
this.threadLocalParam_.state = DeviceController.getState();
ROIInfo.lock();
try {
Iterator<ROIInfo> it = this.listRoi_.iterator();
while (it.hasNext()) {
ROIInfo roiInfo = it.next();
switch (roiInfo.getType()) {
case 1:
int[] info = new int[5];
if (roiInfo.isBigEnouth() && DeviceController.getRectTemperatureInfo(roiInfo.getBeginPointX(), roiInfo.getBeginPointY(), roiInfo.getEndPointX(), roiInfo.getEndPointY(), info, false)) {
roiInfo.setTempInfo(info[0], info[1], info[2], info[3], info[4]);
break;
}
break;
}
}
} finally {
ROIInfo.unlock();
}
}
public void initData(int fpaWidth, int fpaHeight) {
this.fpaWidth_ = fpaWidth;
this.fpaHeight_ = fpaHeight;
if (this.bmpIr_ == null) {
this.bmpIr_ = Bitmap.createBitmap(fpaWidth, fpaHeight, Bitmap.Config.ARGB_8888);
} else if (this.bmpIr_.getWidth() != fpaWidth || this.bmpIr_.getHeight() != fpaHeight) {
if (!this.bmpIr_.isRecycled()) {
this.bmpIr_.recycle();
}
this.bmpIr_ = Bitmap.createBitmap(fpaWidth, fpaHeight, Bitmap.Config.ARGB_8888);
}
}
@Override // cn.com.magnity.magnitycx.sdk.UsbCommunication.DelegateNewFrame
public void onNewFrameReceived(int fpaTemp, int camTemp) {
DeviceController.Lock();
if (!DeviceController.getOutputBMPData(this.bmpIr_, this.fpaWidth_ * this.fpaHeight_ * 4)) {
DeviceController.Unlock();
return;
}
int i = this.frameIndex_;
this.frameIndex_ = i + 1;
if ((i & 7) == 0) {
updateUiTemps(this.fpaWidth_, this.fpaHeight_);
}
DeviceController.Unlock();
if (DeviceController.isRecording()) {
recordingOneFrame();
}
invalidate_();
}
private void calculateScreenFit() {
int width;
int height;
int width2 = getWidth();
int height2 = getHeight();
if (getResources().getConfiguration().orientation == 1) {
if (width2 * 4 > height2 * 3) {
height = (height2 / 12) * 12;
width = (height * 3) / 4;
} else {
width = (width2 / 12) * 12;
height = (width * 4) / 3;
}
} else if (width2 * 3 > height2 * 4) {
height = (height2 / 12) * 12;
width = (height * 4) / 3;
} else {
width = (width2 / 12) * 12;
height = (width * 3) / 4;
}
this.dx_ = (getWidth() - width) / 2;
this.dy_ = (getHeight() - height) / 2;
this.width_ = width;
this.height_ = height;
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceCreated(SurfaceHolder holder) {
if (this.cachedbmp_ == null) {
switch (DeviceController.getPreviewOrientation()) {
case 0:
case 180:
this.cachedbmp_ = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);
break;
case 90:
case 270:
this.cachedbmp_ = Bitmap.createBitmap(480, 640, Bitmap.Config.ARGB_8888);
break;
}
}
if (this.cachedCanvas_ == null) {
this.cachedCanvas_ = new Canvas();
this.cachedCanvas_.setBitmap(this.cachedbmp_);
}
Canvas canvas = this.holder_.lockCanvas();
if (canvas != null) {
this.paint_.setTextSize(getResources().getDimensionPixelSize(R.dimen.liveTemperatureTextSize));
this.paint_.setTypeface(Typeface.SANS_SERIF);
this.paint_.setTextAlign(Paint.Align.LEFT);
this.paint_.setColor(getResources().getColor(R.color.liveBackground));
canvas.drawRect(0.0f, 0.0f, getWidth(), getHeight(), this.paint_);
this.holder_.unlockCanvasAndPost(canvas);
this.paint_.setColor(getResources().getColor(R.color.textColor));
this.paint_.setStyle(Paint.Style.FILL_AND_STROKE);
this.paint_.setStrokeWidth(2.0f);
this.paint_.setShadowLayer(12.0f, 0.0f, 0.0f, getResources().getColor(R.color.black));
this.paintVGA_.setTextSize(getResources().getDimensionPixelSize(R.dimen.recordingTemperatureTextSize));
this.paintVGA_.setTypeface(Typeface.SANS_SERIF);
this.paintVGA_.setTextAlign(Paint.Align.LEFT);
this.paintVGA_.setColor(getResources().getColor(R.color.textColor));
this.paintVGA_.setStyle(Paint.Style.FILL_AND_STROKE);
this.paintVGA_.setStrokeWidth(1.0f);
this.paintVGA_.setShadowLayer(6.0f, 0.0f, 0.0f, getResources().getColor(R.color.black));
this.paintROI_.setColor(getResources().getColor(R.color.roiColor));
this.paintROI_.setStyle(Paint.Style.STROKE);
this.paintROI_.setStrokeWidth(4.0f);
this.paintROI_.setShadowLayer(6.0f, 0.0f, 0.0f, getResources().getColor(R.color.black));
this.paintROIVGA_.setColor(getResources().getColor(R.color.roiColor));
this.paintROIVGA_.setStyle(Paint.Style.STROKE);
this.paintROIVGA_.setStrokeWidth(2.0f);
this.paintROIVGA_.setShadowLayer(2.0f, 0.0f, 0.0f, getResources().getColor(R.color.black));
}
this.pfd_ = new PaintFlagsDrawFilter(0, 3);
synchronized (syncNotifyNewFrame_) {
imgViewerList_.add(this);
}
calculateScreenFit();
this.aimOrientation_ = getResources().getConfiguration().orientation;
if (this.aimOrientation_ == 1) {
this.aimX_ = SharedPreferencesManager.getInt("aimX_portrait", getWidth() / 2);
this.aimY_ = SharedPreferencesManager.getInt("aimY_portrait", getHeight() / 2);
} else {
this.aimX_ = SharedPreferencesManager.getInt("aimX_landscape", getWidth() / 2);
this.aimY_ = SharedPreferencesManager.getInt("aimY_landscape", getHeight() / 2);
}
DeviceController.setColorbarSize(100, 20);
DeviceController.setColorPalette(SharedPreferencesManager.getInt("paletteIndex", 2));
this.threadRender_ = new ThreadRender();
this.isExitThreadRender_ = false;
this.waitCondition_.notified = false;
this.threadRender_.start();
this.threadRecording_ = new ThreadRecording();
this.isExitThreadRecording_ = false;
this.condRecording_.notified = false;
this.threadRecording_.start();
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
calculateScreenFit();
}
@Override // android.view.SurfaceHolder.Callback
public void surfaceDestroyed(SurfaceHolder holder) {
if (this.aimOrientation_ == 1) {
SharedPreferencesManager.putInt("aimX_portrait", this.aimX_);
SharedPreferencesManager.putIntWithCommit("aimY_portrait", this.aimY_);
} else {
SharedPreferencesManager.putInt("aimX_landscape", this.aimX_);
SharedPreferencesManager.putIntWithCommit("aimY_landscape", this.aimY_);
}
this.isExitThreadRender_ = true;
synchronized (this.waitCondition_.cond) {
this.waitCondition_.notified = true;
this.waitCondition_.cond.notify();
}
try {
this.threadRender_.join();
this.threadRender_ = null;
} catch (InterruptedException e) {
}
this.isExitThreadRecording_ = true;
synchronized (this.condRecording_.cond) {
this.condRecording_.notified = true;
this.condRecording_.cond.notify();
}
try {
this.threadRecording_.join();
this.threadRecording_ = null;
} catch (InterruptedException e2) {
}
synchronized (syncNotifyNewFrame_) {
imgViewerList_.remove(this);
}
this.cachedCanvas_ = null;
if (!this.cachedbmp_.isRecycled()) {
this.cachedbmp_.recycle();
this.cachedbmp_ = null;
}
}
@Override // cn.com.magnity.magnitycx.FragmentMainCenter.DelegateCapture
public boolean onStartRecording(String pathName) {
boolean ret = DeviceController.startRecording(pathName, this.cachedbmp_.getWidth(), this.cachedbmp_.getHeight(), 2048, 20, 5);
this.recordingTimeElapsed_.set(0L);
this.timerHelper_.start(1000L, 1000L);
return ret;
}
@Override // cn.com.magnity.magnitycx.FragmentMainCenter.DelegateCapture
public void onStopRecording() {
this.timerHelper_.stop();
if (DeviceController.isRecording()) {
DeviceController.stopRecording();
}
}
@Override // cn.com.magnity.magnitycx.FragmentMainCenter.DelegateCapture
public Bitmap onCapture() {
OSDParam osdParam = new OSDParam();
osdParam.setCrossLogo(R.mipmap.cross_capture);
osdParam.setWaterMark(R.mipmap.water_mark);
osdParam.setMinTrace(R.mipmap.min_trace_capture);
osdParam.setMaxTrace(R.mipmap.max_trace_capture);
DeviceController.Lock();
updateUiTemps(this.fpaWidth_, this.fpaHeight_);
DeviceController.Unlock();
drawImage(this.cachedCanvas_, this.paintVGA_, this.paintROIVGA_, this.matrixVGA_, 0, 0, this.cachedbmp_.getWidth(), this.cachedbmp_.getHeight(), osdParam);
return this.cachedbmp_;
}
@Override // cn.com.magnity.magnitycx.FragmentMainCenter.DelegateCapture
public void onCaptureFinished(String pathName) {
}
@Override // android.view.View
public boolean onTouchEvent(MotionEvent event) {
boolean z = false;
if (!DeviceController.isProcessImage()) {
return false;
}
switch (event.getActionMasked()) {
case 0:
if (MagApplication.magParameter.isTraceRoi) {
int[] coor = DeviceController.screenXY2ClientXY(((int) event.getX()) - this.dx_, ((int) event.getY()) - this.dy_, this.width_, this.height_);
boolean isPointInROI = false;
ROIInfo.lock();
try {
Iterator<ROIInfo> it = this.listRoi_.iterator();
while (true) {
if (it.hasNext()) {
if (it.next().isPointIn(coor[0], coor[1])) {
it.remove();
isPointInROI = true;
}
}
}
if (!isPointInROI && this.listRoi_.size() > 0) {
this.listRoi_.remove(0);
}
ROIInfo.unlock();
ROIInfo roiInfo = new ROIInfo(1);
roiInfo.setBeginPoint(coor[0], coor[1]);
roiInfo.setEndPoint(coor[0], coor[1]);
ROIInfo.lock();
try {
this.listRoi_.add(roiInfo);
return true;
} finally {
}
} finally {
}
}
if (MagApplication.magParameter.basePara1.devType != 1 || !MagApplication.magParameter.isShowMovingCross || event.getX() <= this.aimX_ - 48 || event.getX() >= this.aimX_ + 48 || event.getY() <= this.aimY_ - 48 || event.getY() >= this.aimY_ + 48) {
return false;
}
this.isAimDrag_ = true;
return true;
case 1:
if (MagApplication.magParameter.isTraceRoi) {
int num = this.listRoi_.size();
if (num < 1) {
return false;
}
ROIInfo roiInfo2 = this.listRoi_.get(num - 1);
int[] coor2 = DeviceController.screenXY2ClientXY(((int) event.getX()) - this.dx_, ((int) event.getY()) - this.dy_, this.width_, this.height_);
ROIInfo.lock();
try {
roiInfo2.setEndPoint(coor2[0], coor2[1]);
if (!roiInfo2.isBigEnouth()) {
this.listRoi_.remove(num - 1);
} else {
roiInfo2.setFinished();
ROIInfo.unlock();
invalidate_();
z = true;
}
return z;
} finally {
}
}
if (!this.isAimDrag_) {
return false;
}
this.isAimDrag_ = false;
invalidate_();
return true;
case 2:
if (MagApplication.magParameter.isTraceRoi) {
int num2 = this.listRoi_.size();
if (num2 < 1) {
return false;
}
ROIInfo roiInfo3 = this.listRoi_.get(num2 - 1);
int[] coor3 = DeviceController.screenXY2ClientXY(((int) event.getX()) - this.dx_, ((int) event.getY()) - this.dy_, this.width_, this.height_);
if (!roiInfo3.isFinished()) {
ROIInfo.lock();
try {
roiInfo3.setEndPoint(coor3[0], coor3[1]);
} finally {
}
}
return true;
}
if (!this.isAimDrag_) {
return false;
}
this.aimX_ = (int) event.getX();
this.aimY_ = (int) event.getY();
if (this.aimX_ < this.dx_) {
this.aimX_ = this.dx_;
} else if (this.aimX_ > this.dx_ + this.width_) {
this.aimX_ = this.dx_ + this.width_;
}
if (this.aimY_ < this.dy_) {
this.aimY_ = this.dy_;
} else if (this.aimY_ > this.dy_ + this.height_) {
this.aimY_ = this.dy_ + this.height_;
}
invalidate_();
return true;
default:
return false;
}
}
/* JADX INFO: Access modifiers changed from: private */
public void doDraw(OSDParam param) {
Bitmap crossLogo;
Canvas canvas = this.holder_.lockCanvas();
if (canvas != null) {
drawImage(canvas, this.paint_, this.paintROI_, this.matrix_, this.dx_, this.dy_, this.width_, this.height_, param);
drawMarginBackground(canvas, this.paint_, this.dx_, this.dy_, this.width_, this.height_);
if (DeviceController.isRecording()) {
drawRecordingTime(canvas, this.paint_, this.dx_, this.dy_, this.width_, this.height_, this.recordingTimeElapsed_.get());
}
if (MagApplication.magParameter.basePara1.devType == 1 && (crossLogo = param.getMovingCrossLogo()) != null && MagApplication.magParameter.isShowMovingCross) {
canvas.drawBitmap(crossLogo, this.aimX_ - (crossLogo.getWidth() / 2), this.aimY_ - (crossLogo.getHeight() / 2), (Paint) null);
}
this.holder_.unlockCanvasAndPost(canvas);
}
}
private void drawFps(Canvas canvas, Paint paint, int dx, int dy, int width, int height, int recvFps, int showFps) {
Paint p = new Paint();
p.setColor(-16711936);
p.setTextSize(20.0f);
String s = String.format("接收帧率:%s", Integer.valueOf(recvFps));
Rect rect = new Rect();
p.getTextBounds(s, 0, s.length(), rect);
canvas.drawText(s, dx + 2, rect.height() + dy + 2, p);
canvas.drawText(String.format("显示帧率:%s", Integer.valueOf(showFps)), dx + 2, ((rect.height() + 2) * 2) + dy, p);
}
private void drawRecordingTime(Canvas canvas, Paint paint, int dx, int dy, int width, int height, long seconds) {
long hour = seconds / 3600;
long min = (seconds - (3600 * hour)) / 60;
long sec = (seconds - (3600 * hour)) - (60 * min);
String hms = String.format("%02d", Long.valueOf(hour)) + Config.TRACE_TODAY_VISIT_SPLIT + String.format("%02d", Long.valueOf(min)) + Config.TRACE_TODAY_VISIT_SPLIT + String.format("%02d", Long.valueOf(sec));
float oldFontSize = paint.getTextSize();
paint.setTextSize(getResources().getDimensionPixelSize(R.dimen.recordingTimeTextSize));
int oldFontColor = paint.getColor();
paint.setColor(getResources().getColor(R.color.highlightText));
Rect rect = new Rect();
paint.getTextBounds(hms + "8", 0, hms.length() + 1, rect);
canvas.drawText(hms, ((getWidth() - rect.width()) / 2) + dx, (dy + height) - 20, paint);
paint.setTextSize(oldFontSize);
paint.setColor(oldFontColor);
}
private void drawMarginBackground(Canvas canvas, Paint paint, int dx, int dy, int width, int height) {
int oldColor = paint.getColor();
paint.setColor(getResources().getColor(R.color.black));
canvas.drawRect(0.0f, 0.0f, dx, getHeight(), paint);
canvas.drawRect(0.0f, 0.0f, getWidth(), dy, paint);
canvas.drawRect(dx + width, 0.0f, getWidth(), getHeight(), paint);
canvas.drawRect(0.0f, dy + height, getWidth(), getHeight(), paint);
paint.setColor(oldColor);
}
private void drawROIs(Canvas canvas, Paint paint, Paint paintROI, Rect rect, int dx, int dy, int width, int height, OSDParam osdParam) {
String format;
int[] coor;
Bitmap maxTrace = osdParam.getMaxTrace();
Bitmap minTrace = osdParam.getMinTrace();
int traceType = MagApplication.magParameter.maxMinTrace;
if (this.isTempStable_) {
format = "%.1f℃";
} else {
format = "~%.1f℃";
}
int pad = maxTrace.getWidth() / 6;
ROIInfo.lock();
try {
Iterator<ROIInfo> it = this.listRoi_.iterator();
while (it.hasNext()) {
ROIInfo roiInfo = it.next();
switch (roiInfo.getType()) {
case 1:
int[] coor2 = DeviceController.clientXY2ScreenXY(roiInfo.getBeginPointX(), roiInfo.getBeginPointY(), width, height);
int[] coor22 = DeviceController.clientXY2ScreenXY(roiInfo.getEndPointX(), roiInfo.getEndPointY(), width, height);
canvas.drawRect(coor2[0] + dx, coor2[1] + dy, coor22[0] + dx, coor22[1] + dy, paintROI);
if (roiInfo.isBigEnouth() && roiInfo.isTempValid()) {
if ((traceType == 0 || traceType == 2 || traceType == -1) && (coor = DeviceController.clientPos2ScreenXY(roiInfo.getMaxPos(), width, height)) != null) {
canvas.drawBitmap(maxTrace, (coor[0] - (maxTrace.getWidth() / 2)) + dx, (coor[1] - (maxTrace.getHeight() / 2)) + dy, paint);
String str = String.format(format, Float.valueOf(roiInfo.getMaxTemp() * 0.001f));
paint.getTextBounds(str, 0, str.length(), rect);
int cx = rect.width();
int cy = rect.height();
int x = coor[0] + pad;
int y = coor[1] + cy + pad;
if (x > width - cx) {
x = (coor[0] - pad) - cx;
}
if (y > height) {
y = (coor[1] - pad) - cy;
}
canvas.drawText(str, x + dx, y + dy, paint);
}
if (traceType != 1 && traceType != 2) {
break;
} else {
int[] coor3 = DeviceController.clientPos2ScreenXY(roiInfo.getMinPos(), width, height);
if (coor3 == null) {
break;
} else {
canvas.drawBitmap(minTrace, (coor3[0] - (minTrace.getWidth() / 2)) + dx, (coor3[1] - (minTrace.getHeight() / 2)) + dy, paint);
String str2 = String.format(format, Float.valueOf(roiInfo.getMinTemp() * 0.001f));
paint.getTextBounds(str2, 0, str2.length(), rect);
int cx2 = rect.width();
int cy2 = rect.height();
int x2 = coor3[0] + pad;
int y2 = coor3[1] + cy2 + pad;
if (x2 > width - cx2) {
x2 = (coor3[0] - pad) - cx2;
}
if (y2 > height) {
y2 = (coor3[1] - pad) - cy2;
}
canvas.drawText(str2, x2 + dx, y2 + dy, paint);
break;
}
}
}
break;
}
}
} finally {
ROIInfo.unlock();
}
}
private void drawMaxMin(Canvas canvas, Paint paint, State state, Rect rect, int dx, int dy, int width, int height, OSDParam osdParam) {
String format;
int[] coor;
int[] coor2;
Bitmap maxTrace = osdParam.getMaxTrace();
Bitmap minTrace = osdParam.getMinTrace();
if (this.isTempStable_) {
format = "%.1f℃";
} else {
format = "~%.1f℃";
}
if (maxTrace != null && minTrace != null) {
int pad = maxTrace.getWidth() / 6;
int traceType = MagApplication.magParameter.maxMinTrace;
if ((traceType == 0 || traceType == 2) && (coor = DeviceController.clientXY2ScreenXY(state.intMaxX, state.intMaxY, width, height)) != null) {
canvas.drawBitmap(maxTrace, (coor[0] - (maxTrace.getWidth() / 2)) + dx, (coor[1] - (maxTrace.getHeight() / 2)) + dy, paint);
String str = String.format(format, Float.valueOf(state.intMaxTemperature * 0.001f));
paint.getTextBounds(str, 0, str.length(), rect);
int cx = rect.width();
int cy = rect.height();
int x = coor[0] + pad;
int y = coor[1] + cy + pad;
if (x > width - cx) {
x = (coor[0] - pad) - cx;
}
if (y > height) {
y = (coor[1] - pad) - cy;
}
canvas.drawText(str, x + dx, y + dy, paint);
}
if ((traceType == 1 || traceType == 2) && (coor2 = DeviceController.clientXY2ScreenXY(state.intMinX, state.intMinY, width, height)) != null) {
canvas.drawBitmap(minTrace, (coor2[0] - (minTrace.getWidth() / 2)) + dx, (coor2[1] - (minTrace.getHeight() / 2)) + dy, paint);
String str2 = String.format(format, Float.valueOf(state.intMinTemperature * 0.001f));
paint.getTextBounds(str2, 0, str2.length(), rect);
int cx2 = rect.width();
int cy2 = rect.height();
int x2 = coor2[0] + pad;
int y2 = coor2[1] + cy2 + pad;
if (x2 > width - cx2) {
x2 = (coor2[0] - pad) - cx2;
}
if (y2 > height) {
y2 = (coor2[1] - pad) - cy2;
}
canvas.drawText(str2, x2 + dx, y2 + dy, paint);
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public void drawImage(Canvas canvas, Paint paint, Paint paintROI, Matrix matrix, int dx, int dy, int width, int height, OSDParam osdParam) {
Bitmap laserLogo;
Bitmap crossLogo;
String str;
matrix.reset();
Rect rect = new Rect();
ThreadLocalParam param = null;
switch (DeviceController.getPreviewOrientation()) {
case 0:
float ratioX = width / this.fpaWidth_;
float ratioY = height / this.fpaHeight_;
matrix.postScale(ratioX, ratioY, 0.0f, 0.0f);
matrix.postTranslate(dx, dy);
break;
case 90:
float ratioX2 = width / this.fpaHeight_;
float ratioY2 = height / this.fpaWidth_;
matrix.postRotate(90.0f);
matrix.postTranslate(this.fpaHeight_ + dx, dy);
matrix.postScale(ratioX2, ratioY2, dx, dy);
break;
case 180:
float ratioX3 = width / this.fpaWidth_;
float ratioY3 = height / this.fpaHeight_;
matrix.postRotate(180.0f, this.fpaWidth_ / 2, this.fpaHeight_ / 2);
matrix.postTranslate(dx, dy);
matrix.postScale(ratioX3, ratioY3, dx, dy);
break;
case 270:
float ratioX4 = width / this.fpaHeight_;
float ratioY4 = height / this.fpaWidth_;
matrix.postRotate(-90.0f);
matrix.postTranslate(dx, this.fpaWidth_ + dy);
matrix.postScale(ratioX4, ratioY4, dx, dy);
break;
}
canvas.setDrawFilter(this.pfd_);
DeviceController.Lock();
canvas.drawBitmap(this.bmpIr_, matrix, null);
try {
param = (ThreadLocalParam) this.threadLocalParam_.clone();
} catch (CloneNotSupportedException e) {
} finally {
DeviceController.Unlock();
}
DeviceController.Unlock();
MagParameter magParameter = MagApplication.magParameter;
if (magParameter.isShowCross && (crossLogo = osdParam.getCrossLogo()) != null) {
canvas.drawBitmap(crossLogo, ((width - crossLogo.getWidth()) / 2) + dx, ((height - crossLogo.getHeight()) / 2) + dy, (Paint) null);
if (this.isTempStable_) {
str = String.format("%.1f℃", Float.valueOf(param.centerTemp * 0.001f));
} else {
str = String.format("~%.1f℃", Float.valueOf(param.centerTemp * 0.001f));
}
paint.getTextBounds(str, 0, str.length(), rect);
int offset = crossLogo.getWidth() / 6;
canvas.drawText(str, (width / 2) + dx + offset, (height / 2) + dy + rect.height() + offset, paint);
}
if (magParameter.isLaserOn && (laserLogo = osdParam.getLaserLogo()) != null) {
int laserPos = magParameter.basePara2.laserPos;
int x = laserPos & 255;
int y = laserPos >> 16;
switch (magParameter.imageEX) {
case 1:
x = ((x - (this.fpaWidth_ / 2)) * 2) + (this.fpaWidth_ / 2);
y = ((y - (this.fpaHeight_ / 2)) * 2) + (this.fpaHeight_ / 2);
break;
case 2:
x = ((x - (this.fpaWidth_ / 2)) * 4) + (this.fpaWidth_ / 2);
y = ((y - (this.fpaHeight_ / 2)) * 4) + (this.fpaHeight_ / 2);
break;
case 3:
x = ((x - (this.fpaWidth_ / 2)) * 8) + (this.fpaWidth_ / 2);
y = ((y - (this.fpaHeight_ / 2)) * 8) + (this.fpaHeight_ / 2);
break;
case 4:
x = ((x - (this.fpaWidth_ / 2)) * 16) + (this.fpaWidth_ / 2);
y = ((y - (this.fpaHeight_ / 2)) * 16) + (this.fpaHeight_ / 2);
break;
}
int[] screenCoor = DeviceController.sensorXY2ScreenXY(x, y, width, height);
if ((magParameter.imageFlip & 1) != 0) {
screenCoor[0] = (width - 1) - screenCoor[0];
}
if ((magParameter.imageFlip & 2) != 0) {
screenCoor[1] = (height - 1) - screenCoor[1];
}
canvas.drawBitmap(laserLogo, (screenCoor[0] - (laserLogo.getWidth() / 2)) + dx, (screenCoor[1] - (laserLogo.getHeight() / 2)) + dy, (Paint) null);
}
if (magParameter.maxMinTrace != -1 && magParameter.isTraceMaxMin && param.state != null) {
drawMaxMin(canvas, paint, param.state, rect, dx, dy, width, height, osdParam);
}
if (magParameter.isTraceRoi) {
drawROIs(canvas, paint, paintROI, rect, dx, dy, width, height, osdParam);
}
Bitmap waterMark = osdParam.getWaterMark();
if (waterMark != null) {
canvas.drawBitmap(waterMark, ((dx + width) - waterMark.getWidth()) - 8, dy + 8, (Paint) null);
}
if (MagApplication.isShowFps && this.frameIndex_ > 20) {
drawFps(canvas, paint, dx, dy, width, height, UsbCommunication.getReceivedFps(), getShowFps());
}
}
private class ThreadRecording extends Thread {
private ThreadRecording() {
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
Logging.trace("Enter ThreadRecording.");
OSDParam osdParam = new OSDParam();
osdParam.setCrossLogo(R.mipmap.cross_capture);
osdParam.setWaterMark(R.mipmap.water_mark);
osdParam.setMinTrace(R.mipmap.min_trace_capture);
osdParam.setMaxTrace(R.mipmap.max_trace_capture);
while (!ImageViewer.this.isExitThreadRecording_) {
synchronized (ImageViewer.this.condRecording_.cond) {
while (!ImageViewer.this.condRecording_.notified) {
try {
ImageViewer.this.condRecording_.cond.wait();
} catch (InterruptedException e) {
}
}
ImageViewer.this.condRecording_.notified = false;
}
if (ImageViewer.this.isExitThreadRecording_) {
break;
} else if (DeviceController.isRecording()) {
ImageViewer.this.drawImage(ImageViewer.this.cachedCanvas_, ImageViewer.this.paintVGA_, ImageViewer.this.paintROIVGA_, ImageViewer.this.matrixVGA_, 0, 0, ImageViewer.this.cachedbmp_.getWidth(), ImageViewer.this.cachedbmp_.getHeight(), osdParam);
DeviceController.doRecording(ImageViewer.this.cachedbmp_);
}
}
osdParam.reset();
Logging.trace("Leave ThreadRecording.");
}
}
private class ThreadRender extends Thread {
private ThreadRender() {
}
@Override // java.lang.Thread, java.lang.Runnable
public void run() {
Logging.trace("Enter ThreadRender.");
OSDParam osdParam = new OSDParam();
osdParam.setCrossLogo(R.mipmap.cross);
osdParam.setMinTrace(R.mipmap.min_trace);
osdParam.setMaxTrace(R.mipmap.max_trace);
osdParam.setLaserLogo(R.mipmap.laser);
osdParam.setMovingCrossLogo(R.mipmap.moving_cross);
int frameIndex = -1;
long t1 = 0;
while (!ImageViewer.this.isExitThreadRender_) {
synchronized (ImageViewer.this.waitCondition_.cond) {
while (!ImageViewer.this.waitCondition_.notified) {
try {
ImageViewer.this.waitCondition_.cond.wait();
} catch (InterruptedException e) {
}
}
ImageViewer.this.waitCondition_.notified = false;
}
if (ImageViewer.this.isExitThreadRender_) {
break;
}
if (DeviceController.isOutputDataReady()) {
ImageViewer.this.doDraw(osdParam);
if (MagApplication.isShowFps) {
if (t1 == 0) {
t1 = System.currentTimeMillis();
} else {
long t = System.currentTimeMillis();
ImageViewer.lock_.lock();
ImageViewer.ticks_[frameIndex % ImageViewer.ticks_.length] = t - t1;
ImageViewer.lock_.unlock();
t1 = t;
}
}
frameIndex++;
} else {
Logging.trace("draw not ready.");
}
}
osdParam.reset();
Logging.trace("Leave ThreadRender.");
}
}
private static int getShowFps() {
long[] ticks = new long[ticks_.length];
lock_.lock();
System.arraycopy(ticks_, 0, ticks, 0, ticks_.length);
lock_.unlock();
int sum = 0;
for (int i = ticks.length - 1; i != -1; i--) {
sum = (int) (sum + ticks[i]);
}
return (ticks_.length * 1000) / sum;
}
}