MCPcopy Create free account
hub / github.com/ddnet/ddnet / ExtractMapImages

Function ExtractMapImages

src/tools/map_extract.cpp:29–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29static void ExtractMapImages(CDataFileReader &Reader, const char *pPathSave)
30{
31 int Start, Num;
32 Reader.GetType(MAPITEMTYPE_IMAGE, &Start, &Num);
33 for(int i = 0; i < Num; i++)
34 {
35 const CMapItemImage_v2 *pItem = static_cast<CMapItemImage_v2 *>(Reader.GetItem(Start + i));
36 if(pItem->m_External)
37 continue;
38
39 const char *pName = Reader.GetDataString(pItem->m_ImageName);
40 if(pName == nullptr || pName[0] == '\0')
41 {
42 log_error("map_extract", "failed to load name of image %d", i);
43 continue;
44 }
45
46 char aBuf[IO_MAX_PATH_LENGTH];
47 str_format(aBuf, sizeof(aBuf), "%s/%s.png", pPathSave, pName);
48 Reader.UnloadData(pItem->m_ImageName);
49
50 if(pItem->m_Version >= 2 && pItem->m_MustBe1 != 1)
51 {
52 log_error("map_extract", "ignoring image '%s' with unknown format %d", aBuf, pItem->m_MustBe1);
53 continue;
54 }
55
56 CImageInfo Image;
57 Image.m_Width = pItem->m_Width;
58 Image.m_Height = pItem->m_Height;
59 Image.m_Format = CImageInfo::FORMAT_RGBA;
60 Image.m_pData = static_cast<uint8_t *>(Reader.GetData(pItem->m_ImageData));
61
62 log_info("map_extract", "writing image: %s (%dx%d)", aBuf, pItem->m_Width, pItem->m_Height);
63 if(!CImageLoader::SavePng(io_open(aBuf, IOFLAG_WRITE), aBuf, Image))
64 {
65 log_error("map_extract", "failed to write image file. filename='%s'", aBuf);
66 }
67 Reader.UnloadData(pItem->m_ImageData);
68 }
69}
70
71static void ExtractMapSounds(CDataFileReader &Reader, const char *pPathSave)
72{

Callers 1

ExtractMapFunction · 0.85

Calls 7

str_formatFunction · 0.85
io_openFunction · 0.85
GetTypeMethod · 0.45
GetItemMethod · 0.45
GetDataStringMethod · 0.45
UnloadDataMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected