File: identify.c

package info (click to toggle)
allegro5 2%3A5.2.6.0-3%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 24,212 kB
  • sloc: ansic: 125,319; cpp: 15,781; objc: 4,579; python: 2,802; java: 2,254; javascript: 1,204; sh: 1,002; makefile: 51; perl: 37; xml: 25; pascal: 24
file content (39 lines) | stat: -rw-r--r-- 817 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "allegro5/allegro.h"
#include "allegro5/allegro_image.h"
#include "allegro5/internal/aintern_image.h"

bool _al_identify_png(ALLEGRO_FILE *f)
{
   uint8_t x[8];
   al_fread(f, x, 8);
   if (memcmp(x, "\x89PNG\r\n\x1a\n", 8) != 0)
      return false;
   return true;
}

bool _al_identify_jpg(ALLEGRO_FILE *f)
{
   uint8_t x[4];
   uint16_t y;
   y = al_fread16be(f);
   if (y != 0xffd8)
      return false;
   al_fseek(f, 6 - 2, ALLEGRO_SEEK_CUR);
   al_fread(f, x, 4);
   if (memcmp(x, "JFIF", 4) != 0)
      return false;
   return true;
}

bool _al_identify_webp(ALLEGRO_FILE *f)
{
   uint8_t x[4];
   al_fread(f, x, 4);
   if (memcmp(x, "RIFF", 4) != 0)
      return false;
   al_fseek(f, 4, ALLEGRO_SEEK_CUR);
   al_fread(f, x, 4);
   if (memcmp(x, "WEBP", 4) != 0)
      return false;
   return true;
}