Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
I
ImgGen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ImgGen
Commits
f137400f
Commit
f137400f
authored
Apr 28, 2020
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve memory alloc by JoyJ
parent
df92db27
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
39 deletions
+38
-39
DataManager.cs
DataManager.cs
+17
-35
Program.cs
Program.cs
+21
-4
No files found.
DataManager.cs
View file @
f137400f
...
@@ -18,9 +18,6 @@ namespace ImgGen
...
@@ -18,9 +18,6 @@ namespace ImgGen
private
static
Bitmap
[]
bLinkNums
=
new
Bitmap
[
8
];
private
static
Bitmap
[]
bLinkNums
=
new
Bitmap
[
8
];
private
static
Bitmap
[]
bLinkMarkers
=
new
Bitmap
[
9
];
private
static
Bitmap
[]
bLinkMarkers
=
new
Bitmap
[
9
];
private
static
Dictionary
<
int
,
Data
>
cardDatas
=
new
Dictionary
<
int
,
Data
>();
private
static
Dictionary
<
int
,
Bitmap
>
cardImages
=
new
Dictionary
<
int
,
Bitmap
>();
private
static
SQLiteConnection
conn
;
private
static
SQLiteConnection
conn
;
private
static
object
locker
=
new
object
();
private
static
object
locker
=
new
object
();
...
@@ -151,35 +148,23 @@ namespace ImgGen
...
@@ -151,35 +148,23 @@ namespace ImgGen
}
}
public
static
Bitmap
GetImage
(
int
code
)
public
static
Bitmap
GetImage
(
int
code
)
{
if
(!
cardImages
.
ContainsKey
(
code
))
{
LoadCard
(
code
);
}
return
cardImages
[
code
];
}
private
static
int
LoadCard
(
int
code
)
{
{
lock
(
locker
)
lock
(
locker
)
{
{
if
(
cardDatas
.
ContainsKey
(
code
))
{
return
0
;
}
Data
data
=
new
Data
();
Data
data
=
new
Data
();
Text
text
=
new
Text
();
Text
text
=
new
Text
();
data
.
code
=
code
;
data
.
code
=
code
;
text
.
name
=
"???"
;
text
.
name
=
"???"
;
text
.
text
=
"???"
;
text
.
text
=
"???"
;
SQLiteCommand
command
=
null
;
SQLiteDataReader
reader
=
null
;
try
try
{
{
conn
.
Open
();
conn
.
Open
();
SQLiteCommand
command
=
new
SQLiteCommand
(
conn
);
command
=
new
SQLiteCommand
(
conn
);
SQLiteDataReader
reader
;
command
.
CommandText
=
$"SELECT * FROM datas WHERE id=
{
code
}
"
;
command
.
CommandText
=
$"SELECT * FROM datas WHERE id=
{
code
}
"
;
reader
=
command
.
ExecuteReader
();
reader
=
command
.
ExecuteReader
();
if
(
reader
.
Read
())
if
(
reader
.
Read
())
{
{
data
.
code
=
reader
.
GetInt32
(
0
);
data
.
code
=
reader
.
GetInt32
(
0
);
...
@@ -196,28 +181,27 @@ namespace ImgGen
...
@@ -196,28 +181,27 @@ namespace ImgGen
command
.
CommandText
=
$"SELECT * FROM texts WHERE id=
{
code
}
"
;
command
.
CommandText
=
$"SELECT * FROM texts WHERE id=
{
code
}
"
;
reader
=
command
.
ExecuteReader
();
reader
=
command
.
ExecuteReader
();
if
(
reader
.
Read
())
if
(
reader
.
Read
())
{
{
text
.
name
=
reader
.
GetString
(
1
);
text
.
name
=
reader
.
GetString
(
1
);
text
.
text
=
reader
.
GetString
(
2
);
text
.
text
=
reader
.
GetString
(
2
);
}
}
reader
.
Close
();
reader
.
Close
();
return
DrawCard
(
data
,
text
);
}
}
catch
catch
(
Exception
e
)
{
{
Console
.
WriteLine
(
$"Error when parsing
{
code
}
-
{
e
}
"
);
return
null
;
}
}
finally
finally
{
{
reader
?.
Close
();
command
?.
Dispose
();
conn
.
Close
();
conn
.
Close
();
}
}
cardDatas
.
Add
(
code
,
data
);
if
(!
cardImages
.
ContainsKey
(
code
))
{
Bitmap
bitmap
;
bitmap
=
DrawCard
(
data
,
text
);
cardImages
.
Add
(
code
,
bitmap
);
}
return
0
;
}
}
}
}
...
@@ -249,7 +233,7 @@ namespace ImgGen
...
@@ -249,7 +233,7 @@ namespace ImgGen
private
static
void
DrawPicture
(
Graphics
graphics
,
Data
data
)
private
static
void
DrawPicture
(
Graphics
graphics
,
Data
data
)
{
{
Bitmap
image
;
Bitmap
image
=
null
;
string
filename
=
"./pico/"
+
data
.
code
.
ToString
()
+
".png"
;
string
filename
=
"./pico/"
+
data
.
code
.
ToString
()
+
".png"
;
if
(!
File
.
Exists
(
filename
))
if
(!
File
.
Exists
(
filename
))
filename
=
"./pico/"
+
data
.
code
.
ToString
()
+
".jpg"
;
filename
=
"./pico/"
+
data
.
code
.
ToString
()
+
".jpg"
;
...
@@ -259,11 +243,7 @@ namespace ImgGen
...
@@ -259,11 +243,7 @@ namespace ImgGen
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
#if DEBUG
Console
.
WriteLine
(
$"Error when parsing
{
data
.
code
}
-
{
e
}
"
);
Console
.
WriteLine
(
$"Error parsing [
{
data
.
code
}
] :
{
e
.
Message
}
"
);
#else
Console
.
WriteLine
(
$"Error parsing [
{
data
.
code
}
] :
{
e
}
"
);
#endif
return
;
return
;
}
}
if
(
data
.
isType
(
Type
.
TYPE_PENDULUM
))
if
(
data
.
isType
(
Type
.
TYPE_PENDULUM
))
...
@@ -290,6 +270,7 @@ namespace ImgGen
...
@@ -290,6 +270,7 @@ namespace ImgGen
else
else
graphics
.
DrawImage
(
image
,
dest
);
graphics
.
DrawImage
(
image
,
dest
);
}
}
image
?.
Dispose
();
}
}
private
static
void
DrawTemplate
(
Graphics
graphics
,
Data
data
)
private
static
void
DrawTemplate
(
Graphics
graphics
,
Data
data
)
...
@@ -359,6 +340,7 @@ namespace ImgGen
...
@@ -359,6 +340,7 @@ namespace ImgGen
template
=
new
Bitmap
(
bTemplates
[
8
]);
template
=
new
Bitmap
(
bTemplates
[
8
]);
}
}
graphics
.
DrawImage
(
template
,
0
,
0
,
400
,
580
);
graphics
.
DrawImage
(
template
,
0
,
0
,
400
,
580
);
template
.
Dispose
();
}
}
private
static
void
DrawStars
(
Graphics
graphics
,
Data
data
)
private
static
void
DrawStars
(
Graphics
graphics
,
Data
data
)
...
@@ -660,7 +642,7 @@ namespace ImgGen
...
@@ -660,7 +642,7 @@ namespace ImgGen
DrawSpellTrapType
(
graphics
,
data
);
DrawSpellTrapType
(
graphics
,
data
);
DrawSpellTrapEffect
(
graphics
,
desc
);
DrawSpellTrapEffect
(
graphics
,
desc
);
}
}
graphics
.
Dispose
();
return
bitmap
;
return
bitmap
;
}
}
...
...
Program.cs
View file @
f137400f
...
@@ -39,7 +39,9 @@ namespace ImgGen
...
@@ -39,7 +39,9 @@ namespace ImgGen
List
<
string
>
files
=
new
List
<
string
>();
List
<
string
>
files
=
new
List
<
string
>();
files
.
AddRange
(
Directory
.
GetFiles
(
"./pico"
,
"*.png"
));
files
.
AddRange
(
Directory
.
GetFiles
(
"./pico"
,
"*.png"
));
files
.
AddRange
(
Directory
.
GetFiles
(
"./pico"
,
"*.jpg"
));
files
.
AddRange
(
Directory
.
GetFiles
(
"./pico"
,
"*.jpg"
));
bool
generateLarge
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateLarge"
]
!=
"False"
;
// true if AppSettings null
bool
generateSmall
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateSmall"
]
==
"True"
;
bool
generateSmall
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateSmall"
]
==
"True"
;
bool
generateThumb
=
System
.
Configuration
.
ConfigurationManager
.
AppSettings
[
"GenerateThumb"
]
==
"True"
;
if
(
generateLarge
)
if
(
generateLarge
)
Directory
.
CreateDirectory
(
"./picn"
);
Directory
.
CreateDirectory
(
"./picn"
);
if
(
generateSmall
)
if
(
generateSmall
)
...
@@ -53,20 +55,35 @@ namespace ImgGen
...
@@ -53,20 +55,35 @@ namespace ImgGen
{
{
code
=
int
.
Parse
(
Path
.
GetFileNameWithoutExtension
(
str
));
code
=
int
.
Parse
(
Path
.
GetFileNameWithoutExtension
(
str
));
}
}
catch
(
Exception
)
catch
{
{
continue
;
continue
;
}
}
string
fileName
=
code
.
ToString
()
+
".jpg"
;
string
fileName
=
code
.
ToString
()
+
".jpg"
;
Console
.
WriteLine
(
$"Generating
{
fileName
}
"
);
Console
.
WriteLine
(
$"Generating
{
fileName
}
"
);
Bitmap
image
=
DataManager
.
GetImage
(
code
);
Bitmap
image
=
DataManager
.
GetImage
(
code
);
if
(
image
==
null
)
{
Console
.
WriteLine
(
$"[
{
code
}
] generation failed"
);
continue
;
}
if
(
generateLarge
)
if
(
generateLarge
)
{
image
.
Save
(
"./picn/"
+
fileName
,
encoderInfo
,
encoderParams
);
image
.
Save
(
"./picn/"
+
fileName
,
encoderInfo
,
encoderParams
);
}
if
(
generateSmall
)
if
(
generateSmall
)
DataManager
.
Zoom
(
image
,
177
,
254
).
Save
(
"./pics/"
+
fileName
,
encoderInfo
,
encoderParams
);
{
Bitmap
bmp
=
DataManager
.
Zoom
(
image
,
177
,
254
);
bmp
.
Save
(
"./pics/"
+
fileName
,
encoderInfo
,
encoderParams
);
bmp
.
Dispose
();
}
if
(
generateThumb
)
if
(
generateThumb
)
DataManager
.
Zoom
(
image
,
44
,
64
).
Save
(
"./pics/thumbnail/"
+
fileName
,
encoderInfo
,
encoderParams
);
{
image
.
Dispose
();
Bitmap
bmp
=
DataManager
.
Zoom
(
image
,
44
,
64
);
bmp
.
Save
(
"./pics/thumbnail/"
+
fileName
,
encoderInfo
,
encoderParams
);
bmp
.
Dispose
();
}
image
?.
Dispose
();
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment