Created
September 7, 2013 10:05
-
-
Save toshinoritakata/6474375 to your computer and use it in GitHub Desktop.
合成マット素材をstraightに変換して、_fillディレクトリに保存する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "windows.h" | |
#include "stdafx.h" | |
#include "FreeImage.h" | |
#include "boost/foreach.hpp" | |
#include "boost/filesystem/path.hpp" | |
#include "boost/filesystem/operations.hpp" | |
void MakeStraight(boost::filesystem::path in_file_path, boost::filesystem::path out_path) | |
{ | |
std::string in_img_name = in_file_path.string(); | |
std::string out_img_name = (out_path/in_file_path.leaf()).string(); | |
FIBITMAP* src_dib = FreeImage_Load(FIF_TIFF, in_img_name.c_str()); | |
if (src_dib == 0) return; | |
FIBITMAP* dst_dib = FreeImage_Clone(src_dib); | |
std::cout << "MakeStraight: " << in_img_name.c_str() << " ==> " << out_img_name.c_str() << std::endl; | |
for (int y = 0; y < FreeImage_GetHeight(src_dib); ++y) { | |
FIRGBA16* src_pix = (FIRGBA16*)FreeImage_GetScanLine(src_dib, y); | |
FIRGBA16* dst_pix = (FIRGBA16*)FreeImage_GetScanLine(dst_dib, y); | |
for (int x = 0; x < FreeImage_GetWidth(src_dib); ++x) { | |
FIRGBA16 col = src_pix[x]; | |
if (col.alpha > 0) { | |
float fr = (float)col.red; | |
float fg = (float)col.green; | |
float fb = (float)col.blue; | |
float fa = (float)col.alpha; | |
col.red = (WORD)(fr/fa*65535.0f+0.5f); | |
col.green = (WORD)(fg/fa*65535.0f+0.5f); | |
col.blue = (WORD)(fb/fa*65535.0f+0.5f); | |
} | |
dst_pix[x] = col; | |
} | |
} | |
FreeImage_Save(FIF_TIFF, dst_dib, out_img_name.c_str()); | |
FreeImage_Unload(src_dib); | |
FreeImage_Unload(dst_dib); | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
if (argc == 2) { | |
FreeImage_Initialise(); | |
boost::filesystem::path path(argv[1]); | |
if (boost::filesystem::exists(path)) { | |
boost::filesystem::path out_path = path/boost::filesystem::path("_fill"); | |
boost::filesystem::create_directory(out_path); | |
BOOST_FOREACH(const boost::filesystem::path& p, | |
std::make_pair(boost::filesystem::directory_iterator(path), | |
boost::filesystem::directory_iterator())) { | |
if (boost::filesystem::is_regular_file(p)) { | |
if (p.extension().string() == ".tif") { | |
MakeStraight(p, out_path); | |
} | |
} | |
} | |
} | |
FreeImage_DeInitialise(); | |
} else { | |
std::cout << "変換したいtifファイルのあるディレクトリを指定して下さい" << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment