Shinya Kitaoka 810553
#pragma once
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
luz paz e2a581
//#define CHECK_VIDEO_FRAME_INTERVAL
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
Shinya Kitaoka 120a6e
class DVAPI CameraImageViewer {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  CameraImageViewer() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  virtual void setImage(TRasterP ras) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// 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
Shinya Kitaoka 120a6e
class ImageProcessing : public TThread::Runnable {
Shinya Kitaoka 120a6e
  Q_OBJECT
Shinya Kitaoka 120a6e
  unsigned char *m_ptr;
Shinya Kitaoka 120a6e
  int m_camWidth;
Shinya Kitaoka 120a6e
  int m_camHeight;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  enum AcquireType { ACQUIRE_FRAME, ACQUIRE_WHITE_IMAGE, NONE } m_acquireType;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ImageProcessing();
Shinya Kitaoka 120a6e
  ~ImageProcessing();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setData(unsigned char *dataPtr);
Shinya Kitaoka 120a6e
  void setImageSize(int camWidth, int camHeight) {
Shinya Kitaoka 120a6e
    m_camWidth  = camWidth;
Shinya Kitaoka 120a6e
    m_camHeight = camHeight;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void run();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
class DVAPI TnzCamera : public QObject {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  CameraImageViewer *m_viewer;
Shinya Kitaoka 120a6e
  CameraLevelManager *m_cameraLevelManager;
Shinya Kitaoka 120a6e
  CameraConnect *m_cameraConnection;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QList<qstring> m_devices;</qstring>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_isCameraConnected;
Shinya Kitaoka 120a6e
  bool m_acquireFrame;
Shinya Kitaoka 120a6e
  bool m_acquireWhiteImage;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  ToonzScene *m_scene;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TDimension m_deviceResolution;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPixel32 m_linesColor;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_startedImageProcessing;
Toshihiro Shimizu 890ddd
#ifndef USE_OPENGL_SHARED
Shinya Kitaoka 120a6e
  TThread::Executor *m_imageProcessingExecutor;
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_freeze;
Toshihiro Shimizu 890ddd
luz paz e2a581
#ifdef CHECK_VIDEO_FRAME_INTERVAL
luz paz e2a581
  double m_videoFrameInterval;
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TnzCamera();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  static TnzCamera *instance();
Shinya Kitaoka 120a6e
  bool initTnzCamera();
Shinya Kitaoka 120a6e
  ~TnzCamera();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef USE_OPENGL_SHARED
Shinya Kitaoka 120a6e
  void notifyImageChanged(int camWidth, int camHeight, unsigned char *ptr) {
Shinya Kitaoka 120a6e
    Q_EMIT imageChanged(camWidth, camHeight, ptr);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  TThread::Executor *getImageProcessingExecutor() const {
Shinya Kitaoka 120a6e
    return m_imageProcessingExecutor;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  bool &startedImageProcessing() { return m_startedImageProcessing; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isFreezed() const { return m_freeze; }
Shinya Kitaoka 120a6e
  void freeze(bool freeze) { m_freeze = freeze; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setScene(ToonzScene *scene);
Shinya Kitaoka 120a6e
  TDimension getDeviceResolution() const { return m_deviceResolution; }
Shinya Kitaoka 120a6e
  CaptureParameters *getCaptureParameters() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TXshSimpleLevel *getCurrentLevel() const;
Shinya Kitaoka 120a6e
  TFrameId getCurrentFid() const;
Toshihiro Shimizu 890ddd
luz paz e2a581
#ifdef CHECK_VIDEO_FRAME_INTERVAL
luz paz e2a581
  double getVideoFrameInterval() const { return m_videoFrameInterval; }
luz paz e2a581
  void setVideoFrameInterval(double interval);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isAcquireFrame() const { return m_acquireFrame; }
Shinya Kitaoka 120a6e
  bool isAcquireWhiteImage() const { return m_acquireWhiteImage; }
Shinya Kitaoka 120a6e
  void setViewImage(TRaster32P img);
Shinya Kitaoka 120a6e
  void setAcquiredImage(TRaster32P img);
Shinya Kitaoka 120a6e
  void setAcquiredWhiteImage(TRasterGR8P img);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterGR8P getWhiteImage();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isCameraConnected() const { return m_isCameraConnected; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void updateDeviceResolution(int width, int height);
Shinya Kitaoka 120a6e
  bool setCurrentImageSize(int width, int height);
Shinya Kitaoka 120a6e
  int getImageWidth() const;
Shinya Kitaoka 120a6e
  int getImageHeight() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int getContrast() const;
Shinya Kitaoka 120a6e
  int getBrightness() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool isSubtractWhiteImage() const;
Shinya Kitaoka 120a6e
  void removeWhiteImage();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool getUpsideDown() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool saveWithoutAlpha() const;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TPixel32 getLinesColor() const { return m_linesColor; }
Shinya Kitaoka 120a6e
  void setLinesColor(TPixel32 color) { m_linesColor = color; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool findConnectedCameras(QList<qstring> &cameras);</qstring>
Shinya Kitaoka 120a6e
  bool cameraConnect(wstring deviceName);
Shinya Kitaoka 120a6e
  void cameraDisconnect();
Shinya Kitaoka 120a6e
  bool onViewfinder(CameraImageViewer *viewer);
Shinya Kitaoka 120a6e
  bool onRelease(TFrameId frameId, wstring fileName, int row = 0, int col = 0,
Shinya Kitaoka 120a6e
                 bool keepWhiteImage = false);
Shinya Kitaoka 120a6e
  int saveType() const;
Shinya Kitaoka 120a6e
  void setSaveType(int value);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Utility function
Shinya Kitaoka 120a6e
  void keepWhiteImage();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void notifyCameraShutDown() { Q_EMIT cameraShutDown(); }
Shinya Kitaoka 120a6e
  void notifyAbort() { Q_EMIT abort(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef USE_OPENGL_SHARED
Toshihiro Shimizu 890ddd
protected Q_SLOTS:
Shinya Kitaoka 120a6e
  void processImage(int camWidth, int camHeight, unsigned char *ptr);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
Q_SIGNALS:
Shinya Kitaoka 120a6e
  void cameraShutDown();
Shinya Kitaoka 120a6e
  void abort();
Shinya Kitaoka 120a6e
  void devicePropChanged();
Shinya Kitaoka 120a6e
  void captureFinished();
Shinya Kitaoka 120a6e
  void imageViewChanged(TRaster *ras);
Shinya Kitaoka 120a6e
  void imageSizeUpdated();
Toshihiro Shimizu 890ddd
#ifdef USE_OPENGL_SHARED
Shinya Kitaoka 120a6e
  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
Shinya Kitaoka 120a6e
class LogWriter  // Singleton
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  Tofstream m_os;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  LogWriter(TFilePath fp);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void write(QString str);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  static LogWriter *instance();
Shinya Kitaoka 120a6e
  ~LogWriter();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // TNZCAMERA_H