Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Album art
Saturday, November 10th, 2007 at 6:59:45pm UTC 

  1. Index: apps/gui/gwps-common.c
  2. ===================================================================
  3. --- apps/gui/gwps-common.c      (révision 15557)
  4. +++ apps/gui/gwps-common.c      (copie de travail)
  5. @@ -48,6 +48,7 @@
  6.  /* Image stuff */
  7.  #include "bmp.h"
  8.  #include "atoi.h"
  9. +#include "albumart.h"
  10.  #endif
  11.  #include "dsp.h"
  12.  #include "action.h"
  13. @@ -929,6 +930,19 @@
  14.          case WPS_TOKEN_METADATA_COMMENT:
  15.              return id3->comment;
  16.  
  17. +#ifdef HAVE_LCD_BITMAP
  18. +        case WPS_TOKEN_ALBUMART_DISPLAY:
  19. +            draw_album_art(gwps, audio_current_aa_hid());
  20. +            return NULL;
  21. +
  22. +        case WPS_TOKEN_ALBUMART_FOUND:
  23. +            if (audio_current_aa_hid() >= 0) {
  24. +                snprintf(buf, buf_size, "C");
  25. +                return buf;
  26. +            }
  27. +            return NULL;
  28. +#endif
  29. +
  30.          case WPS_TOKEN_FILE_BITRATE:
  31.              if(id3->bitrate)
  32.                  snprintf(buf, buf_size, "%d", id3->bitrate);
  33. Index: apps/gui/albumart.c
  34. ===================================================================
  35. --- apps/gui/albumart.c (révision 0)
  36. +++ apps/gui/albumart.c (révision 0)
  37. @@ -0,0 +1,228 @@
  38. +/***************************************************************************
  39. + *             __________               __   ___.
  40. + *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  41. + *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  42. + *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  43. + *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  44. + *                     \/            \/     \/    \/            \/
  45. + * $Id$
  46. + *
  47. + * Copyright (C) 2007 Nicolas Pennequin
  48. + *
  49. + * All files in this archive are subject to the GNU General Public License.
  50. + * See the file COPYING in the source tree root for full license agreement.
  51. + *
  52. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  53. + * KIND, either express or implied.
  54. + *
  55. + ****************************************************************************/
  56. +
  57. +#include <string.h>
  58. +#include "sprintf.h"
  59. +#include "system.h"
  60. +#include "albumart.h"
  61. +#include "id3.h"
  62. +#include "gwps.h"
  63. +#include "buffering.h"
  64. +#include "dircache.h"
  65. +#include "debug.h"
  66. +
  67. +
  68. +/* Strip filename from a full path
  69. + *
  70. + * buf      - buffer to extract directory to.
  71. + * buf_size - size of buffer.
  72. + * fullpath - fullpath to extract from.
  73. + *
  74. + * Split the directory part of the given fullpath and store it in buf
  75. + *   (including last '/').
  76. + * The function return parameter is a pointer to the filename
  77. + *   inside the given fullpath.
  78. + */
  79. +static char* strip_filename(char* buf, int buf_size, const char* fullpath)
  80. +{
  81. +    char* sep;
  82. +    int   len;
  83. +
  84. +    if (!buf || buf_size <= 0 || !fullpath)
  85. +        return NULL;
  86. +
  87. +    /* if 'fullpath' is only a filename return immediately */
  88. +    sep = strrchr(fullpath, '/');
  89. +    if (sep == NULL)
  90. +    {
  91. +        buf[0] = 0;
  92. +        return (char*)fullpath;
  93. +    }
  94. +
  95. +    len = MIN(sep - fullpath + 1, buf_size - 1);
  96. +    strncpy(buf, fullpath, len);
  97. +    buf[len] = 0;
  98. +    return (sep + 1);
  99. +}
  100. +
  101. +static char* strip_extension(char* buf, int buf_size, const char* file)
  102. +{
  103. +    char* sep;
  104. +    int len;
  105. +
  106. +    if (!buf || buf_size <= 0 || !file)
  107. +        return NULL;
  108. +
  109. +    buf[0] = 0;
  110. +
  111. +    sep = strrchr(file,'.');
  112. +    if (sep == NULL)
  113. +        return NULL;
  114. +
  115. +    len = MIN(sep - file, buf_size - 1);
  116. +    strncpy(buf, file, len);
  117. +    buf[len] = 0;
  118. +    return buf;
  119. +}
  120. +
  121. +static bool file_exists(const char *file)
  122. +{
  123. +    int fd;
  124. +
  125. +    if (!file || strlen(file) <= 0)
  126. +        return false;
  127. +
  128. +#ifdef HAVE_DIRCACHE
  129. +    if (dircache_is_enabled())
  130. +        return (dircache_get_entry_ptr(file) != NULL);
  131. +#endif
  132. +
  133. +    fd = open(file, O_RDONLY);
  134. +    if (fd < 0)
  135. +        return false;
  136. +    close(fd);
  137. +    return true;
  138. +}
  139. +
  140. +/* Look for albumart bitmap in the same dir as the track and in its parent dir;
  141. + * stores the found filename in the track->albumart_path.
  142. + * Returns true if a bitmap was found, false otherwise */
  143. +bool find_albumart(const struct mp3entry *id3, char *buf, int buflen)
  144. +{
  145. +    char path[MAX_PATH + 1];
  146. +    char dir[MAX_PATH + 1];
  147. +    bool found = false;
  148. +    const char *trackname;
  149. +
  150. +    if (!id3 || !buf)
  151. +        return false;
  152. +
  153. +    trackname = id3->path;
  154. +    strip_filename(dir, sizeof(dir), trackname);
  155. +
  156. +    DEBUGF("Looking for album art for %s\n", trackname);
  157. +
  158. +    /* the first file we look for is one specific to the track playing */
  159. +    strip_extension(path, sizeof(path) - 4, trackname);
  160. +    strcat(path, ".bmp");
  161. +    found = file_exists(path);
  162. +    if (!found && id3->album && strlen(id3->album) > 0)
  163. +    {   /* if it doesn't exist,
  164. +         * we look for a file specific to the track's album name */
  165. +        snprintf(path, sizeof(path) - 1,
  166. +                 "%s%s.bmp",
  167. +                 (strlen(dir) >= 1) ? dir : "",
  168. +                 id3->album);
  169. +        path[sizeof(path) - 1] = 0;
  170. +        found = file_exists(path);
  171. +    }
  172. +
  173. +    if (!found)
  174. +    {
  175. +        /* if it still doesn't exist, we look for a generic file */
  176. +        snprintf(path, sizeof(path)-1,
  177. +                 "%scover.bmp",
  178. +                 (strlen(dir) >= 1) ? dir : "");
  179. +        path[sizeof(path)-1] = 0;
  180. +        found = file_exists(path);
  181. +    }
  182. +
  183. +    if (!found)
  184. +    {
  185. +        /* if it still doesn't exist,
  186. +         * we continue to search in the parent directory */
  187. +        char temp[MAX_PATH + 1];
  188. +        strncpy(temp, dir, strlen(dir) - 1);
  189. +        temp[strlen(dir) - 1] = 0;
  190. +
  191. +        strip_filename(dir, sizeof(dir), temp);
  192. +    }
  193. +
  194. +    if (!found && id3->album && strlen(id3->album) > 0)
  195. +    {
  196. +        /* we look in the parent directory
  197. +        ** for a file specific to the track's album name */
  198. +        snprintf(path, sizeof(path)-1,
  199. +                 "%s%s.bmp",
  200. +                 (strlen(dir) >= 1) ? dir : "",
  201. +                 id3->album);
  202. +        found = file_exists(path);
  203. +    }
  204. +
  205. +    if (!found)
  206. +    {
  207. +        /* if it still doesn't exist, we look in the parent directory
  208. +         * for a generic file */
  209. +        snprintf(path, sizeof(path)-1,
  210. +                 "%scover.bmp",
  211. +                 (strlen(dir) >= 1) ? dir : "");
  212. +        path[sizeof(path)-1] = 0;
  213. +        found = file_exists(path);
  214. +    }
  215. +
  216. +    if (!found)
  217. +        return false;
  218. +
  219. +    strncpy(buf, path, buflen);
  220. +    DEBUGF("Album art found for %s : %s\n", trackname, path);
  221. +    return true;
  222. +}
  223. +
  224. +void draw_album_art(struct gui_wps *gwps, int handle_id)
  225. +{
  226. +    if(!gwps || !gwps->data || !gwps->display || handle_id < 0)
  227. +        return;
  228. +
  229. +    struct wps_data *data = gwps->data;
  230. +    /* if(data->wps_uses_albumart == WPS_ALBUMART_NONE)
  231. +        return; */
  232. +
  233. +    struct bitmap *bmp;
  234. +    bufgetdata(handle_id, 0, (void *)&bmp);
  235. +
  236. +    short x = data->albumart_x;
  237. +    short y = data->albumart_y;
  238. +    short width = bmp->width;
  239. +    short height = bmp->height;
  240. +
  241. +    if(data->albumart_max_width > 0)
  242. +    {
  243. +        width = MIN(bmp->width, data->albumart_max_width);
  244. +
  245. +        if (data->albumart_xalign & WPS_ALBUMART_ALIGN_RIGHT)
  246. +            x += data->albumart_max_width - width;
  247. +        else if (data->albumart_xalign & WPS_ALBUMART_ALIGN_CENTER)
  248. +            x += (data->albumart_max_width - width) / 2;
  249. +    }
  250. +
  251. +    if(data->albumart_max_height > 0)
  252. +    {
  253. +        height = MIN(bmp->height, data->albumart_max_height);
  254. +
  255. +        if (data->albumart_yalign & WPS_ALBUMART_ALIGN_BOTTOM)
  256. +            y += data->albumart_max_height - height;
  257. +        else if (data->albumart_yalign & WPS_ALBUMART_ALIGN_CENTER)
  258. +            y += (data->albumart_max_height - height) / 2;
  259. +    }
  260. +
  261. +    gwps->display->set_drawmode(DRMODE_FG);
  262. +    gwps->display->bitmap_part((fb_data*)bmp->data, 0, 0, bmp->width,
  263. +                               x, y, width, height);
  264. +    gwps->display->set_drawmode(DRMODE_SOLID);
  265. +}
  266. Index: apps/gui/albumart.h
  267. ===================================================================
  268. --- apps/gui/albumart.h (révision 0)
  269. +++ apps/gui/albumart.h (révision 0)
  270. @@ -0,0 +1,35 @@
  271. +/***************************************************************************
  272. + *             __________               __   ___.
  273. + *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  274. + *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  275. + *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  276. + *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  277. + *                     \/            \/     \/    \/            \/
  278. + * $Id$
  279. + *
  280. + * Copyright (C) 2007 Nicolas Pennequin
  281. + *
  282. + * All files in this archive are subject to the GNU General Public License.
  283. + * See the file COPYING in the source tree root for full license agreement.
  284. + *
  285. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  286. + * KIND, either express or implied.
  287. + *
  288. + ****************************************************************************/
  289. +
  290. +#ifndef _ALBUMART_H_
  291. +#define _ALBUMART_H_
  292. +
  293. +#ifdef HAVE_LCD_BITMAP
  294. +
  295. +#include <stdbool.h>
  296. +#include "id3.h"
  297. +#include "gwps.h"
  298. +
  299. +
  300. +bool find_albumart(const struct mp3entry *id3, char *buf, int buflen);
  301. +void draw_album_art(struct gui_wps *gwps, int handle_id);
  302. +
  303. +#endif /* HAVE_LCD_BITMAP */
  304. +
  305. +#endif /* _ALBUMART_H_ */
  306. Index: apps/gui/gwps.c
  307. ===================================================================
  308. --- apps/gui/gwps.c     (révision 15557)
  309. +++ apps/gui/gwps.c     (copie de travail)
  310. @@ -796,3 +796,18 @@
  311.      unload_remote_wps_backdrop();
  312.  #endif
  313.  }
  314. +
  315. +/*
  316. + * returns true if at least one of the gui_wps screens
  317. + *   has an albumart tag in its wps structure
  318. + */
  319. +bool gui_sync_wps_uses_albumart(void)
  320. +{
  321. +    int  i;
  322. +    FOR_NB_SCREENS(i) {
  323. +        struct gui_wps *gwps = &gui_wps[i];
  324. +        if (gwps->data && (gwps->data->wps_uses_albumart != WPS_ALBUMART_NONE))
  325. +            return true;
  326. +    }
  327. +    return false;
  328. +}
  329. Index: apps/gui/wps_parser.c
  330. ===================================================================
  331. --- apps/gui/wps_parser.c       (révision 15557)
  332. +++ apps/gui/wps_parser.c       (copie de travail)
  333. @@ -124,6 +124,10 @@
  334.          struct wps_token *token, struct wps_data *wps_data);
  335.  static int parse_image_load(const char *wps_bufptr,
  336.          struct wps_token *token, struct wps_data *wps_data);
  337. +static int parse_albumart_load(const char *wps_bufptr,
  338. +        struct wps_token *token, struct wps_data *wps_data);
  339. +static int parse_albumart_conditional(const char *wps_bufptr,
  340. +        struct wps_token *token, struct wps_data *wps_data);
  341.  #endif /*HAVE_LCD_BITMAP */
  342.  
  343.  #ifdef CONFIG_RTC
  344. @@ -283,6 +287,8 @@
  345.  
  346.      { WPS_TOKEN_IMAGE_DISPLAY,            "x",   0,       parse_image_load },
  347.      { WPS_TOKEN_IMAGE_PROGRESS_BAR,       "P",   0,    parse_image_special },
  348. +    { WPS_NO_TOKEN,                       "Cl",  0,    parse_albumart_load },
  349. +    { WPS_TOKEN_ALBUMART_DISPLAY,         "C",   WPS_REFRESH_DYNAMIC, parse_albumart_conditional },
  350.  #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
  351.      { WPS_TOKEN_IMAGE_BACKDROP,           "X",   0,    parse_image_special },
  352.  #endif
  353. @@ -606,6 +612,217 @@
  354.  #endif
  355.  }
  356.  
  357. +#ifdef HAVE_LCD_BITMAP
  358. +static int parse_albumart_load(const char *wps_bufptr,
  359. +                          struct wps_token *token,
  360. +                          struct wps_data *wps_data)
  361. +{
  362. +    const char* _pos;
  363. +    bool parsing;
  364. +    const short xalign_mask = WPS_ALBUMART_ALIGN_LEFT |
  365. +                              WPS_ALBUMART_ALIGN_CENTER |
  366. +                              WPS_ALBUMART_ALIGN_RIGHT;
  367. +    const short yalign_mask = WPS_ALBUMART_ALIGN_TOP |
  368. +                              WPS_ALBUMART_ALIGN_CENTER |
  369. +                              WPS_ALBUMART_ALIGN_BOTTOM;
  370. +
  371. +    (void)(token); /* silence warning */
  372. +
  373. +    /* reset albumart info in wps */
  374. +    wps_data->wps_uses_albumart = WPS_ALBUMART_NONE;
  375. +    wps_data->albumart_max_width = -1;
  376. +    wps_data->albumart_max_height = -1;
  377. +    wps_data->albumart_xalign = WPS_ALBUMART_ALIGN_CENTER; /* default */
  378. +    wps_data->albumart_yalign = WPS_ALBUMART_ALIGN_CENTER; /* default */
  379. +
  380. +    /* format: %Cl|x|y|[[l|c|r][d|i|s]mwidth]|[[t|c|b][d|i|s]mheight]| */
  381. +    /* initial validation and parsing of x and y components */
  382. +    if (*wps_bufptr != '|')
  383. +        return 0; /* malformed token: e.g. %Cl7  */
  384. +
  385. +    _pos = wps_bufptr+1;
  386. +    if (!isdigit(*_pos))
  387. +        return 0; /* malformed token: e.g. %Cl|@  */
  388. +    wps_data->albumart_x = atoi(_pos);
  389. +
  390. +    _pos = strchr(_pos, '|');
  391. +    if (!_pos || !isdigit(*(++_pos)))
  392. +        return 0; /* malformed token: e.g. %Cl|7\n or %Cl|7|@ */
  393. +
  394. +    wps_data->albumart_y = atoi(_pos);
  395. +
  396. +    _pos = strchr(_pos, '|');
  397. +    if (!_pos)
  398. +        return 0; /* malformed token: no | after y coordinate
  399. +                     e.g. %Cl|7|59\n */
  400. +
  401. +    /* parsing width field */
  402. +    parsing = true;
  403. +    while (parsing)
  404. +    {
  405. +        /* apply each modifier in turn */
  406. +        ++_pos;
  407. +        switch (*_pos)
  408. +        {
  409. +            case 'l':
  410. +            case 'L':
  411. +            case '+':
  412. +                wps_data->albumart_xalign =
  413. +                    (wps_data->albumart_xalign & xalign_mask) |
  414. +                    WPS_ALBUMART_ALIGN_LEFT;
  415. +                break;
  416. +            case 'c':
  417. +            case 'C':
  418. +                wps_data->albumart_xalign =
  419. +                    (wps_data->albumart_xalign & xalign_mask) |
  420. +                    WPS_ALBUMART_ALIGN_CENTER;
  421. +                break;
  422. +            case 'r':
  423. +            case 'R':
  424. +            case '-':
  425. +                wps_data->albumart_xalign =
  426. +                    (wps_data->albumart_xalign & xalign_mask) |
  427. +                    WPS_ALBUMART_ALIGN_RIGHT;
  428. +                break;
  429. +            case 'd':
  430. +            case 'D':
  431. +                wps_data->albumart_xalign |= WPS_ALBUMART_DECREASE;
  432. +                break;
  433. +            case 'i':
  434. +            case 'I':
  435. +                wps_data->albumart_xalign |= WPS_ALBUMART_INCREASE;
  436. +                break;
  437. +            case 's':
  438. +            case 'S':
  439. +                wps_data->albumart_xalign |=
  440. +                    (WPS_ALBUMART_DECREASE | WPS_ALBUMART_INCREASE);
  441. +                break;
  442. +            default:
  443. +                parsing = false;
  444. +                break;
  445. +        }
  446. +    }
  447. +    /* extract max width data */
  448. +    if (*_pos != '|')
  449. +    {
  450. +        if (!isdigit(*_pos))
  451. +            return 0; /* malformed token:  e.g. %Cl|7|59|# */
  452. +        wps_data->albumart_max_width = atoi(_pos);
  453. +        _pos = strchr(_pos, '|');
  454. +        if (!_pos)
  455. +            return 0; /* malformed token: no | after width field
  456. +                         e.g. %Cl|7|59|200\n */
  457. +    }
  458. +
  459. +    /* parsing height field */
  460. +    parsing = true;
  461. +    while (parsing)
  462. +    {
  463. +        /* apply each modifier in turn */
  464. +        ++_pos;
  465. +        switch (*_pos)
  466. +        {
  467. +            case 't':
  468. +            case 'T':
  469. +            case 'r': /* yuck */
  470. +            case 'R':
  471. +            case '-':
  472. +                wps_data->albumart_yalign =
  473. +                    (wps_data->albumart_yalign & yalign_mask) |
  474. +                    WPS_ALBUMART_ALIGN_TOP;
  475. +                break;
  476. +            case 'c':
  477. +            case 'C':
  478. +                wps_data->albumart_yalign =
  479. +                    (wps_data->albumart_yalign & yalign_mask) |
  480. +                    WPS_ALBUMART_ALIGN_CENTER;
  481. +                break;
  482. +            case 'b':
  483. +            case 'B':
  484. +            case 'l': /* yuck */
  485. +            case 'L':
  486. +            case '+':
  487. +                wps_data->albumart_yalign =
  488. +                    (wps_data->albumart_yalign & yalign_mask) |
  489. +                    WPS_ALBUMART_ALIGN_BOTTOM;
  490. +                break;
  491. +            case 'd':
  492. +            case 'D':
  493. +                wps_data->albumart_yalign |= WPS_ALBUMART_DECREASE;
  494. +                break;
  495. +            case 'i':
  496. +            case 'I':
  497. +                wps_data->albumart_yalign |= WPS_ALBUMART_INCREASE;
  498. +                break;
  499. +            case 's':
  500. +            case 'S':
  501. +                wps_data->albumart_yalign |=
  502. +                    (WPS_ALBUMART_DECREASE | WPS_ALBUMART_INCREASE);
  503. +                break;
  504. +            default:
  505. +                parsing = false;
  506. +                break;
  507. +        }
  508. +    }
  509. +    /* extract max height data */
  510. +    if (*_pos != '|')
  511. +    {
  512. +        if (!isdigit(*_pos))
  513. +            return 0; /* malformed token  e.g. %Cl|7|59|200|@  */
  514. +        wps_data->albumart_max_height = atoi(_pos);
  515. +        _pos = strchr(_pos, '|');
  516. +        if (!_pos)
  517. +            return 0; /* malformed token: no closing |
  518. +                         e.g. %Cl|7|59|200|200\n */
  519. +    }
  520. +
  521. +    /* if we got here, we parsed everything ok .. ! */
  522. +    if (wps_data->albumart_max_width < 0)
  523. +        wps_data->albumart_max_width = 0;
  524. +    else if (wps_data->albumart_max_width > LCD_WIDTH)
  525. +        wps_data->albumart_max_width = LCD_WIDTH;
  526. +
  527. +    if (wps_data->albumart_max_height < 0)
  528. +        wps_data->albumart_max_height = 0;
  529. +    else if (wps_data->albumart_max_height > LCD_HEIGHT)
  530. +        wps_data->albumart_max_height = LCD_HEIGHT;
  531. +
  532. +    wps_data->wps_uses_albumart = WPS_ALBUMART_LOAD;
  533. +
  534. +    /* Skip the rest of the line */
  535. +    return skip_end_of_line(wps_bufptr);
  536. +}
  537. +
  538. +static int parse_albumart_conditional(const char *wps_bufptr,
  539. +                                      struct wps_token *token,
  540. +                                      struct wps_data *wps_data)
  541. +{
  542. +    struct wps_token *prevtoken = token;
  543. +    --prevtoken;
  544. +    if (wps_data->num_tokens >= 1 && prevtoken->type == WPS_TOKEN_CONDITIONAL)
  545. +    {
  546. +        /* This %C is part of a %?C construct.
  547. +           It's either %?C<blah> or %?Cn<blah> */
  548. +        token->type = WPS_TOKEN_ALBUMART_FOUND;
  549. +        if (*wps_bufptr == 'n' && *(wps_bufptr+1) == '<')
  550. +        {
  551. +            token->next = true;
  552. +            return 1;
  553. +        }
  554. +        else if (*wps_bufptr == '<')
  555. +        {
  556. +            return 0;
  557. +        }
  558. +        else
  559. +        {
  560. +            token->type = WPS_NO_TOKEN;
  561. +            return 0;
  562. +        }
  563. +    }
  564. +    else return 0;
  565. +};
  566. +#endif /* HAVE_LCD_BITMAP */
  567. +
  568.  /* Parse a generic token from the given string. Return the length read */
  569.  static int parse_token(const char *wps_bufptr, struct wps_data *wps_data)
  570.  {
  571. @@ -915,6 +1132,9 @@
  572.      bool rwps = data->remote_wps; /* remember whether the data is for a RWPS */
  573.  #endif
  574.      memset(data, 0, sizeof(*data));
  575. +#ifdef HAVE_LCD_BITMAP
  576. +    data->wps_uses_albumart = WPS_ALBUMART_NONE;
  577. +#endif
  578.      wps_data_init(data);
  579.  #ifdef HAVE_REMOTE_LCD
  580.      data->remote_wps = rwps;
  581. Index: apps/gui/gwps.h
  582. ===================================================================
  583. --- apps/gui/gwps.h     (révision 15557)
  584. +++ apps/gui/gwps.h     (copie de travail)
  585. @@ -39,6 +39,19 @@
  586.  #define WPS_ALIGN_CENTER 64
  587.  #define WPS_ALIGN_LEFT 128
  588.  
  589. +/* albumart definitions */
  590. +#define WPS_ALBUMART_NONE           0      /* WPS does not contain AA tag */
  591. +#define WPS_ALBUMART_CHECK          1      /* WPS contains AA conditional tag */
  592. +#define WPS_ALBUMART_LOAD           2      /* WPS contains AA tag */
  593. +
  594. +#define WPS_ALBUMART_ALIGN_RIGHT    WPS_ALIGN_RIGHT    /* x align:   right */
  595. +#define WPS_ALBUMART_ALIGN_CENTER   WPS_ALIGN_CENTER   /* x/y align: center */
  596. +#define WPS_ALBUMART_ALIGN_LEFT     WPS_ALIGN_LEFT     /* x align:   left */
  597. +#define WPS_ALBUMART_ALIGN_TOP      WPS_ALIGN_RIGHT    /* y align:   top */
  598. +#define WPS_ALBUMART_ALIGN_BOTTOM   WPS_ALIGN_LEFT     /* y align:   bottom */
  599. +#define WPS_ALBUMART_INCREASE       8                  /* increase if smaller */
  600. +#define WPS_ALBUMART_DECREASE       16                 /* decrease if larger */
  601. +
  602.  /* wps_data*/
  603.  
  604.  #ifdef HAVE_LCD_BITMAP
  605. @@ -185,6 +198,10 @@
  606.      WPS_TOKEN_IMAGE_PRELOAD,
  607.      WPS_TOKEN_IMAGE_PRELOAD_DISPLAY,
  608.      WPS_TOKEN_IMAGE_DISPLAY,
  609. +
  610. +    /* Albumart */
  611. +    WPS_TOKEN_ALBUMART_DISPLAY,
  612. +    WPS_TOKEN_ALBUMART_FOUND,
  613.  #endif
  614.  
  615.      /* Metadata */
  616. @@ -309,6 +326,18 @@
  617.      short progress_start;
  618.      short progress_end;
  619.      bool peak_meter_enabled;
  620. +
  621. +    /* Album art additions */
  622. +    unsigned char wps_uses_albumart; /* WPS_ALBUMART_NONE, _CHECK, _LOAD */
  623. +    short albumart_x;
  624. +    short albumart_y;
  625. +    unsigned short albumart_xalign; /* WPS_ALBUMART_ALIGN_LEFT, _CENTER, _RIGHT,
  626. +                                       + .._INCREASE,  + .._DECREASE */
  627. +    unsigned short albumart_yalign; /* WPS_ALBUMART_ALIGN_TOP, _CENTER, _BOTTOM,
  628. +                                       + .._INCREASE,  + .._DECREASE */
  629. +    short albumart_max_width;
  630. +    short albumart_max_height;
  631. +
  632.  #else /*HAVE_LCD_CHARCELLS */
  633.      unsigned short wps_progress_pat[8];
  634.      bool full_line_progressbar;
  635. @@ -417,4 +446,7 @@
  636.  void gui_sync_wps_init(void);
  637.  void gui_sync_wps_screen_init(void);
  638.  
  639. +/* gives back if WPS contains an albumart tag */
  640. +bool gui_sync_wps_uses_albumart(void);
  641. +
  642.  #endif
  643. Index: apps/playback.c
  644. ===================================================================
  645. --- apps/playback.c     (révision 15557)
  646. +++ apps/playback.c     (copie de travail)
  647. @@ -66,6 +66,7 @@
  648.  #include "icons.h"
  649.  #include "peakmeter.h"
  650.  #include "action.h"
  651. +#include "albumart.h"
  652.  #endif
  653.  #include "lang.h"
  654.  #include "bookmark.h"
  655. @@ -217,6 +218,9 @@
  656.      int audio_hid;             /* The ID for the track's buffer handle */
  657.      int id3_hid;               /* The ID for the track's metadata handle */
  658.      int codec_hid;             /* The ID for the track's codec handle */
  659. +#ifdef HAVE_LCD_BITMAP
  660. +    int aa_hid;                /* The ID for the track's album art handle */
  661. +#endif
  662.  
  663.      size_t filesize;           /* File total length */
  664.  
  665. @@ -391,6 +395,15 @@
  666.              return false;
  667.      }
  668.  
  669. +#ifdef HAVE_LCD_BITMAP
  670. +    if (track->aa_hid >= 0) {
  671. +        if (bufclose(track->aa_hid))
  672. +            track->aa_hid = -1;
  673. +        else
  674. +            return false;
  675. +#endif
  676. +    }
  677. +
  678.      track->filesize = 0;
  679.      track->taginfo_ready = false;
  680.      track->event_sent = false;
  681. @@ -635,6 +648,13 @@
  682.  
  683.  #endif /* HAVE_RECORDING */
  684.  
  685. +#ifdef HAVE_LCD_BITMAP
  686. +int audio_current_aa_hid(void)
  687. +{
  688. +    return CUR_TI->aa_hid;
  689. +}
  690. +#endif
  691. +
  692.  struct mp3entry* audio_current_track(void)
  693.  {
  694.      const char *filename;
  695. @@ -2381,6 +2401,16 @@
  696.      else
  697.          track_id3 = bufgetid3(tracks[track_widx].id3_hid);
  698.  
  699. +
  700. +#ifdef HAVE_LCD_BITMAP
  701. +    if (gui_sync_wps_uses_albumart())
  702. +    {
  703. +        char aa_path[MAX_PATH];
  704. +        if (find_albumart(track_id3, aa_path, sizeof(aa_path)))
  705. +            tracks[track_widx].aa_hid = bufopen(aa_path, 0, TYPE_BITMAP);
  706. +    }
  707. +#endif
  708. +
  709.      track_id3->elapsed = 0;
  710.  
  711.      enum data_type type = TYPE_PACKET_AUDIO;
  712. @@ -3286,6 +3316,9 @@
  713.          tracks[i].audio_hid = -1;
  714.          tracks[i].id3_hid = -1;
  715.          tracks[i].codec_hid = -1;
  716. +#ifdef HAVE_LCD_BITMAP
  717. +        tracks[i].aa_hid = -1;
  718. +#endif
  719.      }
  720.  
  721.      /* Probably safe to say */
  722. Index: apps/SOURCES
  723. ===================================================================
  724. --- apps/SOURCES        (révision 15557)
  725. +++ apps/SOURCES        (copie de travail)
  726. @@ -50,6 +50,7 @@
  727.  gui/gwps-common.c
  728.  #ifdef HAVE_LCD_BITMAP
  729.  gui/icon.c
  730. +gui/albumart.c
  731.  #endif
  732.  gui/list.c
  733.  gui/option_select.c
  734. Index: apps/buffering.c
  735. ===================================================================
  736. --- apps/buffering.c    (révision 15557)
  737. +++ apps/buffering.c    (copie de travail)
  738. @@ -48,6 +48,7 @@
  739.  #include "playback.h"
  740.  #include "pcmbuf.h"
  741.  #include "buffer.h"
  742. +#include "bmp.h"
  743.  
  744.  #ifdef SIMULATOR
  745.  #define ata_disk_is_active() 1
  746. @@ -745,7 +746,7 @@
  747.  
  748.      if (h->next && h->filerem == 0 &&
  749.              (h->type == TYPE_ID3 || h->type == TYPE_CUESHEET ||
  750. -             h->type == TYPE_IMAGE || h->type == TYPE_CODEC ||
  751. +             h->type == TYPE_BITMAP || h->type == TYPE_CODEC ||
  752.               h->type == TYPE_ATOMIC_AUDIO))
  753.      {
  754.          /* metadata handle: we can move all of it */
  755. @@ -767,6 +768,10 @@
  756.              adjust_mp3entry((struct mp3entry *)&buffer[h->data],
  757.                              (void *)&buffer[h->data],
  758.                              (void *)&buffer[olddata]);
  759. +        } else if (h->type == TYPE_BITMAP) {
  760. +            logf("move bitmap handle");
  761. +            struct bitmap *bmp = (struct bitmap *)&buffer[h->data];
  762. +            bmp->data = &buffer[h->data + sizeof(struct bitmap)];
  763.          }
  764.      }
  765.      else
  766. @@ -814,7 +819,20 @@
  767.      }
  768.  }
  769.  
  770. +#ifdef HAVE_LCD_BITMAP
  771. +static int load_bitmap(const int fd)
  772. +{
  773. +    int rc;
  774. +    struct bitmap *bmp = (struct bitmap *)&buffer[buf_widx];
  775. +    bmp->data = &buffer[buf_widx + sizeof(struct bitmap)];
  776. +    bmp->maskdata = NULL;
  777. +    int free = (int)MIN(buffer_len - BUF_USED, buffer_len - buf_widx);
  778. +    rc = read_bmp_fd(fd, bmp, free, FORMAT_ANY|FORMAT_TRANSPARENT);
  779. +    return rc + (rc > 0 ? sizeof(struct bitmap) : 0);
  780. +}
  781. +#endif
  782.  
  783. +
  784.  /*
  785.  MAIN BUFFERING API CALLS
  786.  ========================
  787. @@ -858,7 +876,6 @@
  788.      }
  789.  
  790.      strncpy(h->path, file, MAX_PATH);
  791. -    h->filesize = size;
  792.      h->filerem = size - offset;
  793.      h->offset = offset;
  794.      h->ridx = buf_widx;
  795. @@ -867,7 +884,23 @@
  796.      h->available = 0;
  797.      h->type = type;
  798.  
  799. -    if (type == TYPE_CUESHEET || type == TYPE_IMAGE) {
  800. +#ifdef HAVE_LCD_BITMAP
  801. +    if (type == TYPE_BITMAP) {
  802. +        mutex_lock(&llist_mutex);
  803. +        size = load_bitmap(fd);
  804. +        if (size <= 0)
  805. +            return ERR_FILE_ERROR;
  806. +        h->filerem = 0;
  807. +        h->available = size;
  808. +        h->widx = buf_widx + size; /* safe because the data doesn't wrap */
  809. +        buf_widx += size;  /* safe too */
  810. +        mutex_unlock(&llist_mutex);
  811. +    }
  812. +#endif
  813. +
  814. +    h->filesize = size;
  815. +
  816. +    if (type == TYPE_CUESHEET) {
  817.          h->fd = fd;
  818.          /* Immediately start buffering those */
  819.          LOGFQUEUE("buffering >| Q_BUFFER_HANDLE");
  820. Index: apps/buffering.h
  821. ===================================================================
  822. --- apps/buffering.h    (révision 15557)
  823. +++ apps/buffering.h    (copie de travail)
  824. @@ -30,7 +30,7 @@
  825.      TYPE_ATOMIC_AUDIO,
  826.      TYPE_ID3,
  827.      TYPE_CUESHEET,
  828. -    TYPE_IMAGE,
  829. +    TYPE_BITMAP,
  830.      TYPE_BUFFER,
  831.      TYPE_UNKNOWN,
  832.  };
  833. Index: firmware/export/audio.h
  834. ===================================================================
  835. --- firmware/export/audio.h     (révision 15557)
  836. +++ firmware/export/audio.h     (copie de travail)
  837. @@ -91,6 +91,9 @@
  838.  #endif /* CONFIG_CODEC == SWCODEC */
  839.  void audio_ff_rewind(long newtime);
  840.  void audio_flush_and_reload_tracks(void);
  841. +#ifdef HAVE_LCD_BITMAP
  842. +int audio_current_aa_hid(void);
  843. +#endif
  844.  struct mp3entry* audio_current_track(void);
  845.  struct mp3entry* audio_next_track(void);
  846.  bool audio_has_changed_track(void);

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right