#include #include #include #include #include "alp.h" #include #include #include #include #include // std::atoiを使うために必要 #pragma pack(push, 1) // from ChatGPT struct BMPHeader { uint16_t fileType; // ファイルタイプ ('BM' - 0x4D42) uint32_t fileSize; // ファイルサイズ uint16_t reserved1; // 予約領域 uint16_t reserved2; // 予約領域 uint32_t offsetData; // データオフセット }; struct DIBHeader { // from chatGPT uint32_t size; // DIBヘッダーサイズ int32_t width; // 幅 int32_t height; // 高さ uint16_t planes; // プレーン数 uint16_t bitCount; // ビット深度 uint32_t compression; // 圧縮方式 uint32_t sizeImage; // イメージサイズ int32_t xPelsPerMeter; // 水平解像度 int32_t yPelsPerMeter; // 垂直解像度 uint32_t colorsUsed; // 使用された色数 uint32_t colorsImportant; // 重要な色数 }; #pragma pack(pop) // from ChatGPT int readBMPFile(const std::string& filePath, std::vector& bImage, BMPHeader& bmpHeader, DIBHeader& dibHeader) { std::ifstream file(filePath, std::ios::binary); if (!file) { std::cerr << "ファイルを開けません: " << filePath << std::endl; return 1; } // BMPヘッダーとDIBヘッダーを読み取る file.read(reinterpret_cast(&bmpHeader), sizeof(BMPHeader)); file.read(reinterpret_cast(&dibHeader), sizeof(DIBHeader)); if (bmpHeader.fileType != 0x4D42) { // 'BM'のチェック std::cerr << "有効なBMPファイルではありません: " << filePath << std::endl; return 1; } // 指定された解像度とビット深度をチェック if (dibHeader.width != 1920 || dibHeader.height != 1080) { std::cerr << "ファイルは指定された解像度 (1920x1080) ではありません: " << filePath << std::endl; return 1; } if (dibHeader.bitCount != 8) { std::cerr << "ファイルは指定されたビット深度 (8ビット) ではありません。なお、8ビットのファイルはミラーのオフは「0」、オンは「0以外」で埋めてください: " << filePath << std::endl; return 1; } // データの読み取り file.seekg(bmpHeader.offsetData, std::ios::beg); bImage.resize(dibHeader.sizeImage); file.read(reinterpret_cast(bImage.data()), dibHeader.sizeImage); std::cout << "ファイルが正しく読み込まれました: " << filePath << std::endl; return 0; } int main(int argc, char* argv[]) { ALP_ID nDevId, nSeqId; long nDmdType, nSizeX, nSizeY; long nReturn; const long nPictureTime = 1000000; // 1000 ms, i.e. 50 Hz frame rate UCHAR* pImageData = NULL; // コマンドライン引数の数を確認 if (argc != 3) { std::cerr << "使用方法: " << argv[0] << " <入力ファイル名> <時間(in microsec)>" << std::endl; return 1; } // 入力ファイル名と出力ファイル名をコマンドライン引数から取得 std::string inputFilePath = argv[1]; int PicTime = std::atoi(argv[2]); std::vector bImage; BMPHeader bmpHeader; DIBHeader dibHeader; // 入力ファイルを読み取る if (readBMPFile(inputFilePath, bImage, bmpHeader, dibHeader) != 0) { return 1; }; //BlackWhiteSample(bImage); if (ALP_OK != AlpDevAlloc(ALP_DEFAULT, ALP_DEFAULT, &nDevId)) { printf("error(AlpDevAlloc)\r\n"); return 1; } if (ALP_OK != AlpDevInquire(nDevId, ALP_DEV_DISPLAY_HEIGHT, &nSizeY) || ALP_OK != AlpDevInquire(nDevId, ALP_DEV_DISPLAY_WIDTH, &nSizeX)) { printf("error(ALP_DEV_DISPLAY_HEIGHT)\r\n"); return 1; } // printf("nSizeX = %d\n", nSizeX); if (ALP_OK != AlpSeqAlloc(nDevId, 1, 1, &nSeqId)) { printf("error(AlpSeqAlloc)\r\n"); return 1; } pImageData = (UCHAR*)malloc(nSizeX * nSizeY); if (NULL == pImageData) { printf("Could not allocate image memory.\r\n"); return 1; } long nX, nY; long nXY; long n2D = nSizeX * nSizeY; for (nXY = 0; nXY < n2D; nXY++) { if (bImage[nXY] == 0) pImageData[nXY] = 0x00; else { pImageData[nXY] = 0x80; } } nReturn = AlpSeqPut(nDevId, nSeqId, 0, 1, pImageData); // Shin free(pImageData); if (ALP_OK != nReturn) { printf("error(AlpSeqPut)\r\n"); return 1; } if (ALP_OK != AlpProjControl(nDevId, ALP_PROJ_MODE, ALP_SLAVE)) { printf("error(AlpProjControl)\r\n"); return 1; } if (ALP_OK != AlpSeqControl(nDevId, nSeqId, ALP_SEQ_REPEAT, 1000000)) { printf("error(AlpSeqControl)\r\n"); return 1; } if (ALP_OK != AlpSeqTiming(nDevId, nSeqId, ALP_DEFAULT, PicTime, ALP_DEFAULT, ALP_DEFAULT, ALP_DEFAULT)) { printf("error(AlpSeqTiming)\r\n"); return 1; } if (ALP_OK != AlpProjStart(nDevId, nSeqId)) { printf("error(AlpProjStartCont)\r\n"); return 1; } //WaitForKeyStroke(); printf("The program will accept down edges for million times. Press any key to stop ALP projection..\r\n"); do { _getch(); } while (_kbhit()); //Done AlpDevHalt(nDevId); AlpDevFree(nDevId); return 0; }