MouseComputer社製 LuvBook Tシリーズ
OS Windous7 Home Plemium 64bit 正規版
プロセッサー インテル® Core™ i7-2670QM プロセッサー(2.20GHz / 4コア)
グラフィックス NVIDIA® GeForce® GT540M / インテル® HD グラフィックス 3000(NVIDIA® Optimus™テクノロジ対応)
です。
インストールしたものは、
NVIDIA グラフィックス ドライバー 285.62
CUDA Toolkit 4.1
GPU Computing SDK 4.1
Visual Studio 2008 c++ Express Edition
winsdk_web.exe setup_x64.bat (この2つは、64bitプラットフォームを作成するためにインストール、実行しました。詳しくは、http://absolutearea.blogspot.com/2010/0 ... m-sdk.html)
設定したパスは、
追加のインクルードディレクトリ "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\include"
追加のライブラリディレクトリ "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.1\lib\x64"
追加の依存ファイル OpenCL.lib
です。
http://www.shuwasystem.co.jp/support/7980html/2608.html
このサイトから、サンプルファイルをダウンロードしたのですが、Bitmapクラスを作成する、というプログラムの実行結果を得ることが出来ません。
手順としては、
新しいソリューションを作成。
ソースファイルを右クリックして、ダウンロードしたファイルから、Bitmap.cppを追加。
ヘッダファイルを右クリックして、ダウンロードしたファイルから、Bitmap.h と Bitmapspec.h と MyError.h を追加。
上記のパスを通す。
ビルド。
を行ったところ、
1>------ ビルド開始: プロジェクト: Bitmap, 構成: Debug Win32 ------
1>コンパイルしています...
1>Bitmap.cpp
1>c:\users\kuro\documents\visual studio 2008\projects\bitmap\bitmap\bitmap.cpp(12) : fatal error C1083: include ファイルを開けません。'MyError.h': No such file or directory
1>ビルドログは "file://c:\Users\kuro\Documents\Visual Studio 2008\Projects\Bitmap\Bitmap\Debug\BuildLog.htm" に保存されました。
1>Bitmap - エラー 1、警告 0
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========
というエラーが出ました。
MyError.h というヘッダファイルは確かに存在しているのですが、一体どういうことなのでしょうか?
このエラーを見る限り、MyError.h だけということはなく、Bitmap.h と Bitmapspec.h も同様のエラーが出ているものと思います。
どなたか解決法、またはこうしたらよいのでは? という方がいらっしゃいましたらよろしくお願いします。
プログラムは、
[Bitmap.cpp]
// List5.3
/*
* Bitmap.cpp (rev1.1, 28.Nov.2010)
* Copyright 2010 Takashi Okuzono. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "MyError.h"
#include "Bitmap.h"
/*-------------------------------------------------------------------------
* コンストラクタ
*/
Bitmap::Bitmap()
: mWidth(0), mHeight(0), mData(0), mDataSize(0), mTotalPixels(0)
{
assert(sizeof(MyBYTE) == 1);
assert(sizeof(MyWORD) == 2);
assert(sizeof(MyDWORD) == 4);
assert(sizeof(MyLONG) == 4);
}
/*-------------------------------------------------------------------------
* デストラクタ
*/
Bitmap::~Bitmap()
{
if (mData != 0) {
delete [] mData;
mData = 0;
}
mDataSize = 0;
}
/*-------------------------------------------------------------------------
* ビットマップデータを作成する
*
* width, height: ビットマップの幅, 高さ
* dataR, dataG, dataB: 0から1.0fで表現した色値
*/
void
Bitmap::create(const int width, const int height,
const float* dataR, const float* dataG, const float* dataB)
{
initialize(width, height);
fillData(dataR, dataG, dataB);
}
/*-------------------------------------------------------------------------
* ビットマップデータを作成する
*
* width, height: ビットマップの幅、高さ
* dataR, dataG, dataB: 0から255で表現した色値
*/
void
Bitmap::create(const int width, const int height,
const unsigned char* dataR,
const unsigned char* dataG,
const unsigned char* dataB)
{
initialize(width, height);
fillData(dataR, dataG, dataB);
}
/*-------------------------------------------------------------------------
* ビットマップデータを作成する
*
* width, height: ビットマップの幅、高さ。
* dataBgra: 1つのピクセル値を、BGRA 4バイトで表したイメージデータ。
* BGRAそれぞれの値は、0から255までの値を取る。
*/
void
Bitmap::createFromBgra(const int width, const int height,
const unsigned char* dataBgra)
{
initialize(width, height);
fillBgraData(dataBgra);
}
/*-------------------------------------------------------------------------
* ビットマップファイルを読み込む
*
* path: 読み込むビットマップファイル
*/
void
Bitmap::readFile(const char *path)
{
FILE *ifp;
fopen_s(&ifp, path, "rb");
if (ifp == 0) {
perror("fopen");
fprintf(stderr, "file: %s\n", path);
throw MyError("bitmap file open failed", __FUNCTION__);
}
int error;
error = readFileHeader(ifp);
if (error > 0) {
throw MyError("failed to read bitmap file header", __FUNCTION__);
}
error = readInfoHeader(ifp);
if (error > 0) {
throw MyError("failed to read bitmap info header", __FUNCTION__);
}
mDataSize = mFileHeader.bfSize - mInfoHeader.biSize - sizeof(mFileHeader);
if (mData != 0) {
delete [] mData;
}
mData = new unsigned char[mDataSize];
error = readBitmapData(ifp);
if (error > 0) {
throw MyError("failed to read bitmap data", __FUNCTION__);
}
mWidth = mInfoHeader.biWidth;
mHeight = mInfoHeader.biHeight;
fclose(ifp);
}
/*-------------------------------------------------------------------------
* ビットマップファイルを書き出す
*
* path: 書き出すビットマップファイル
*/
void
Bitmap::writeFile(const char *path) const
{
FILE *ofp;
fopen_s(&ofp, path, "wb");
if (ofp == 0) {
perror("fopen");
fprintf(stderr, "file: %s\n", path);
throw MyError("bitmap file open failed", __FUNCTION__);
}
writeFileHeader(ofp);
writeInfoHeader(ofp);
writeBitmapData(ofp);
fclose(ofp);
}
/*-------------------------------------------------------------------------
* 画像データをR, G, Bチャンネル (dataR, dataG, dataB) に分割して返す。
*/
void
Bitmap::getRgbData(unsigned char* dataR,
unsigned char* dataG,
unsigned char* dataB) const
{
int index = 0;
if (mInfoHeader.biBitCount == 32) {
// 32-bitビットマップ (BGRA)
for (int i = 0; i < mDataSize; i += 4) {
dataB[index] = mData[i + 0];
dataG[index] = mData[i + 1];
dataR[index] = mData[i + 2];
index++;
}
} else if (mInfoHeader.biBitCount == 24) {
// 24-bitビットマップ (BGR)
for (int i = 0; i < mDataSize; i += 3) {
dataB[index] = mData[i + 0];
dataG[index] = mData[i + 1];
dataR[index] = mData[i + 2];
index++;
}
} else {
throw MyError("Unsupported bitmap format", __FUNCTION__);
}
}
/*-------------------------------------------------------------------------
* 画像データをBGRAとして返す。
*/
void
Bitmap::getBgraData(unsigned char* dataBgra) const
{
if (mInfoHeader.biBitCount == 32) {
// 32bitビットマップはBGRAの順に並んでいるので、そのままコピーする。
memcpy(dataBgra, mData, mDataSize);
} else if (mInfoHeader.biBitCount == 24) {
// 24bitビットマップはAチャンネルにダミーのデータをセットする。
int index = 0;
for (int i = 0; i < mDataSize; i += 3) {
dataBgra[index++] = mData[i + 0]; // B
dataBgra[index++] = mData[i + 1]; // G
dataBgra[index++] = mData[i + 2]; // R
dataBgra[index++] = 255; // A
}
} else {
throw MyError("Unsupported bitmap format", __FUNCTION__);
}
}
/*-------------------------------------------------------------------------
*
*/
void
Bitmap::initialize(const int width, const int height)
{
if (width <= 0) {
throw MyError("width must be > 0\n", __FUNCTION__);
}
if (width % 4 != 0) {
throw MyError("width must be a multiply of 4.", __FUNCTION__);
}
initFileHeader();
initInfoHeader();
mWidth = width;
mHeight = height;
const int absHeight = height > 0 ? height : height * -1;
mTotalPixels = width * absHeight;
mDataSize = mTotalPixels * 3;
if (mData != 0) {
delete [] mData;
mData = 0;
}
mData = new unsigned char[mDataSize];
mInfoHeader.biWidth = width;
mInfoHeader.biHeight = height;
mFileHeader.bfSize = (MyDWORD)(mDataSize
+ sizeof(mFileHeader)
+ sizeof(mInfoHeader));
}
/*-------------------------------------------------------------------------
*
*/
void
Bitmap::fillData(const float* dataR, const float* dataG, const float* dataB)
{
int index = 0;
for (int i = 0; i < mDataSize; i += 3) {
mData[i + 0] = getPixelValue(dataB[index]);
mData[i + 1] = getPixelValue(dataG[index]);
mData[i + 2] = getPixelValue(dataR[index]);
index++;
}
}
/*-------------------------------------------------------------------------
*
*/
void
Bitmap::fillData(const unsigned char* dataR,
const unsigned char* dataG,
const unsigned char* dataB)
{
int index = 0;
for (int i = 0; i < mDataSize; i += 3) {
mData[i + 0] = dataB[index];
mData[i + 1] = dataG[index];
mData[i + 2] = dataR[index];
index++;
}
}
/*-------------------------------------------------------------------------
* 受け取ったBGRAデータを、内部のデータとしてセットする。
* BGRのみ取得し、Aチャンネルは捨てる。
*/
void
Bitmap::fillBgraData(const unsigned char* dataBgra)
{
int index = 0;
int bgraSize = (mDataSize * 4) / 3;
for (int i = 0; i < bgraSize; i += 4) {
mData[index++] = dataBgra[i + 0]; // B
mData[index++] = dataBgra[i + 1]; // G
mData[index++] = dataBgra[i + 2]; // R
// mData[index++] = dataBgra[i + 3]; // A
}
}
/*-------------------------------------------------------------------------
*
*/
int
Bitmap::readFileHeader(FILE *fp)
{
int error = 0;
const size_t numobject = 1;
size_t result = fread(&mFileHeader, sizeof(mFileHeader), numobject, fp);
if (numobject != result) {
error++;
}
return error;
}
/*-------------------------------------------------------------------------
*
*/
int
Bitmap::readInfoHeader(FILE *fp)
{
int error = 0;
const size_t numobject = 1;
size_t result = fread(&mInfoHeader, sizeof(mInfoHeader), numobject, fp);
if (numobject != result) {
error++;
}
return error;
}
/*-------------------------------------------------------------------------
*
*/
int
Bitmap::readBitmapData(FILE *fp)
{
if (mData == 0 || mDataSize == 0) {
return 1;
}
size_t result = fread(mData, sizeof(*mData), mDataSize, fp);
if (mDataSize != result) {
return 1;
}
return 0;
}
/*-------------------------------------------------------------------------
*
*/
int
Bitmap::writeFileHeader(FILE *fp) const
{
int error = 0;
const size_t numobject = 1;
size_t times = fwrite(&mFileHeader, sizeof(mFileHeader), numobject, fp);
if (numobject != times) {
error++;
return error;
}
return error;
}
/*-------------------------------------------------------------------------
*
*/
int
Bitmap::writeInfoHeader(FILE *fp) const
{
int error = 0;
const size_t numobject = 1;
size_t times = fwrite(&mInfoHeader, sizeof(mInfoHeader), numobject, fp);
if (numobject != times) {
error++;
return error;
}
return error;
}
/*-------------------------------------------------------------------------
*
*/
int
Bitmap::writeBitmapData(FILE *fp) const
{
int error = 0;
const size_t numobject = mDataSize;
size_t times = fwrite(mData, sizeof(*mData), mDataSize, fp);
if (numobject != times) {
error++;
return error;
}
return error;
}
/*-------------------------------------------------------------------------
*
*/
void
Bitmap::initFileHeader()
{
mFileHeader.bfType = 0x4d42;
mFileHeader.bfSize = 0;
mFileHeader.bfSize = sizeof(mInfoHeader);
mFileHeader.bfReserved1 = 0;
mFileHeader.bfReserved2 = 0;
mFileHeader.bfOffBits = 54;
}
/*-------------------------------------------------------------------------
*
*/
void
Bitmap::initInfoHeader()
{
mInfoHeader.biSize = sizeof(mInfoHeader);
mInfoHeader.biWidth = 0;
mInfoHeader.biHeight = 0;
mInfoHeader.biPlanes = 1;
mInfoHeader.biBitCount = 24;
mInfoHeader.biCompression = 0;
mInfoHeader.biSizeImage = 0;
mInfoHeader.biXPelsPerMeter = 0;
mInfoHeader.biYPelsPerMeter = 0;
mInfoHeader.biClrUsed = 0;
mInfoHeader.biClrImportant = 0;
}
/*-------------------------------------------------------------------------
*
*/
unsigned char
Bitmap::getPixelValue(const float val) const
{
int intval = (int)(val * 255.0f);
if (intval < 0) {
intval = 0;
} else if (intval > 255) {
intval = 255;
}
return (unsigned char)intval;
}
[bitmap.h]
// List5.2
/*
* Bitmap.h (rev1.1, 28.Nov.2010)
* Copyright 2010 Takashi Okuzono. All rights reserved.
*/
#ifndef __BITMAP_H__
#define __BITMAP_H__
#include <stdio.h>
#include "bitmapspec.h"
/*-------------------------------------------------------------------------
*
*/
class Bitmap {
public:
Bitmap();
virtual ~Bitmap();
void create(const int width, const int height,
const float* dataR,
const float* dataG,
const float* dataB);
void create(const int width, const int height,
const unsigned char* dataR,
const unsigned char* dataG,
const unsigned char* dataB);
void createFromBgra(const int width, const int height,
const unsigned char* dataBgra);
void readFile(const char *path);
void writeFile(const char *path) const;
void getRgbData(unsigned char* dataR,
unsigned char* dataG,
unsigned char* dataB) const;
void getBgraData(unsigned char* dataBgra) const;
int getWidth() const {return mWidth;}
int getHeight() const {return mHeight;}
int getDataSize() const {return mDataSize;}
int getTotalPixels() const {return mTotalPixels;}
private:
void initialize(const int width, const int height);
void fillData(const float* dataR,
const float* dataG,
const float* dataB);
void fillData(const unsigned char* dataR,
const unsigned char* dataG,
const unsigned char* dataB);
void fillBgraData(const unsigned char *dataBgra);
int readFileHeader(FILE *ifp);
int readInfoHeader(FILE *ifp);
int readBitmapData(FILE *ifp);
int writeFileHeader(FILE *ofp) const;
int writeInfoHeader(FILE *ofp) const;
int writeBitmapData(FILE *ofp) const;
void initFileHeader();
void initInfoHeader();
unsigned char getPixelValue(const float val) const;
unsigned char getPixelValue(const int val) const;
private:
BitmapFileHeader mFileHeader;
BitmapInfoHeader mInfoHeader;
int mWidth; // 画面の幅
int mHeight; // 画面の高さ
unsigned char *mData; // 画像データ
size_t mDataSize; // 画像データのサイズ
size_t mTotalPixels; // 画面のピクセル数
};
#endif // __BITMAP_H__
[Bitmapspec.h]
/ List5.1
/*
* bitmapspec.h (rev1.1, 28.Nov.2010)
* Copyright 2010 Takashi Okuzono All rights reserved.
*/
#ifndef __BITMAPSPEC_H__
#define __BITMAPSPEC_H__
typedef char MyBYTE; // 1byte
typedef short MyWORD; // 2byte
typedef int MyDWORD; // 4byte
typedef int MyLONG; // 4byte
#pragma pack(push, 1)
typedef struct {
MyWORD bfType;
MyDWORD bfSize;
MyWORD bfReserved1;
MyWORD bfReserved2;
MyDWORD bfOffBits;
} BitmapFileHeader;
typedef struct {
MyDWORD biSize;
MyLONG biWidth;
MyLONG biHeight;
MyWORD biPlanes;
MyWORD biBitCount;
MyDWORD biCompression;
MyDWORD biSizeImage;
MyLONG biXPelsPerMeter;
MyLONG biYPelsPerMeter;
MyDWORD biClrUsed;
MyDWORD biClrImportant;
} BitmapInfoHeader;
#pragma pack(pop)
#endif // __BITMAPSPEC_H__
[MyError.h]
// List5.4
/*
* MyError.h (rev1.1, 28.Nov.2010)
* Copyright 2010 Takashi Okuozno All rights reserved.
*/
#ifndef __MY_ERROR_H__
#define __MY_ERROR_H__
#include <string>
class MyError {
public:
MyError(const std::string & msg,
const std::string & function = "") {mMsg = msg + " " + function;}
virtual ~MyError() {};
const std::string message() const {return mMsg;}
const char * cstr() const {return mMsg.c_str();}
private:
std::string mMsg;
};
#endif // __MY_ERROR_H__