Commit 45e75646 authored by ElenaSubbotina's avatar ElenaSubbotina Committed by Alexander Trofimov

DocFormatReader - конвертация dib картинок в png (user_manual_v52.doc)

parent 08399f16
...@@ -81,7 +81,6 @@ namespace DocFileFormat ...@@ -81,7 +81,6 @@ namespace DocFileFormat
void OpenXmlPackage::SaveToFile( const std::wstring& outputDir, const std::wstring& fileName, const void* buf, unsigned int size ) void OpenXmlPackage::SaveToFile( const std::wstring& outputDir, const std::wstring& fileName, const void* buf, unsigned int size )
{ {
if ( buf != NULL ) if ( buf != NULL )
{ {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h" #include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h"
#include "../../Common/DocxFormat/Source/SystemUtility/FileSystem/Directory.h" #include "../../Common/DocxFormat/Source/SystemUtility/FileSystem/Directory.h"
#include "../../DesktopEditor/raster/BgraFrame.h"
namespace ImageHelper namespace ImageHelper
{ {
inline static int CompareStrings (const wchar_t* str1, const wchar_t* str2) inline static int CompareStrings (const wchar_t* str1, const wchar_t* str2)
...@@ -16,92 +18,34 @@ namespace ImageHelper ...@@ -16,92 +18,34 @@ namespace ImageHelper
return 1; return 1;
} }
//inline static void GetEncoderCLSID (const wchar_t* pFormat, CLSID* pClsid) inline bool SaveImageToFileFromDIB(unsigned char* buffer, int size, const std::wstring& file)
//{ {
// // variables bool result = false;
// UINT nEncoders = 0; const BITMAPINFOHEADER* info = (BITMAPINFOHEADER*)buffer;
// UINT nSize = 0;
// Gdiplus::ImageCodecInfo* pImageCodecInfo = 0; if (NULL != info && info->biSize == 40)
{
// // retrieve encoders info unsigned char* pBgraData = buffer + sizeof(BITMAPINFOHEADER);
// Gdiplus::GetImageEncodersSize(&nEncoders, &nSize);
int nWidth = info->biWidth;
// // check for valid encoders int nHeight = info->biHeight;
// if (!nSize)
// throw 0; CBgraFrame oFrame;
oFrame.put_Data (pBgraData);
// // create encoders info structure of necessary size oFrame.put_Width (nWidth);
// pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(nSize)); oFrame.put_Height (nHeight);
// // check for valid encoder int nStride = info->biSizeImage / nHeight;
// if (!pImageCodecInfo) oFrame.put_Stride( -nStride );
// throw 0;
result = oFrame.SaveFile(file, 4);
// // retrieve all encoders
// Gdiplus::GetImageEncoders(nEncoders, nSize, pImageCodecInfo); oFrame.put_Data(NULL);
// // locate necessary encoder }
// for (UINT nEncoder = 0; nEncoder < nEncoders; ++nEncoder)
// { return result;
// // compare MIME strings }
// if (CompareStrings(pImageCodecInfo[nEncoder].MimeType, pFormat) == 0)
// {
// // save CLSID
// *pClsid = pImageCodecInfo[nEncoder].Clsid;
// // clear memory
// free(pImageCodecInfo);
// // all ok
// return;
// }
// }
// // clear memory
// free(pImageCodecInfo);
// // codec not found
// throw 0;
//}
//inline bool SaveImageToFileFromDIB(unsigned char* buffer, const std::wstring& file)
//{
// const BITMAPFILEHEADER* bmfh = (BITMAPFILEHEADER*)buffer;
// const BITMAPINFO* info = (BITMAPINFO*)buffer;
// if (NULL != bmfh && NULL != info)
// {
// HDC hdc = GetDC(NULL);
// if (hdc)
// {
// HBITMAP hbm = ::CreateDIBitmap(hdc, &info->bmiHeader, CBM_INIT, (buffer + sizeof(BITMAPINFO)), info, DIB_RGB_COLORS);
// if (hbm)
// {
// Gdiplus::Bitmap oBitmap (hbm, NULL);
// if (Gdiplus::Ok == oBitmap.GetLastStatus())
// {
// CLSID guid;
// GetEncoderCLSID (L"image/png", &guid);
// if (Gdiplus::Ok == oBitmap.Save (file.c_str(), &guid))
// {
// oBitmap.Save(file.c_str(), &guid);
// DeleteObject(hbm);
// ReleaseDC(NULL, hdc);
// return (Gdiplus::Ok == oBitmap.GetLastStatus());
// }
// }
// DeleteObject(hbm);
// }
// ReleaseDC(NULL, hdc);
// }
// }
// return false;
//}
} }
namespace DocFileFormat namespace DocFileFormat
...@@ -154,18 +98,13 @@ namespace DocFileFormat ...@@ -154,18 +98,13 @@ namespace DocFileFormat
copy(iter->data.begin(), iter->data.end(), bytes); copy(iter->data.begin(), iter->data.end(), bytes);
if (Global::msoblipDIB == iter->blipType) if (Global::msoblipDIB == iter->blipType)
{ {//user_manual_v52.doc
std::wstring file = string2std_string(pathMedia.GetPath()) + FILE_SEPARATOR_STR + _T("image") + FormatUtils::IntToWideString(i++) + iter->ext; std::wstring file_name = string2std_string(pathMedia.GetPath()) + FILE_SEPARATOR_STR + _T("image") + FormatUtils::IntToWideString(i++) + iter->ext;
//ImageHelper::SaveImageToFileFromDIB(bytes, file); ImageHelper::SaveImageToFileFromDIB(bytes, iter->data.size(), file_name);
//todooo ... any system
} }
else else
{ {
SaveToFile(string2std_string(pathMedia.GetPath()), std::wstring(_T("image" )) + FormatUtils::IntToWideString(i++) + iter->ext, (void*)bytes, (unsigned int)iter->data.size()); SaveToFile(string2std_string(pathMedia.GetPath()), std::wstring(_T("image" )) + FormatUtils::IntToWideString(i++) + iter->ext, (void*)bytes, (unsigned int)iter->data.size());
} }
RELEASEARRAYOBJECTS(bytes); RELEASEARRAYOBJECTS(bytes);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment