Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // これにデータをセットして返す?
- namespace ImageJpegTag{
- struct JpegTag{
- wchar_t* filepath;
- wchar_t* keyword;
- wchar_t* comment;
- wchar_t* cameraMaker;
- wchar_t* cameraModel;
- wchar_t* programName;
- wchar_t* dateCreated;
- wchar_t* author;
- wchar_t* dateOriginal; // 本来の作成日
- wchar_t* dateDigitized; // デジタルにした日付
- };
- }
- // タグ書き込みの際のID
- namespace CrackImage{
- namespace TagId{
- const int Keyword = 1;
- const int Comment = 2;
- }
- }
- // GDI+ のヘルプファイルに記述されていたもの
- namespace ImageImage{
- namespace Util{
- void propertyTypeFromWORD( WORD index, WCHAR* str ){
- WCHAR* propTypes[] = {
- L"Nothing", // 0
- L"PropertyTagTypeByte", // 1
- L"PropertyTagTypeASCII", // 2
- L"PropertyTagTypeShort", // 3
- L"PropertyTagTypeLong", // 4
- L"PropertyTagTypeRational", // 5
- L"Nothing", // 6
- L"PropertyTagTypeUndefined", // 7
- L"Nothing", // 8
- L"PropertyTagTypeSLONG", // 9
- L"PropertyTagTypeSRational" // 10
- };
- wcscpy( str, propTypes[index] );
- return;
- }
- int getEncoderClsid( const WCHAR* format, CLSID* pClsid ){
- UINT num = 0; // イメージエンコーダ数
- UINT size = 0; // イメージエンコーダ配列のサイズ
- Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;
- Gdiplus::GetImageEncodersSize( &num, &size );
- if( size == 0 ) return -1; // 失敗
- pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc( size ));
- if( pImageCodecInfo == nullptr ) return -1;
- Gdiplus::GetImageEncoders( num, size, pImageCodecInfo );
- for( UINT i = 0; i < num; ++i ){
- if( wcscmp( pImageCodecInfo[i].MimeType, format ) == 0 ){
- *pClsid = pImageCodecInfo[i].Clsid;
- free( pImageCodecInfo );
- return i; // 成功
- }
- }
- free( pImageCodecInfo );
- return -1; // 失敗
- }
- }
- }
- namespace ImageImage{
- namespace TagName{
- const char Keyword[] = "0x9c9e";
- const char Comment[] = "0x9c9c";
- const char CameraMaker[] = "0x10f";
- const char CameraModel[] = "0x110";
- const char ProgramName[] = "0x131";
- const char DateCreated[] = "0x132";
- const char Author[] = "0x13b";
- const char DateOriginal[] = "0x9003";
- const char DateDigitized[] = "0x9004";
- }
- namespace TagHandler{
- class TagReader{
- public:
- // コンストラクタ.
- TagReader( const wchar_t *JpgFilePath ){
- // Initialize GDI+
- Gdiplus::GdiplusStartupInput gdiplusStartupInput;
- Gdiplus::GdiplusStartup( &gdiplusToken_, &gdiplusStartupInput, NULL );
- size_ = count_ = 0;
- lstrcpy( strPropertyType_, L"" );
- jpgfilepath_ = const_cast<wchar_t*>(JpgFilePath);
- bitmap_ = new Gdiplus::Bitmap( jpgfilepath_ );
- bitmap_->GetPropertySize( &size_, &count_ );
- // GetAllPropertyItemsメンバ関数はPorpertyItem配列を返す
- // なので配列の大きさ分確保しておく
- pPropBuffer_ = (Gdiplus::PropertyItem*)malloc( size_ );
- // PropertyItem配列の取得
- bitmap_->GetAllPropertyItems( size_, count_, pPropBuffer_ );
- }
- // デストラクタ.
- ~TagReader(){
- free( pPropBuffer_ );
- delete bitmap_;
- Gdiplus::GdiplusShutdown( gdiplusToken_ );
- }
- // 関数オブジェクトにするためのオペレータ
- ImageJpegTag::JpegTag operator()(){
- ImageJpegTag::JpegTag t = { 0 };
- t.filepath = const_cast<wchar_t*>(jpgfilepath_);
- char strId[10];
- std::wstring all;
- int c = 0; // すべて表示すると画面に入らないから制限...
- for( UINT i = 0; i < count_; ++i ){
- ImageImage::Util::propertyTypeFromWORD( pPropBuffer_[i].type, strPropertyType_ );
- sprintf( strId, "0x%x", pPropBuffer_[i].id );
- if( strcmp( strId, ImageImage::TagName::Keyword ) == 0 ){
- t.keyword = (wchar_t*)pPropBuffer_[i].value;
- }else if( strcmp( strId, ImageImage::TagName::Comment ) == 0 ){
- t.comment = (wchar_t*)pPropBuffer_[i].value;
- }else if( strcmp( strId, ImageImage::TagName::CameraMaker ) == 0 ){
- t.cameraMaker = (wchar_t*)pPropBuffer_[i].value;
- }else if( strcmp( strId, ImageImage::TagName::CameraModel ) == 0 ){
- t.cameraModel = (wchar_t*)pPropBuffer_[i].value;
- }else if( strcmp( strId, ImageImage::TagName::ProgramName ) == 0 ){
- t.programName = (wchar_t*)pPropBuffer_[i].value;
- }else if( strcmp( strId, ImageImage::TagName::DateCreated ) == 0 ){
- t.dateCreated = (wchar_t*)pPropBuffer_[i].value;
- }else if( strcmp( strId, ImageImage::TagName::Author ) == 0 ){
- t.author = (wchar_t*)pPropBuffer_[i].value;
- }else if( strcmp( strId, ImageImage::TagName::DateOriginal ) == 0 ){
- t.dateOriginal = (wchar_t*)pPropBuffer_[i].value;
- }else if( strcmp( strId, ImageImage::TagName::DateDigitized ) == 0 ){
- t.dateDigitized = (wchar_t*)pPropBuffer_[i].value;
- }else{
- c++;
- if( c <= 15 ){ // 15個までは表示
- wchar_t temp[MAX_PATH*10+1];
- wsprintf( temp, L"ID: %S, DATA: %ld\n", strId, (long)pPropBuffer_[i].value );
- //MessageBoxW( NULL, temp, L"列挙", MB_OK );
- all += temp;
- }
- }
- }
- MessageBoxW( NULL, all.c_str(), L"列挙", MB_OK );
- return t;
- }
- private:
- ULONG_PTR gdiplusToken_;
- Gdiplus::Bitmap* bitmap_;
- UINT size_;
- UINT count_;
- Gdiplus::PropertyItem* pPropBuffer_;
- wchar_t strPropertyType_[50];
- wchar_t* jpgfilepath_;
- };
- }
- }
- namespace ImageImage{
- namespace TagHandler{
- ImageJpegTag::JpegTag read( const wchar_t* filepath ){
- TagHandler::TagReader reader( filepath );
- return reader();
- }
- bool write( const wchar_t* filepath, const ImageJpegTag::JpegTag *tag, int tagId ){
- TagHandler::TagWriter writer( filepath );
- if( tagId == ImageImage::TagId::Keyword ) return writer.writeKeyword( tag->filepath, tag->keyword );
- if( tagId == ImageImage::TagId::Comment ) return writer.writeComment( tag->filepath, tag->comment );
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement