forked from mapic91/MpcAsfTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMpctoGif.cpp
119 lines (108 loc) · 3.97 KB
/
MpctoGif.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "wx/log.h"
#include "wx/stream.h"
#include "wx/mstream.h"
#include "wx/filename.h"
#include <fstream>
#include "MpctoPic.hpp"
#include "MpcDecode.hpp"
#include "ShdDecode.hpp"
#include "MAPICDATA.hpp"
//#include "FreeImage_IO_CallBack.hpp"
CovMpctoPic::CovMpctoPic(const wxString inMpcFilePath, const wxString outGifFilePath)
{
inFilePath = inMpcFilePath;
outFilePath = outGifFilePath;
}
bool CovMpctoPic::Save(FileType type, bool ShdIncluded, long direction, long interval,
long bottom, long left, bool makeshadow,
long offsetsunx, long offsetsuny,long offsetposx, long offsetposy)
{
if(inFilePath.IsEmpty() || outFilePath.IsEmpty()) return false;
else
{
unsigned long framessum, width, height;
FILOCRGBQUAD *strdata = NULL, *shddata;
MpcDecode decode;
ShdDecode shddecode;
MAPICDATA data;
wxString shdpath;
bool shdicl = false;
if(!decode.ReadMpcFile(inFilePath)) return false;
framessum = decode.GetFramesCounts();
width = decode.GetGlobleWidth();
height = decode.GetGlobleHeight();
data.Init((long)width, (long)height);
if(ShdIncluded)
{
shdpath = wxFileName::FileName(inFilePath).GetPath(wxPATH_GET_VOLUME|wxPATH_GET_SEPARATOR);
shdpath += wxFileName::FileName(inFilePath).GetName();
shdpath += wxT(".shd");
if(wxFileName::FileExists(shdpath))
{
if(shddecode.ReadShdFile(shdpath))
{
if(shddecode.GetGlobleWidth() == (long)width &&
shddecode.GetGlobleHeight() == (long)height)
{
shdicl = true;
}
}
}
}
for(unsigned long i = 0; i < framessum; i++)
{
strdata = decode.GetGlobleFIDecodedFrameData(i, NULL, NULL, MpcDecode::PIC_RGBA);
if(!strdata)
{
return false;
}
if(shdicl)
{
shddata = shddecode.GetGlobleFIDecodedFrameData(i, NULL, NULL, ShdDecode::PIC_RGBA);
if(shddata)
{
for(unsigned long sidx = 0; sidx < width*height; sidx++)
{
if(strdata[sidx].rgbReserved != 0)
{
shddata[sidx].rgbBlue = strdata[sidx].rgbBlue;
shddata[sidx].rgbGreen = strdata[sidx].rgbGreen;
shddata[sidx].rgbRed = strdata[sidx].rgbRed;
shddata[sidx].rgbReserved = strdata[sidx].rgbReserved;
}
}
delete[] strdata;
strdata = shddata;
}
}
data.AddFrame(strdata);
}
if(type == T_GIF)
{
if(!data.SaveToGif(outFilePath)) return false;
wxMessageBox(wxT("GIF文件已保存"));
return true;
}
else if(type == T_PNG)
{
wxString infilename = wxFileName::FileName(inFilePath).GetName();
if(!data.SaveToPng(outFilePath+wxFileName::GetPathSeparator()+infilename)) return false;
wxMessageBox(wxT("PNG文件已保存"));
return true;
}
else if(type == T_MPC)
{
if(!data.SaveToMpc(outFilePath, direction, interval, bottom, makeshadow)) return false;
wxMessageBox(wxT("MPC文件已保存"));
return true;
}
else if(type == T_ASF)
{
if(!data.SaveToAsf(outFilePath, direction, interval, bottom, left, makeshadow,
offsetsunx, offsetsuny, offsetposx, offsetposy)) return false;
wxMessageBox(wxT("ASF文件已保存"));
return true;
}
}
return true;
}