#include "raw_image_class.h"
template<class Type>
inline Raw_image<Type>::Raw_image(char* filename)
{
//画像読み込み
FILE* file;
fopen_s(&file, filename, "rb");
if (file == NULL) {
image = 0;
return;
}
// ファイルサイズ確認
fseek(file, 0, SEEK_END);
int fileSize = ftell(file);
int depth = fileSize / (data.Width * data.Height * sizeof(Type));
if (depth != data.Depth) {
if (data.Depth == 0) {
data.Depth = depth;
data.VOXELS = data.Width * data.Height * data.Depth;
}
else {
data.Depth = depth > data.Depth ? data.Depth : depth;
data.VOXELS = data.Width * data.Height * data.Depth;
}
}
else {
data.Depth = depth;
data.VOXELS = data.Width * data.Height * data.Depth;
}
image = new Type[data.VOXELS];
// データ読み込み
fseek(file, 0, SEEK_SET);
fread(image, sizeof(Type), data.VOXELS, file);
fclose(file);
return;
}
template<class Type>
Raw_image<Type>::Raw_image()
{
}
template<class Type>
Raw_image<Type>::~Raw_image()
{
if (image != 0) {
delete[] image;
}
return;
}
template<class Type>
bool Raw_image<Type>::empty()
{
if (image == 0) {
return false;
}
else {
return true;
}
}