tahoma2d/toonz/sources/include/tnzcamera.h

224 lines
5 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TNZCAMERA_H
#define TNZCAMERA_H
#include "tcommon.h"
#include "timage.h"
#include "tiio.h"
#include "tthread.h"
#include "toonz/toonzscene.h"
//#define WRITE_LOG_FILE
//#define CHECK_VIDEO_FRAME_INTERVALL
//#define USE_OPENGL_SHARED
#undef DVAPI
#undef DVVAR
#ifdef TCAMERA_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
// forward declaration
class CameraLevelManager;
class CameraConnect;
class QImage;
class CaptureParameters;
class TXshSimpleLevel;
//===================================================================
// CameraImageViewer
2016-06-15 18:43:10 +12:00
class DVAPI CameraImageViewer {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
CameraImageViewer() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void setImage(TRasterP ras) = 0;
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
// void processImage(unsigned char* m_ptr, int camWidth, int camHeight);
2016-03-19 06:57:51 +13:00
#ifndef USE_OPENGL_SHARED
//=============================================================================
// ImageProcessing
2016-06-15 18:43:10 +12:00
class ImageProcessing : public TThread::Runnable {
Q_OBJECT
unsigned char *m_ptr;
int m_camWidth;
int m_camHeight;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
enum AcquireType { ACQUIRE_FRAME, ACQUIRE_WHITE_IMAGE, NONE } m_acquireType;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ImageProcessing();
~ImageProcessing();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setData(unsigned char *dataPtr);
void setImageSize(int camWidth, int camHeight) {
m_camWidth = camWidth;
m_camHeight = camHeight;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void run();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void onFinished(TThread::RunnableP task);
2016-03-19 06:57:51 +13:00
};
#endif
//===================================================================
// CameraTest
2016-06-15 18:43:10 +12:00
class DVAPI TnzCamera : public QObject {
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
CameraImageViewer *m_viewer;
CameraLevelManager *m_cameraLevelManager;
CameraConnect *m_cameraConnection;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QList<QString> m_devices;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_isCameraConnected;
bool m_acquireFrame;
bool m_acquireWhiteImage;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
ToonzScene *m_scene;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TDimension m_deviceResolution;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPixel32 m_linesColor;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_startedImageProcessing;
2016-03-19 06:57:51 +13:00
#ifndef USE_OPENGL_SHARED
2016-06-15 18:43:10 +12:00
TThread::Executor *m_imageProcessingExecutor;
2016-03-19 06:57:51 +13:00
#else
#endif
2016-06-15 18:43:10 +12:00
bool m_freeze;
2016-03-19 06:57:51 +13:00
#ifdef CHECK_VIDEO_FRAME_INTERVALL
2016-06-15 18:43:10 +12:00
double m_videoFrameIntervall;
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
TnzCamera();
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
static TnzCamera *instance();
bool initTnzCamera();
~TnzCamera();
2016-03-19 06:57:51 +13:00
#ifdef USE_OPENGL_SHARED
2016-06-15 18:43:10 +12:00
void notifyImageChanged(int camWidth, int camHeight, unsigned char *ptr) {
Q_EMIT imageChanged(camWidth, camHeight, ptr);
}
2016-03-19 06:57:51 +13:00
#else
2016-06-15 18:43:10 +12:00
TThread::Executor *getImageProcessingExecutor() const {
return m_imageProcessingExecutor;
}
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
bool &startedImageProcessing() { return m_startedImageProcessing; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isFreezed() const { return m_freeze; }
void freeze(bool freeze) { m_freeze = freeze; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setScene(ToonzScene *scene);
TDimension getDeviceResolution() const { return m_deviceResolution; }
CaptureParameters *getCaptureParameters() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TXshSimpleLevel *getCurrentLevel() const;
TFrameId getCurrentFid() const;
2016-03-19 06:57:51 +13:00
#ifdef CHECK_VIDEO_FRAME_INTERVALL
2016-06-15 18:43:10 +12:00
double getVideoFrameIntervall() const { return m_videoFrameIntervall; }
void setVideoFrameIntervall(double intervall);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
bool isAcquireFrame() const { return m_acquireFrame; }
bool isAcquireWhiteImage() const { return m_acquireWhiteImage; }
void setViewImage(TRaster32P img);
void setAcquiredImage(TRaster32P img);
void setAcquiredWhiteImage(TRasterGR8P img);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRasterGR8P getWhiteImage();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isCameraConnected() const { return m_isCameraConnected; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void updateDeviceResolution(int width, int height);
bool setCurrentImageSize(int width, int height);
int getImageWidth() const;
int getImageHeight() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int getContrast() const;
int getBrightness() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isSubtractWhiteImage() const;
void removeWhiteImage();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool getUpsideDown() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool saveWithoutAlpha() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TPixel32 getLinesColor() const { return m_linesColor; }
void setLinesColor(TPixel32 color) { m_linesColor = color; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool findConnectedCameras(QList<QString> &cameras);
bool cameraConnect(wstring deviceName);
void cameraDisconnect();
bool onViewfinder(CameraImageViewer *viewer);
bool onRelease(TFrameId frameId, wstring fileName, int row = 0, int col = 0,
bool keepWhiteImage = false);
int saveType() const;
void setSaveType(int value);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Utility function
void keepWhiteImage();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void notifyCameraShutDown() { Q_EMIT cameraShutDown(); }
void notifyAbort() { Q_EMIT abort(); }
2016-03-19 06:57:51 +13:00
#ifdef USE_OPENGL_SHARED
protected Q_SLOTS:
2016-06-15 18:43:10 +12:00
void processImage(int camWidth, int camHeight, unsigned char *ptr);
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
Q_SIGNALS:
void cameraShutDown();
void abort();
void devicePropChanged();
void captureFinished();
void imageViewChanged(TRaster *ras);
void imageSizeUpdated();
2016-03-19 06:57:51 +13:00
#ifdef USE_OPENGL_SHARED
2016-06-15 18:43:10 +12:00
void imageChanged(int camWidth, int camHeight, unsigned char *ptr);
2016-03-19 06:57:51 +13:00
#endif
};
#ifdef WRITE_LOG_FILE
//===================================================================
// LogWriter
#include "tfilepath_io.h"
2016-06-15 18:43:10 +12:00
class LogWriter // Singleton
2016-03-19 06:57:51 +13:00
{
2016-06-15 18:43:10 +12:00
Tofstream m_os;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
LogWriter(TFilePath fp);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void write(QString str);
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
static LogWriter *instance();
~LogWriter();
2016-03-19 06:57:51 +13:00
};
#endif
2016-06-15 18:43:10 +12:00
#endif // TNZCAMERA_H