aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Portable/pmp_ipod/iPodArtworkDB.h
blob: 8e74e3e09a57520b2d03d0fdae6469be217b1c79 (plain) (blame)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
 *
 *
 * Copyright (c) 2007 Will Fisher (will.fisher@gmail.com)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *
 *
 */

#ifndef __IPODARTDB_H__
#define __IPODARTDB_H__

#pragma once

//#include <stdio.h>
#include <windows.h>
#include <vector>
#include <map>
#include <bfc/platform/types.h>

class ArtDB;
class ArtDataSet;
class ArtImageList;
class ArtImage;
class ArtImageName;
class ArtDataObject;
class ArtAlbumList;
class ArtFileList;
class ArtFile;
class ArtFileImage;

// this contains our whole art database
class ArtDB { //mhfd
public:
	int headerlen; //0x84
	int totallen;
	int unk1;
	int unk2; // must be 2
	// numchildren // should be 3
	int unk3;
	uint32_t nextid; // for ArtImage ids, starts at 0x40
	__int64 unk5;
	__int64 unk6;
	int unk7; // 2
	int unk8; // 0
	int unk9; // 0
	int unk10;
	int unk11;
	ArtDataSet * imageListDS;
	ArtDataSet * albumListDS;
	ArtDataSet * fileListDS;

	ArtDB();
	~ArtDB();
	int parse(BYTE * data, int len, wchar_t drive);
	int write(BYTE * data, int len);
	
	void makeEmptyDB(wchar_t drive);
};

class ArtDataSet { //mhsd
public:
	int headerlen; //0x60
	int totallen;
	int index; // 1=image list, 2=album list, 3=file list
	ArtImageList * imageList;
	ArtAlbumList * albumList;
	ArtFileList * fileList;

	ArtDataSet();
	ArtDataSet(int idx);
	~ArtDataSet();
	int parse(BYTE *data, int len);
	int write(BYTE *data, int len);
};

// contains a list of images
class ArtImageList { //mhli
public:
	typedef std::map<uint64_t ,ArtImage*> ArtImageMap;
	typedef ArtImageMap::iterator ArtImageMapIterator;
	typedef ArtImageMap::value_type ArtImageMapPair;

	int headerlen; //0x5c
	//int numchildren;
	ArtImageMap images;
	
	ArtImageList();
	~ArtImageList();
	int parse(BYTE *data, int len);
	int write(BYTE *data, int len);
};

// contains a reference to an image within an .ithmb file
class ArtImage { //mhii
public:
	int headerlen; //0x98
	int totallen;
	//int numchildren;
	uint32_t id;
	uint64_t songid;
	int32_t unk4;
	int32_t rating;
	int32_t unk6;
	uint32_t originalDate; //0
	uint32_t digitizedDate; //0
	uint32_t srcImageSize; // in bytes
	std::vector<ArtDataObject*> dataobjs;

	ArtImage();
	~ArtImage();
	int parse(BYTE *data, int len);
	int write(BYTE *data, int len);
};

class ArtDataObject { //mhod
public:
	int headerlen; //0x18
	// total length
	short type;
	unsigned char unk1;
	// unsigned char padding; // must pad to a multiple of 4 bytes! this is usually 2, but can be 0,1,2 or 3
	BYTE * data;
	int datalen;
	ArtImageName * image;

	ArtDataObject();
	~ArtDataObject();
	int parse(BYTE *data, int len);
	int write(BYTE *data, int len);

	void GetString(wchar_t * str, int len);
	void SetString(wchar_t * str);
};

class ArtImageName { //mhni
public:
	int headerlen; //0x4c
	int totallen;
	//num children = 1
	unsigned int corrid;
	unsigned int ithmboffset;
	unsigned int imagesize; // in bytes
	short vpad;
	short hpad;
	unsigned short imgh;
	unsigned short imgw;
	ArtDataObject* filename;

	ArtImageName();
	~ArtImageName();
	int parse(BYTE *data, int len);
	int write(BYTE *data, int len);
};

// this is only used in photo databases (which we don't care about) so it's only a stub
class ArtAlbumList { //mhla
public:
	int headerlen; //0x5c
	//num children, should be 0 for artwork db
	ArtAlbumList();
	~ArtAlbumList();
	int parse(BYTE *data, int len);
	int write(BYTE *data, int len);
};

// this contains the list of .ithmb files
class ArtFileList { //mhlf
public:
	int headerlen; //0x5c
	// num children
	std::vector<ArtFile*> files;
	
	ArtFileList();
	~ArtFileList();
	int parse(BYTE *data, int len);
	int write(BYTE *data, int len);
	ArtFile * getFile(int corrid);
};

// this talks about a .ithmb file
class ArtFile { //mhif
public:
	int headerlen; //0x7c
	unsigned int corrid;
	unsigned int imagesize; // bytes
	
	ArtFile();
	~ArtFile();
	int parse(BYTE *data, int len);
	int write(BYTE *data, int len);

	std::vector<ArtFileImage*> images;
	wchar_t * file;
	void sortImages();
	size_t getNextHole(size_t size);
};

class ArtFileImage {
public:
	size_t start;
	size_t len;
	int refcount;
	ArtFileImage(size_t start, size_t len, int refcount) : start(start), len(len), refcount(refcount) {}
};

bool writeDataToThumb(wchar_t *file, unsigned short * data, int len);

#endif //__IPODARTDB_H__