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