Crossfire Server, Trunk
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
o
p
r
s
t
u
v
w
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
i
j
k
m
n
o
p
r
s
t
u
v
Enumerations
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
Data Fields
All
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Enumerations
Enumerator
Properties
a
b
c
d
e
f
h
i
j
k
l
m
n
p
q
r
s
t
y
Related Functions
:
b
d
o
s
w
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
Variables
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
w
y
z
Typedefs
a
c
d
e
f
i
j
k
l
m
n
o
p
q
s
t
y
Enumerations
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
PngLoader.cpp
Go to the documentation of this file.
1
/*
2
* Crossfire -- cooperative multi-player graphical RPG and adventure game
3
*
4
* Copyright (c) 2020 the Crossfire Development Team
5
*
6
* Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7
* welcome to redistribute it under certain conditions. For details, please
8
* see COPYING and LICENSE.
9
*
10
* The authors can be reached via e-mail at <crossfire@metalforge.org>.
11
*/
12
13
#include "
PngLoader.h
"
14
#include "
Faces.h
"
15
#include "
Facesets.h
"
16
17
#include "string.h"
18
#include "
global.h
"
19
#include "
compat.h
"
20
#include "
image.h
"
21
22
PngLoader::PngLoader
(
Faces
*
faces
,
Facesets
*facesets) : m_faces(
faces
), m_facesets(facesets) {
23
}
24
25
void
PngLoader::load
(
BufferReader
*reader,
const
std::string &filename) {
26
auto
slash = strrchr(filename.c_str(),
'/'
);
27
char
*dup = slash ?
strdup_local
(strrchr(filename.c_str(),
'/'
) + 1) : strdup(filename.c_str());
28
char
*
split
[20];
29
30
size_t
count
=
split_string
(dup,
split
, 20,
'.'
);
31
if
(
count
< 4) {
32
free(dup);
33
return
;
34
}
35
36
char
buf
[500];
37
buf
[0] =
'\0'
;
38
/* char *set = split[count - 3]; */
39
for
(
size_t
p = 0; p <
count
- 1; p++) {
40
if
(p !=
count
- 3) {
41
if
(p > 0) {
42
strcat(
buf
,
"."
);
43
}
44
strcat(
buf
,
split
[p]);
45
}
46
}
47
48
face_sets
*set =
m_facesets
->
get
(
split
[
count
- 3]);
49
50
const
Face
*face =
m_faces
->
get
(
buf
);
51
if
(face->
number
>= set->
allocated
) {
52
set->
faces
=
static_cast<
face_info
*
>
(realloc(set->
faces
, (face->
number
+ 1) *
sizeof
(
face_info
)));
53
for
(
int
i = set->
allocated
; i <= face->number; i++) {
54
set->
faces
[i].
data
= NULL;
55
set->
faces
[i].
datalen
= 0;
56
set->
faces
[i].
checksum
= 0;
57
}
58
set->
allocated
= face->
number
+ 1;
59
}
60
61
if
(set->
faces
[face->
number
].
data
) {
62
LOG
(
llevDebug
,
"replacing facedata %s by %s\n"
, face->
name
, filename.c_str());
63
free(set->
faces
[face->
number
].
data
);
64
}
65
66
set->
faces
[face->
number
].
datalen
=
bufferreader_data_length
(reader);
67
set->
faces
[face->
number
].
data
=
static_cast<
uint8_t *
>
(malloc(set->
faces
[face->
number
].
datalen
));
68
if
(!set->
faces
[face->
number
].
data
) {
69
fatal
(
OUT_OF_MEMORY
);
70
}
71
memcpy(set->
faces
[face->
number
].
data
,
bufferreader_data
(reader), set->
faces
[face->
number
].
datalen
);
72
set->
faces
[face->
number
].
checksum
= 0;
73
for
(
size_t
i = 0; i < set->
faces
[face->
number
].
datalen
; i++) {
74
ROTATE_RIGHT
(set->
faces
[face->
number
].
checksum
);
75
set->
faces
[face->
number
].
checksum
+= set->
faces
[face->
number
].
data
[i];
76
set->
faces
[face->
number
].
checksum
&= 0xffffffff;
77
}
78
79
free(dup);
80
}
Face::name
sstring name
Definition:
face.h:19
PngLoader::m_facesets
Facesets * m_facesets
Definition:
PngLoader.h:33
Face
Definition:
face.h:14
global.h
bufferreader_data
char * bufferreader_data(BufferReader *br)
Definition:
bufferreader.cpp:148
LOG
void LOG(LogLevel logLevel, const char *format,...)
Definition:
logger.cpp:58
strdup_local
#define strdup_local
Definition:
compat.h:29
PngLoader::m_faces
Faces * m_faces
Definition:
PngLoader.h:32
Facesets
Definition:
Facesets.h:23
Facesets.h
bufferreader_data_length
size_t bufferreader_data_length(BufferReader *br)
Definition:
bufferreader.cpp:144
face_sets::allocated
size_t allocated
Definition:
image.h:25
buf
StringBuffer * buf
Definition:
readable.cpp:1565
ROTATE_RIGHT
#define ROTATE_RIGHT(c)
Definition:
global.h:160
Face::number
uint16_t number
Definition:
face.h:15
split_string
size_t split_string(char *str, char *array[], size_t array_size, char sep)
Definition:
utils.cpp:473
compat.h
face_info::data
uint8_t * data
Definition:
image.h:11
face_info
Definition:
image.h:10
disinfect.count
int count
Definition:
disinfect.py:7
AssetsCollection::get
T * get(const Key &name)
Definition:
AssetsCollection.h:89
image.h
fatal
void fatal(enum fatal_error err)
Definition:
utils.cpp:590
Faces
Definition:
Faces.h:19
Faces.h
PngLoader.h
PngLoader::load
virtual void load(BufferReader *reader, const std::string &filename) override
Definition:
PngLoader.cpp:25
face_info::datalen
uint16_t datalen
Definition:
image.h:12
face_info::checksum
uint32_t checksum
Definition:
image.h:13
PngLoader::PngLoader
PngLoader(Faces *faces, Facesets *facesets)
Definition:
PngLoader.cpp:22
dragon_attune.faces
dictionary faces
Definition:
dragon_attune.py:31
split
static std::vector< std::string > split(const std::string &field, const std::string &by)
Definition:
mapper.cpp:2609
face_sets
Definition:
image.h:17
OUT_OF_MEMORY
@ OUT_OF_MEMORY
Definition:
define.h:48
BufferReader
Definition:
bufferreader.cpp:21
face_sets::faces
face_info * faces
Definition:
image.h:26
llevDebug
@ llevDebug
Definition:
logger.h:13
crossfire-crossfire-server
common
assets
PngLoader.cpp
Generated by
1.8.17