Advertisement
Guest User

Untitled

a guest
Oct 30th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.06 KB | None | 0 0
  1. // これにデータをセットして返す?
  2. namespace ImageJpegTag{
  3. struct JpegTag{
  4. wchar_t* filepath;
  5. wchar_t* keyword;
  6. wchar_t* comment;
  7. wchar_t* cameraMaker;
  8. wchar_t* cameraModel;
  9. wchar_t* programName;
  10. wchar_t* dateCreated;
  11. wchar_t* author;
  12. wchar_t* dateOriginal; // 本来の作成日
  13. wchar_t* dateDigitized; // デジタルにした日付
  14. };
  15. }
  16.  
  17. // タグ書き込みの際のID
  18. namespace CrackImage{
  19. namespace TagId{
  20. const int Keyword = 1;
  21. const int Comment = 2;
  22. }
  23. }
  24.  
  25.  
  26. // GDI+ のヘルプファイルに記述されていたもの
  27. namespace ImageImage{
  28. namespace Util{
  29. void propertyTypeFromWORD( WORD index, WCHAR* str ){
  30. WCHAR* propTypes[] = {
  31. L"Nothing", // 0
  32. L"PropertyTagTypeByte", // 1
  33. L"PropertyTagTypeASCII", // 2
  34. L"PropertyTagTypeShort", // 3
  35. L"PropertyTagTypeLong", // 4
  36. L"PropertyTagTypeRational", // 5
  37. L"Nothing", // 6
  38. L"PropertyTagTypeUndefined", // 7
  39. L"Nothing", // 8
  40. L"PropertyTagTypeSLONG", // 9
  41. L"PropertyTagTypeSRational" // 10
  42. };
  43.  
  44. wcscpy( str, propTypes[index] );
  45. return;
  46. }
  47.  
  48. int getEncoderClsid( const WCHAR* format, CLSID* pClsid ){
  49. UINT num = 0; // イメージエンコーダ数
  50. UINT size = 0; // イメージエンコーダ配列のサイズ
  51.  
  52. Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL;
  53.  
  54. Gdiplus::GetImageEncodersSize( &num, &size );
  55. if( size == 0 ) return -1; // 失敗
  56.  
  57. pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc( size ));
  58. if( pImageCodecInfo == nullptr ) return -1;
  59.  
  60. Gdiplus::GetImageEncoders( num, size, pImageCodecInfo );
  61.  
  62. for( UINT i = 0; i < num; ++i ){
  63. if( wcscmp( pImageCodecInfo[i].MimeType, format ) == 0 ){
  64. *pClsid = pImageCodecInfo[i].Clsid;
  65. free( pImageCodecInfo );
  66. return i; // 成功
  67. }
  68. }
  69. free( pImageCodecInfo );
  70. return -1; // 失敗
  71. }
  72. }
  73. }
  74.  
  75. namespace ImageImage{
  76. namespace TagName{
  77. const char Keyword[] = "0x9c9e";
  78. const char Comment[] = "0x9c9c";
  79. const char CameraMaker[] = "0x10f";
  80. const char CameraModel[] = "0x110";
  81. const char ProgramName[] = "0x131";
  82. const char DateCreated[] = "0x132";
  83. const char Author[] = "0x13b";
  84. const char DateOriginal[] = "0x9003";
  85. const char DateDigitized[] = "0x9004";
  86. }
  87.  
  88. namespace TagHandler{
  89. class TagReader{
  90. public:
  91. // コンストラクタ.
  92. TagReader( const wchar_t *JpgFilePath ){
  93. // Initialize GDI+
  94. Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  95. Gdiplus::GdiplusStartup( &gdiplusToken_, &gdiplusStartupInput, NULL );
  96.  
  97. size_ = count_ = 0;
  98.  
  99. lstrcpy( strPropertyType_, L"" );
  100.  
  101. jpgfilepath_ = const_cast<wchar_t*>(JpgFilePath);
  102.  
  103. bitmap_ = new Gdiplus::Bitmap( jpgfilepath_ );
  104. bitmap_->GetPropertySize( &size_, &count_ );
  105.  
  106. // GetAllPropertyItemsメンバ関数はPorpertyItem配列を返す
  107. // なので配列の大きさ分確保しておく
  108. pPropBuffer_ = (Gdiplus::PropertyItem*)malloc( size_ );
  109.  
  110. // PropertyItem配列の取得
  111. bitmap_->GetAllPropertyItems( size_, count_, pPropBuffer_ );
  112. }
  113.  
  114. // デストラクタ.
  115. ~TagReader(){
  116. free( pPropBuffer_ );
  117. delete bitmap_;
  118. Gdiplus::GdiplusShutdown( gdiplusToken_ );
  119. }
  120.  
  121. // 関数オブジェクトにするためのオペレータ
  122. ImageJpegTag::JpegTag operator()(){
  123. ImageJpegTag::JpegTag t = { 0 };
  124. t.filepath = const_cast<wchar_t*>(jpgfilepath_);
  125. char strId[10];
  126. std::wstring all;
  127. int c = 0; // すべて表示すると画面に入らないから制限...
  128. for( UINT i = 0; i < count_; ++i ){
  129. ImageImage::Util::propertyTypeFromWORD( pPropBuffer_[i].type, strPropertyType_ );
  130. sprintf( strId, "0x%x", pPropBuffer_[i].id );
  131. if( strcmp( strId, ImageImage::TagName::Keyword ) == 0 ){
  132. t.keyword = (wchar_t*)pPropBuffer_[i].value;
  133. }else if( strcmp( strId, ImageImage::TagName::Comment ) == 0 ){
  134. t.comment = (wchar_t*)pPropBuffer_[i].value;
  135. }else if( strcmp( strId, ImageImage::TagName::CameraMaker ) == 0 ){
  136. t.cameraMaker = (wchar_t*)pPropBuffer_[i].value;
  137. }else if( strcmp( strId, ImageImage::TagName::CameraModel ) == 0 ){
  138. t.cameraModel = (wchar_t*)pPropBuffer_[i].value;
  139. }else if( strcmp( strId, ImageImage::TagName::ProgramName ) == 0 ){
  140. t.programName = (wchar_t*)pPropBuffer_[i].value;
  141. }else if( strcmp( strId, ImageImage::TagName::DateCreated ) == 0 ){
  142. t.dateCreated = (wchar_t*)pPropBuffer_[i].value;
  143. }else if( strcmp( strId, ImageImage::TagName::Author ) == 0 ){
  144. t.author = (wchar_t*)pPropBuffer_[i].value;
  145. }else if( strcmp( strId, ImageImage::TagName::DateOriginal ) == 0 ){
  146. t.dateOriginal = (wchar_t*)pPropBuffer_[i].value;
  147. }else if( strcmp( strId, ImageImage::TagName::DateDigitized ) == 0 ){
  148. t.dateDigitized = (wchar_t*)pPropBuffer_[i].value;
  149. }else{
  150. c++;
  151. if( c <= 15 ){ // 15個までは表示
  152. wchar_t temp[MAX_PATH*10+1];
  153. wsprintf( temp, L"ID: %S, DATA: %ld\n", strId, (long)pPropBuffer_[i].value );
  154. //MessageBoxW( NULL, temp, L"列挙", MB_OK );
  155. all += temp;
  156. }
  157. }
  158. }
  159.  
  160. MessageBoxW( NULL, all.c_str(), L"列挙", MB_OK );
  161. return t;
  162. }
  163. private:
  164. ULONG_PTR gdiplusToken_;
  165. Gdiplus::Bitmap* bitmap_;
  166. UINT size_;
  167. UINT count_;
  168. Gdiplus::PropertyItem* pPropBuffer_;
  169. wchar_t strPropertyType_[50];
  170. wchar_t* jpgfilepath_;
  171. };
  172. }
  173. }
  174.  
  175. namespace ImageImage{
  176. namespace TagHandler{
  177. ImageJpegTag::JpegTag read( const wchar_t* filepath ){
  178. TagHandler::TagReader reader( filepath );
  179. return reader();
  180. }
  181.  
  182. bool write( const wchar_t* filepath, const ImageJpegTag::JpegTag *tag, int tagId ){
  183. TagHandler::TagWriter writer( filepath );
  184. if( tagId == ImageImage::TagId::Keyword ) return writer.writeKeyword( tag->filepath, tag->keyword );
  185. if( tagId == ImageImage::TagId::Comment ) return writer.writeComment( tag->filepath, tag->comment );
  186. return false;
  187. }
  188. }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement