change project url to github.
[platform/upstream/lightmediascanner.git] / src / plugins / png / png.c
index aab0379..d02d55e 100644 (file)
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#define _XOPEN_SOURCE 600
 #include <lightmediascanner_plugin.h>
 #include <lightmediascanner_utils.h>
 #include <lightmediascanner_db.h>
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
 #include <strings.h>
 
+static const struct lms_string_size dlna_mime =
+    LMS_STATIC_STRING_SIZE("image/png");
+static const struct lms_string_size dlna_sm_ico =
+    LMS_STATIC_STRING_SIZE("PNG_SM_ICO");
+static const struct lms_string_size dlna_lrg_ico =
+    LMS_STATIC_STRING_SIZE("PNG_LRG_ICO");
+static const struct lms_string_size dlna_tn =
+    LMS_STATIC_STRING_SIZE("PNG_TN");
+static const struct lms_string_size dlna_lrg =
+    LMS_STATIC_STRING_SIZE("PNG_LRG");
+
+static void
+_fill_dlna_profile(struct lms_image_info *info)
+{
+    const unsigned short w = info->width;
+    const unsigned short h = info->height;
+
+    info->dlna_mime = dlna_mime;
+
+    if (w == 0 || h == 0)
+        return;
+
+    if (w == 48 && h == 48)
+        info->dlna_profile = dlna_sm_ico;
+    else if (w == 120 && h == 120)
+        info->dlna_profile = dlna_lrg_ico;
+    else if (w <= 160 && h <= 160)
+        info->dlna_profile = dlna_tn;
+    else if (w <= 4096 && h <= 4096)
+        info->dlna_profile = dlna_lrg;
+}
+
 static inline unsigned int
 _chunk_to_uint(unsigned char *buf)
 {
@@ -126,7 +154,7 @@ _match(struct plugin *p, const char *path, int len, int base)
 static int
 _parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_info *finfo, void *match)
 {
-    struct lms_image_info info = {0};
+    struct lms_image_info info = { };
     int fd, r;
 
     fd = open(finfo->path, O_RDONLY);
@@ -143,21 +171,17 @@ _parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_in
     if (info.date == 0)
         info.date = finfo->mtime;
 
-    if (!info.title.str) {
-      long ext_idx;
-
-      ext_idx = ((long)match) - 1;
-      info.title.len = finfo->path_len - finfo->base - _exts[ext_idx].len;
-      info.title.str = malloc((info.title.len + 1) * sizeof(char));
-      memcpy(info.title.str, finfo->path + finfo->base, info.title.len);
-      info.title.str[info.title.len] = '\0';
-    }
-
+    if (!info.title.str)
+        lms_name_from_path(&info.title, finfo->path, finfo->path_len,
+                           finfo->base, _exts[((long) match) - 1].len,
+                           NULL);
     if (info.title.str)
-      lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
+        lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
     if (info.artist.str)
       lms_charset_conv(ctxt->cs_conv, &info.artist.str, &info.artist.len);
 
+    _fill_dlna_profile(&info);
+
     info.id = finfo->id;
     r = lms_db_image_add(plugin->img_db, &info);
 
@@ -217,6 +241,7 @@ lms_plugin_open(void)
     plugin->plugin.setup = (lms_plugin_setup_fn_t)_setup;
     plugin->plugin.start = (lms_plugin_start_fn_t)_start;
     plugin->plugin.finish = (lms_plugin_finish_fn_t)_finish;
+    plugin->plugin.order = 0;
 
     return (struct lms_plugin *)plugin;
 }
@@ -230,7 +255,7 @@ lms_plugin_info(void)
         "PNG images",
         PACKAGE_VERSION,
         _authors,
-        "http://lms.garage.maemo.org"
+        "http://github.com/profusion/lightmediascanner"
     };
 
     return &info;