1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include "imageviewer.h"
24 #include "image_decoder.h"
26 static const char *decoder_names
[MAX_IMAGE_TYPES
] = {
32 /* check file type by extention */
33 enum image_type
get_image_type(const char *name
)
39 { ".bmp", IMAGE_BMP
},
40 { ".jpg", IMAGE_JPEG
},
41 { ".jpe", IMAGE_JPEG
},
42 { ".jpeg", IMAGE_JPEG
},
43 { ".png", IMAGE_PNG
},
46 const char *ext
= rb
->strrchr(name
, '.');
51 for (i
= 0; i
< (int)ARRAYLEN(ext_list
); i
++)
53 if (!rb
->strcasecmp(ext
, ext_list
[i
].ext
))
54 return ext_list
[i
].type
;
59 static void *decoder_handle
= NULL
;
60 const struct image_decoder
*load_decoder(struct loader_info
*loader_info
)
63 char filename
[MAX_PATH
];
64 struct imgdec_header
*hdr
;
65 struct lc_header
*lc_hdr
;
67 if (loader_info
->type
< 0 || loader_info
->type
>= MAX_IMAGE_TYPES
)
69 rb
->splashf(2*HZ
, "Unknown type: %d", loader_info
->type
);
75 name
= decoder_names
[loader_info
->type
];
76 rb
->snprintf(filename
, MAX_PATH
, VIEWERS_DIR
"/%s.ovl", name
);
78 /* load decoder to the buffer. */
79 decoder_handle
= rb
->lc_open(filename
, loader_info
->buffer
, loader_info
->size
);
82 rb
->splashf(2*HZ
, "Can't open %s", filename
);
86 hdr
= rb
->lc_get_header(decoder_handle
);
89 rb
->splash(2*HZ
, "Can't get header");
92 lc_hdr
= &hdr
->lc_hdr
;
94 if (lc_hdr
->magic
!= PLUGIN_MAGIC
|| lc_hdr
->target_id
!= TARGET_ID
)
96 rb
->splashf(2*HZ
, "%s decoder: Incompatible model.", name
);
100 if (lc_hdr
->api_version
!= IMGDEC_API_VERSION
)
102 rb
->splashf(2*HZ
, "%s decoder: Incompatible version.", name
);
107 *(hdr
->img_api
) = loader_info
->iv
;
109 /* set remaining buffer size to loader_info. decoder will
110 * be loaded to the end of the buffer, so fix size only. */
111 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
112 loader_info
->size
= lc_hdr
->load_addr
- loader_info
->buffer
;
123 void release_decoder(void)
125 if (decoder_handle
!= NULL
)
127 rb
->lc_close(decoder_handle
);
128 decoder_handle
= NULL
;