Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro
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
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
ygopro
Commits
afd7fbf4
Commit
afd7fbf4
authored
Feb 03, 2026
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor ImageManager
parent
975a134e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
54 deletions
+74
-54
gframe/image_manager.cpp
gframe/image_manager.cpp
+70
-54
gframe/image_manager.h
gframe/image_manager.h
+4
-0
No files found.
gframe/image_manager.cpp
View file @
afd7fbf4
...
...
@@ -119,7 +119,8 @@ void ImageManager::ResizeTexture() {
if
(
!
tBackGround_deck
)
tBackGround_deck
=
tBackGround
;
}
// function by Warr1024, from https://github.com/minetest/minetest/issues/2419 , modified
/** Scale image using nearest neighbor anti-aliasing.
* Function by Warr1024, from https://github.com/minetest/minetest/issues/2419, modified. */
void
imageScaleNNAA
(
irr
::
video
::
IImage
*
src
,
irr
::
video
::
IImage
*
dest
)
{
const
auto
&
srcDim
=
src
->
getDimension
();
const
auto
&
destDim
=
dest
->
getDimension
();
...
...
@@ -192,22 +193,63 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
}
}
// end of parallel region
}
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureFromFile
(
const
char
*
file
,
irr
::
s32
width
,
irr
::
s32
height
)
{
irr
::
video
::
ITexture
*
texture
;
irr
::
video
::
IImage
*
srcimg
=
driver
->
createImageFromFile
(
file
);
/** Convert image to texture, resizing if needed.
* @param name Texture name (Irrlicht texture key).
* @param srcimg Source image; will be dropped by this function.
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`). */
irr
::
video
::
ITexture
*
ImageManager
::
addTexture
(
const
char
*
name
,
irr
::
video
::
IImage
*
srcimg
,
irr
::
s32
width
,
irr
::
s32
height
)
{
if
(
srcimg
==
nullptr
)
return
nullptr
;
irr
::
video
::
ITexture
*
texture
;
if
(
srcimg
->
getDimension
()
==
irr
::
core
::
dimension2d
<
irr
::
u32
>
(
width
,
height
))
{
texture
=
driver
->
addTexture
(
fil
e
,
srcimg
);
texture
=
driver
->
addTexture
(
nam
e
,
srcimg
);
}
else
{
irr
::
video
::
IImage
*
destimg
=
driver
->
createImage
(
srcimg
->
getColorFormat
(),
irr
::
core
::
dimension2d
<
irr
::
u32
>
(
width
,
height
));
irr
::
video
::
IImage
*
destimg
=
driver
->
createImage
(
srcimg
->
getColorFormat
(),
irr
::
core
::
dimension2d
<
irr
::
u32
>
(
width
,
height
));
imageScaleNNAA
(
srcimg
,
destimg
);
texture
=
driver
->
addTexture
(
fil
e
,
destimg
);
texture
=
driver
->
addTexture
(
nam
e
,
destimg
);
destimg
->
drop
();
}
srcimg
->
drop
();
return
texture
;
}
/** Load image from file and convert to texture.
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`). */
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureFromFile
(
const
char
*
file
,
irr
::
s32
width
,
irr
::
s32
height
)
{
irr
::
video
::
IImage
*
img
=
driver
->
createImageFromFile
(
file
);
if
(
img
==
nullptr
)
{
return
nullptr
;
}
char
name
[
256
];
mysnprintf
(
name
,
"%s/%d_%d"
,
file
,
width
,
height
);
return
addTexture
(
name
,
img
,
width
,
height
);
}
/** Load card picture from `expansions` or `pics` folder.
* Files in the expansions directory have priority, allowing custom pictures to be loaded without modifying the original files.
* @return Image pointer. Must be dropped after use. */
irr
::
video
::
IImage
*
ImageManager
::
GetImage
(
int
code
)
{
char
file
[
256
];
mysnprintf
(
file
,
"expansions/pics/%d.jpg"
,
code
);
irr
::
video
::
IImage
*
img
=
driver
->
createImageFromFile
(
file
);
if
(
img
==
nullptr
)
{
mysnprintf
(
file
,
"pics/%d.jpg"
,
code
);
img
=
driver
->
createImageFromFile
(
file
);
}
return
img
;
}
/** Load card picture.
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`). */
irr
::
video
::
ITexture
*
ImageManager
::
GetTexture
(
int
code
,
irr
::
s32
width
,
irr
::
s32
height
)
{
irr
::
video
::
IImage
*
img
=
GetImage
(
code
);
if
(
img
==
nullptr
)
{
return
nullptr
;
}
char
name
[
256
];
mysnprintf
(
name
,
"pics/%d/%d_%d"
,
code
,
width
,
height
);
return
addTexture
(
name
,
img
,
width
,
height
);
}
/** Load managed card picture texture.
* @param fit Resize to fit scale if true.
* @return Texture pointer. Should NOT be removed nor dropped. */
irr
::
video
::
ITexture
*
ImageManager
::
GetTexture
(
int
code
,
bool
fit
)
{
if
(
code
==
0
)
return
fit
?
tUnknownFit
:
tUnknown
;
...
...
@@ -222,21 +264,17 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
}
auto
tit
=
tMap
[
fit
?
1
:
0
].
find
(
code
);
if
(
tit
==
tMap
[
fit
?
1
:
0
].
end
())
{
char
file
[
256
];
mysnprintf
(
file
,
"expansions/pics/%d.jpg"
,
code
);
irr
::
video
::
ITexture
*
img
=
GetTextureFromFile
(
file
,
width
,
height
);
if
(
img
==
nullptr
)
{
mysnprintf
(
file
,
"pics/%d.jpg"
,
code
);
img
=
GetTextureFromFile
(
file
,
width
,
height
);
}
tMap
[
fit
?
1
:
0
][
code
]
=
img
;
return
(
img
==
nullptr
)
?
(
fit
?
tUnknownFit
:
tUnknown
)
:
img
;
irr
::
video
::
ITexture
*
texture
=
GetTexture
(
code
,
width
,
height
);
tMap
[
fit
?
1
:
0
][
code
]
=
texture
;
return
(
texture
==
nullptr
)
?
(
fit
?
tUnknownFit
:
tUnknown
)
:
texture
;
}
if
(
tit
->
second
)
return
tit
->
second
;
else
return
fit
?
tUnknownFit
:
tUnknown
;
}
/** Load managed card picture texture with zoom.
* @return Texture pointer. Should NOT be removed nor dropped. */
irr
::
video
::
ITexture
*
ImageManager
::
GetBigPicture
(
int
code
,
float
zoom
)
{
if
(
code
==
0
)
return
tUnknown
;
...
...
@@ -244,29 +282,15 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
driver
->
removeTexture
(
tBigPicture
);
tBigPicture
=
nullptr
;
}
irr
::
video
::
ITexture
*
texture
;
char
file
[
256
];
mysnprintf
(
file
,
"expansions/pics/%d.jpg"
,
code
);
irr
::
video
::
IImage
*
srcimg
=
driver
->
createImageFromFile
(
file
);
if
(
srcimg
==
nullptr
)
{
mysnprintf
(
file
,
"pics/%d.jpg"
,
code
);
srcimg
=
driver
->
createImageFromFile
(
file
);
}
if
(
srcimg
==
nullptr
)
{
irr
::
video
::
IImage
*
img
=
GetImage
(
code
);
if
(
img
==
nullptr
)
{
return
tUnknown
;
}
if
(
zoom
==
1
)
{
texture
=
driver
->
addTexture
(
file
,
srcimg
);
}
else
{
auto
origsize
=
srcimg
->
getDimension
();
irr
::
video
::
IImage
*
destimg
=
driver
->
createImage
(
srcimg
->
getColorFormat
(),
irr
::
core
::
dimension2d
<
irr
::
u32
>
(
origsize
.
Width
*
zoom
,
origsize
.
Height
*
zoom
));
imageScaleNNAA
(
srcimg
,
destimg
);
texture
=
driver
->
addTexture
(
file
,
destimg
);
destimg
->
drop
();
}
srcimg
->
drop
();
tBigPicture
=
texture
;
return
texture
;
char
name
[
256
];
mysnprintf
(
name
,
"pics/%d/big"
,
code
);
auto
origsize
=
img
->
getDimension
();
tBigPicture
=
addTexture
(
name
,
img
,
origsize
.
Width
*
zoom
,
origsize
.
Height
*
zoom
);
return
tBigPicture
;
}
int
ImageManager
::
LoadThumbThread
()
{
while
(
true
)
{
...
...
@@ -279,13 +303,7 @@ int ImageManager::LoadThumbThread() {
int
code
=
imageManager
.
tThumbLoadingCodes
.
front
();
imageManager
.
tThumbLoadingCodes
.
pop
();
imageManager
.
tThumbLoadingMutex
.
unlock
();
char
file
[
256
];
mysnprintf
(
file
,
"expansions/pics/%d.jpg"
,
code
);
irr
::
video
::
IImage
*
img
=
imageManager
.
driver
->
createImageFromFile
(
file
);
if
(
img
==
nullptr
)
{
mysnprintf
(
file
,
"pics/%d.jpg"
,
code
);
img
=
imageManager
.
driver
->
createImageFromFile
(
file
);
}
irr
::
video
::
IImage
*
img
=
imageManager
.
GetImage
(
code
);
if
(
img
!=
nullptr
)
{
int
width
=
CARD_THUMB_WIDTH
*
mainGame
->
xScale
;
int
height
=
CARD_THUMB_HEIGHT
*
mainGame
->
yScale
;
...
...
@@ -316,6 +334,8 @@ int ImageManager::LoadThumbThread() {
}
return
0
;
}
/** Load managed card thumbnail texture.
* @return Texture pointer. Should NOT be removed nor dropped. */
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureThumb
(
int
code
)
{
if
(
code
==
0
)
return
tUnknownThumb
;
...
...
@@ -323,15 +343,9 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if
(
tit
==
tThumb
.
end
()
&&
!
mainGame
->
gameConf
.
use_image_load_background_thread
)
{
int
width
=
CARD_THUMB_WIDTH
*
mainGame
->
xScale
;
int
height
=
CARD_THUMB_HEIGHT
*
mainGame
->
yScale
;
char
file
[
256
];
mysnprintf
(
file
,
"expansions/pics/%d.jpg"
,
code
);
irr
::
video
::
ITexture
*
img
=
GetTextureFromFile
(
file
,
width
,
height
);
if
(
img
==
NULL
)
{
mysnprintf
(
file
,
"pics/%d.jpg"
,
code
);
img
=
GetTextureFromFile
(
file
,
width
,
height
);
}
tThumb
[
code
]
=
img
;
return
(
img
==
NULL
)
?
tUnknownThumb
:
img
;
irr
::
video
::
ITexture
*
texture
=
GetTexture
(
code
,
width
,
height
);
tThumb
[
code
]
=
texture
;
return
(
texture
==
nullptr
)
?
tUnknownThumb
:
texture
;
}
if
(
tit
==
tThumb
.
end
()
||
tit
->
second
==
tLoading
)
{
imageManager
.
tThumbLoadingMutex
.
lock
();
...
...
@@ -339,7 +353,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if
(
lit
!=
tThumbLoading
.
end
())
{
if
(
lit
->
second
!=
nullptr
)
{
char
textureName
[
256
];
mysnprintf
(
textureName
,
"pics/%d
.jpg_thumbnail"
,
code
);
// not an actual file
mysnprintf
(
textureName
,
"pics/%d
/thumbnail"
,
code
);
irr
::
video
::
ITexture
*
texture
=
driver
->
addTexture
(
textureName
,
lit
->
second
);
// textures must be added in the main thread due to OpenGL
lit
->
second
->
drop
();
tThumb
[
code
]
=
texture
;
...
...
@@ -367,6 +381,8 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
else
return
tUnknownThumb
;
}
/** Load managed duel field texture.
* @return Texture pointer. Should NOT be removed nor dropped. */
irr
::
video
::
ITexture
*
ImageManager
::
GetTextureField
(
int
code
)
{
if
(
code
==
0
)
return
nullptr
;
...
...
gframe/image_manager.h
View file @
afd7fbf4
...
...
@@ -10,12 +10,16 @@
namespace
ygo
{
class
ImageManager
{
private:
irr
::
video
::
ITexture
*
addTexture
(
const
char
*
name
,
irr
::
video
::
IImage
*
srcimg
,
irr
::
s32
width
,
irr
::
s32
height
);
public:
bool
Initial
();
void
SetDevice
(
irr
::
IrrlichtDevice
*
dev
);
void
ClearTexture
();
void
ResizeTexture
();
irr
::
video
::
ITexture
*
GetTextureFromFile
(
const
char
*
file
,
irr
::
s32
width
,
irr
::
s32
height
);
irr
::
video
::
IImage
*
GetImage
(
int
code
);
irr
::
video
::
ITexture
*
GetTexture
(
int
code
,
irr
::
s32
width
,
irr
::
s32
height
);
irr
::
video
::
ITexture
*
GetTexture
(
int
code
,
bool
fit
=
false
);
irr
::
video
::
ITexture
*
GetBigPicture
(
int
code
,
float
zoom
);
irr
::
video
::
ITexture
*
GetTextureThumb
(
int
code
);
...
...
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