forked from mapic91/MpcAsfTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAsftoPic.cpp
93 lines (86 loc) · 3.38 KB
/
AsftoPic.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
#include "AsftoPic.hpp"
#include "AsfDecode.hpp"
#include "MAPICDATA.hpp"
//#include "FreeImage_IO_CallBack.hpp"
#include "FreeImage.h"
#include "wx/log.h"
#include "wx/stream.h"
#include "wx/mstream.h"
#include "wx/filename.h"
#include <fstream>
CovAsftoPic::CovAsftoPic(const wxString inMpcFilePath, const wxString outGifFilePath)
{
inFilePath = inMpcFilePath;
outFilePath = outGifFilePath;
}
bool CovAsftoPic::Save(FileType type, Palette_Colour *backcolor, unsigned char transmask,
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;
//bool res, istran;
//BYTE *strdata = NULL, transidx;
FILOCRGBQUAD *strdata = NULL;
AsfDecode decode;
MAPICDATA data;
if(!decode.ReadAsfFile(inFilePath))return false;
framessum = decode.GetFramesCounts();
width = decode.GetGlobleWidth();
height = decode.GetGlobleHeight();
data.Init((long)width, (long)height);
if(type == T_GIF)
{
for(unsigned long i = 0; i < framessum; i++)
{
strdata = decode.GetFIDecodedFrameData(i, NULL, NULL, AsfDecode::PIC_RGB, NULL, backcolor, transmask);
if(!strdata)return false;
data.AddFrame(strdata);
}
if(!data.SaveToGif(outFilePath)) return false;
wxMessageBox(wxT("GIF文件已保存"));
return true;
}
else if(type == T_PNG)
{
for(unsigned long i = 0; i < framessum; i++)
{
strdata = decode.GetFIDecodedFrameData(i, NULL, NULL, AsfDecode::PIC_RGBA, NULL, backcolor);
if(!strdata)return false;
data.AddFrame(strdata);
}
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)
{
for(unsigned long i = 0; i < framessum; i++)
{
strdata = decode.GetFIDecodedFrameData(i, NULL, NULL, AsfDecode::PIC_RGB, NULL, backcolor, transmask);
if(!strdata)return false;
data.AddFrame(strdata);
}
if(!data.SaveToMpc(outFilePath, direction, interval, bottom, makeshadow)) return false;
wxMessageBox(wxT("MPC文件已保存"));
return true;
}
else if(type == T_ASF)
{
for(unsigned long i = 0; i < framessum; i++)
{
strdata = decode.GetFIDecodedFrameData(i, NULL, NULL, AsfDecode::PIC_RGBA, NULL, backcolor);
if(!strdata)return false;
data.AddFrame(strdata);
}
if(!data.SaveToAsf(outFilePath, direction, interval, bottom, left, makeshadow,
offsetsunx, offsetsuny, offsetposx, offsetposy)) return false;
wxMessageBox(wxT("ASF文件已保存"));
return true;
}
}
return true;
}