-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·201 lines (180 loc) · 8.36 KB
/
main.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//---------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <algorithm>
#include <Jpeg.hpp>
#include <vector>
using std::min;
using std::max;
#include <gdiplus.h>
#include <vcl.h>
#pragma hdrstop
#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
using namespace Gdiplus;
TForm1 *Form1;
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
unsigned int num = 0; // number of image encoders
unsigned int size = 0; // size of the image encoder array in bytes
Gdiplus::GetImageEncodersSize(&num, &size);
if(size == 0)return -1;
Gdiplus::ImageCodecInfo* imageCodecInfo = new Gdiplus::ImageCodecInfo[size];
Gdiplus::GetImageEncoders(num, size, imageCodecInfo);
for(unsigned int i = 0; i < num; ++i)
{
if( wcscmp(imageCodecInfo[i].MimeType, format) == 0 )
{
*pClsid = imageCodecInfo[i].Clsid;
delete[] imageCodecInfo;
return i;
}
}
delete[] imageCodecInfo;
return -1;
}
void oPliki(AnsiString Nazwa_Katalogu)
{
TSearchRec sr;
if(FindFirst(Nazwa_Katalogu+"\\*.*",faDirectory, sr)==0)
{
if(((sr.Attr & faDirectory) != faDirectory)&&(sr.Name!=".")&&(sr.Name!="..")&&
((UpperCase (ExtractFileExt (sr. Name))==".BMP")||
(UpperCase (ExtractFileExt (sr. Name))==".JPG")||
(UpperCase (ExtractFileExt (sr. Name))==".JPEG")||
(UpperCase (ExtractFileExt (sr. Name))==".GIF")||
(UpperCase (ExtractFileExt (sr. Name))==".BMP")||
(UpperCase (ExtractFileExt (sr. Name))==".TIFF")||
(UpperCase (ExtractFileExt (sr. Name))==".PNG")||
(UpperCase (ExtractFileExt (sr. Name))==".EMF")||
(UpperCase (ExtractFileExt (sr. Name))==".TIF")) )
{
if(Form1->CheckBox2->Checked)
{
/*AnsiString buf = sr.Name;
fixname(&sr.Name);
if(buf!=sr.Name)
RenameFile(Nazwa_Katalogu+"\\"+buf,Nazwa_Katalogu+"\\"+sr.Name); */
}
Form1->status->SimpleText = "Przetwarzam: "+sr.Name;
if (!DirectoryExists(Nazwa_Katalogu+"\\"+Form1->m->Text))
CreateDir(Nazwa_Katalogu+"\\"+Form1->m->Text);
if(!FileExists(Nazwa_Katalogu+"\\"+Form1->m->Text+"\\"+sr.Name)||(Form1->CheckBox1->Checked)){
Gdiplus::Bitmap image(WideString(Nazwa_Katalogu+"\\"+sr.Name).c_bstr());
Gdiplus::Image* Thumbnail = image.GetThumbnailImage(Form1->szerokosc->Value, Form1->wysokosc->Value, NULL, NULL);
Gdiplus::Graphics grphx(Form1->Image1->Canvas->Handle);
grphx.DrawImage(Thumbnail, 0, 0,Thumbnail->GetWidth(), Thumbnail->GetHeight());
Form1->Image1->Refresh();
CLSID gifClsid;
GetEncoderClsid(L"image/jpeg", &gifClsid);
sr.Name = StringReplace(sr.Name, ExtractFileExt(sr.Name), ".jpg",TReplaceFlags() << rfReplaceAll);
Thumbnail->Save(WideString(Nazwa_Katalogu+"\\"+Form1->m->Text+"\\"+sr.Name), &gifClsid, NULL);
delete Thumbnail;
Application->ProcessMessages();
}
}
while(FindNext(sr) == 0)
if(((sr.Attr & faDirectory) != faDirectory)&&(sr.Name!=".")&&(sr.Name!="..")&&
((UpperCase (ExtractFileExt (sr. Name))==".BMP")||
(UpperCase (ExtractFileExt (sr. Name))==".JPG")||
(UpperCase (ExtractFileExt (sr. Name))==".JPEG")||
(UpperCase (ExtractFileExt (sr. Name))==".GIF")||
(UpperCase (ExtractFileExt (sr. Name))==".BMP")||
(UpperCase (ExtractFileExt (sr. Name))==".TIFF")||
(UpperCase (ExtractFileExt (sr. Name))==".PNG")||
(UpperCase (ExtractFileExt (sr. Name))==".EMF")||
(UpperCase (ExtractFileExt (sr. Name))==".TIF")) )
{
Form1->status->SimpleText = "Przetwarzam: "+sr.Name;
if(Form1->CheckBox2->Checked){
/* AnsiString buf = sr.Name;
fixname(&sr.Name);
if(buf!=sr.Name)
RenameFile(Nazwa_Katalogu+"\\"+buf,Nazwa_Katalogu+"\\"+sr.Name); */
}
if (!DirectoryExists(Nazwa_Katalogu+"\\"+Form1->m->Text))
CreateDir(Nazwa_Katalogu+"\\"+Form1->m->Text);
if(!FileExists(Nazwa_Katalogu+"\\"+Form1->m->Text+"\\"+sr.Name)||(Form1->CheckBox1->Checked)){
Gdiplus::Bitmap image(WideString(Nazwa_Katalogu+"\\"+sr.Name).c_bstr());
Gdiplus::Image* Thumbnail = image.GetThumbnailImage(Form1->szerokosc->Value, Form1->wysokosc->Value, NULL, NULL);
Gdiplus::Graphics grphx(Form1->Image1->Canvas->Handle);
grphx.DrawImage(Thumbnail, 0, 0,Thumbnail->GetWidth(), Thumbnail->GetHeight());
Form1->Image1->Refresh();
CLSID gifClsid;
GetEncoderClsid(L"image/jpeg", &gifClsid);
sr.Name = StringReplace(sr.Name, ExtractFileExt(sr.Name), ".jpg", TReplaceFlags() << rfReplaceAll);
Thumbnail->Save(WideString(Nazwa_Katalogu+"\\"+Form1->m->Text+"\\"+sr.Name), &gifClsid, NULL);
delete Thumbnail;
}
}
Application->ProcessMessages();
FindClose(sr);
}
}
void oKatalogi(AnsiString gdzie)
{
std::vector<AnsiString*> directory;
TSearchRec sr;
directory.push_back(new AnsiString(gdzie));
oPliki(gdzie);
for (int i = 0; i < directory.size(); ++i){
if(FindFirst(*directory[i]+"\\*.*",faDirectory, sr)==0){
if(((sr.Attr & faDirectory) == faDirectory)&&(sr.Name!=".")&&(sr.Name!="..")&&(sr.Name!=Form1->m->Text)) {
if(Form1->CheckBox2->Checked)
{ /*
AnsiString buf = sr.Name;
fixname(&sr.Name);
if(buf!=sr.Name)
RenameFile(k->NazwaKatalogu()+"\\"+buf,k->NazwaKatalogu()+"\\"+sr.Name); */
}
directory.push_back(new AnsiString(*directory[i]+"\\"+sr.Name));
Form1->status->SimpleText = "Przetwarzam: "+sr.Name;
Application->ProcessMessages();
} // if(((sr.Attr & faDirectory) == faDirectory)&&(sr.Name!=".")&&(sr.Name!="..")&&(sr.Name!=Form1->m->Text))
while(FindNext(sr) == 0){
if(((sr.Attr & faDirectory) == faDirectory)&&(sr.Name!=".")&&(sr.Name!="..")&&(sr.Name!=Form1->m->Text)) {
if(Form1->CheckBox2->Checked)
{ /*
AnsiString buf = sr.Name;
fixname(&sr.Name);
if(buf!=sr.Name)
RenameFile(k->NazwaKatalogu()+"\\"+buf,k->NazwaKatalogu()+"\\"+sr.Name); */
}
directory.push_back(new AnsiString(*directory[i]+"\\"+sr.Name));
Form1->status->SimpleText = "Przetwarzam: "+sr.Name;
Application->ProcessMessages();
} //if(((sr.Attr & faDirectory) == faDirectory)&&(sr.Name!=".")&&(sr.Name!="..")&&(sr.Name!=Form1->m->Text))
} //while
FindClose(sr);
} //if(FindFirst(*directory[i]+"\\*.*",faDirectory, sr)==0){
} //for
for (int i = 0; i < directory.size(); ++i)
oPliki(*directory[i]);
//free memory
Form1->status->SimpleText = "Zakoñczono tworzenie miniatur. ";
for (int i = 0; i < directory.size(); ++i) delete directory[i];
};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
Gdiplus::GdiplusShutdown(gdiplusToken);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
oKatalogi(dir->Directory);
}
//---------------------------------------------------------------------------