iPodArtworkDB.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. *
  3. *
  4. * Copyright (c) 2007 Will Fisher ([email protected])
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. The name of the author may not be used to endorse or promote products
  16. * derived from this software without specific prior permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  19. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  20. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. *
  30. *
  31. */
  32. #ifndef __IPODARTDB_H__
  33. #define __IPODARTDB_H__
  34. #pragma once
  35. //#include <stdio.h>
  36. #include <windows.h>
  37. #include <vector>
  38. #include <map>
  39. #include <bfc/platform/types.h>
  40. class ArtDB;
  41. class ArtDataSet;
  42. class ArtImageList;
  43. class ArtImage;
  44. class ArtImageName;
  45. class ArtDataObject;
  46. class ArtAlbumList;
  47. class ArtFileList;
  48. class ArtFile;
  49. class ArtFileImage;
  50. // this contains our whole art database
  51. class ArtDB { //mhfd
  52. public:
  53. int headerlen; //0x84
  54. int totallen;
  55. int unk1;
  56. int unk2; // must be 2
  57. // numchildren // should be 3
  58. int unk3;
  59. uint32_t nextid; // for ArtImage ids, starts at 0x40
  60. __int64 unk5;
  61. __int64 unk6;
  62. int unk7; // 2
  63. int unk8; // 0
  64. int unk9; // 0
  65. int unk10;
  66. int unk11;
  67. ArtDataSet * imageListDS;
  68. ArtDataSet * albumListDS;
  69. ArtDataSet * fileListDS;
  70. ArtDB();
  71. ~ArtDB();
  72. int parse(BYTE * data, int len, wchar_t drive);
  73. int write(BYTE * data, int len);
  74. void makeEmptyDB(wchar_t drive);
  75. };
  76. class ArtDataSet { //mhsd
  77. public:
  78. int headerlen; //0x60
  79. int totallen;
  80. int index; // 1=image list, 2=album list, 3=file list
  81. ArtImageList * imageList;
  82. ArtAlbumList * albumList;
  83. ArtFileList * fileList;
  84. ArtDataSet();
  85. ArtDataSet(int idx);
  86. ~ArtDataSet();
  87. int parse(BYTE *data, int len);
  88. int write(BYTE *data, int len);
  89. };
  90. // contains a list of images
  91. class ArtImageList { //mhli
  92. public:
  93. typedef std::map<uint64_t ,ArtImage*> ArtImageMap;
  94. typedef ArtImageMap::iterator ArtImageMapIterator;
  95. typedef ArtImageMap::value_type ArtImageMapPair;
  96. int headerlen; //0x5c
  97. //int numchildren;
  98. ArtImageMap images;
  99. ArtImageList();
  100. ~ArtImageList();
  101. int parse(BYTE *data, int len);
  102. int write(BYTE *data, int len);
  103. };
  104. // contains a reference to an image within an .ithmb file
  105. class ArtImage { //mhii
  106. public:
  107. int headerlen; //0x98
  108. int totallen;
  109. //int numchildren;
  110. uint32_t id;
  111. uint64_t songid;
  112. int32_t unk4;
  113. int32_t rating;
  114. int32_t unk6;
  115. uint32_t originalDate; //0
  116. uint32_t digitizedDate; //0
  117. uint32_t srcImageSize; // in bytes
  118. std::vector<ArtDataObject*> dataobjs;
  119. ArtImage();
  120. ~ArtImage();
  121. int parse(BYTE *data, int len);
  122. int write(BYTE *data, int len);
  123. };
  124. class ArtDataObject { //mhod
  125. public:
  126. int headerlen; //0x18
  127. // total length
  128. short type;
  129. unsigned char unk1;
  130. // unsigned char padding; // must pad to a multiple of 4 bytes! this is usually 2, but can be 0,1,2 or 3
  131. BYTE * data;
  132. int datalen;
  133. ArtImageName * image;
  134. ArtDataObject();
  135. ~ArtDataObject();
  136. int parse(BYTE *data, int len);
  137. int write(BYTE *data, int len);
  138. void GetString(wchar_t * str, int len);
  139. void SetString(wchar_t * str);
  140. };
  141. class ArtImageName { //mhni
  142. public:
  143. int headerlen; //0x4c
  144. int totallen;
  145. //num children = 1
  146. unsigned int corrid;
  147. unsigned int ithmboffset;
  148. unsigned int imagesize; // in bytes
  149. short vpad;
  150. short hpad;
  151. unsigned short imgh;
  152. unsigned short imgw;
  153. ArtDataObject* filename;
  154. ArtImageName();
  155. ~ArtImageName();
  156. int parse(BYTE *data, int len);
  157. int write(BYTE *data, int len);
  158. };
  159. // this is only used in photo databases (which we don't care about) so it's only a stub
  160. class ArtAlbumList { //mhla
  161. public:
  162. int headerlen; //0x5c
  163. //num children, should be 0 for artwork db
  164. ArtAlbumList();
  165. ~ArtAlbumList();
  166. int parse(BYTE *data, int len);
  167. int write(BYTE *data, int len);
  168. };
  169. // this contains the list of .ithmb files
  170. class ArtFileList { //mhlf
  171. public:
  172. int headerlen; //0x5c
  173. // num children
  174. std::vector<ArtFile*> files;
  175. ArtFileList();
  176. ~ArtFileList();
  177. int parse(BYTE *data, int len);
  178. int write(BYTE *data, int len);
  179. ArtFile * getFile(int corrid);
  180. };
  181. // this talks about a .ithmb file
  182. class ArtFile { //mhif
  183. public:
  184. int headerlen; //0x7c
  185. unsigned int corrid;
  186. unsigned int imagesize; // bytes
  187. ArtFile();
  188. ~ArtFile();
  189. int parse(BYTE *data, int len);
  190. int write(BYTE *data, int len);
  191. std::vector<ArtFileImage*> images;
  192. wchar_t * file;
  193. void sortImages();
  194. size_t getNextHole(size_t size);
  195. };
  196. class ArtFileImage {
  197. public:
  198. size_t start;
  199. size_t len;
  200. int refcount;
  201. ArtFileImage(size_t start, size_t len, int refcount) : start(start), len(len), refcount(refcount) {}
  202. };
  203. bool writeDataToThumb(wchar_t *file, unsigned short * data, int len);
  204. #endif //__IPODARTDB_H__