+_get_orientation_app0(char *app0_head, size_t remain_length)
+{
+ unsigned int length = 0;
+ unsigned int w = 0, h = 0;
+ unsigned int format = 0;
+ unsigned int data_size = 0;
+ char *p;
+
+ /* p is appn's start pointer excluding app0 marker */
+ p = app0_head + 2;
+
+
+ length = ((*p << 8) + *(p + 1));
+
+ /* JFIF segment format */
+ if (!memcmp(p + 2, JfifHeader, sizeof (JfifHeader)))
+ {
+ format = 3;
+ w = *(p + 14);
+ h = *(p + 15);
+ }
+ else if (!memcmp(p + 2, JfxxHeader, sizeof (JfxxHeader)))
+ {
+ if (*(p + 7) == 0x11)
+ format = 1;
+ else
+ format = 3;
+ w = *(p + 8);
+ h = *(p + 9);
+ }
+
+ data_size = format * w * h;
+ p += length + data_size;
+
+ if (!memcmp(p, App1, sizeof (App1)))
+ return _get_orientation_app1(p, remain_length - (2 + length + data_size));
+ else
+ return 0;
+}
+
+static int
+_get_orientation_app1(char *app1_head, size_t remain_length)