media/libpng/arm/linux.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libpng/arm/linux.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,159 @@
     1.4 +/* contrib/arm-neon/linux.c
     1.5 + *
     1.6 + * Copyright (c) 2014 Glenn Randers-Pehrson
     1.7 + * Written by John Bowler, 2014.
     1.8 + * Last changed in libpng 1.6.10 [March 6, 2014]
     1.9 + *
    1.10 + * This code is released under the libpng license.
    1.11 + * For conditions of distribution and use, see the disclaimer
    1.12 + * and license in png.h
    1.13 + *
    1.14 + * SEE contrib/arm-neon/README before reporting bugs
    1.15 + *
    1.16 + * STATUS: SUPPORTED
    1.17 + * BUG REPORTS: png-mng-implement@sourceforge.net
    1.18 + *
    1.19 + * png_have_neon implemented for Linux by reading the widely available
    1.20 + * pseudo-file /proc/cpuinfo.
    1.21 + *
    1.22 + * This code is strict ANSI-C and is probably moderately portable, it does
    1.23 + * however use <stdio.h> and assumes that /proc/cpuinfo is never localized.
    1.24 + */
    1.25 +#include <stdio.h>
    1.26 +
    1.27 +static int
    1.28 +png_have_neon(png_structp png_ptr)
    1.29 +{
    1.30 +   FILE *f = fopen("/proc/cpuinfo", "rb");
    1.31 +
    1.32 +   if (f != NULL)
    1.33 +   {
    1.34 +      /* This is a simple state machine which reads the input byte-by-byte until
    1.35 +       * it gets a match on the 'neon' feature or reaches the end of the stream.
    1.36 +       */
    1.37 +      static const char ch_feature[] = { 70, 69, 65, 84, 85, 82, 69, 83 };
    1.38 +      static const char ch_neon[] = { 78, 69, 79, 78 };
    1.39 +
    1.40 +      enum
    1.41 +      {
    1.42 +         StartLine, Feature, Colon, StartTag, Neon, HaveNeon, SkipTag, SkipLine
    1.43 +      }  state;
    1.44 +      int counter;
    1.45 +
    1.46 +      for (state=StartLine, counter=0;;)
    1.47 +      {
    1.48 +         int ch = fgetc(f);
    1.49 +
    1.50 +         if (ch == EOF)
    1.51 +         {
    1.52 +            /* EOF means error or end-of-file, return false; neon at EOF is
    1.53 +             * assumed to be a mistake.
    1.54 +             */
    1.55 +            fclose(f);
    1.56 +            return 0;
    1.57 +         }
    1.58 +
    1.59 +         switch (state)
    1.60 +         {
    1.61 +            case StartLine:
    1.62 +               /* Match spaces at the start of line */
    1.63 +               if (ch <= 32) /* skip control characters and space */
    1.64 +                  break;
    1.65 +
    1.66 +               counter=0;
    1.67 +               state = Feature;
    1.68 +               /* FALL THROUGH */
    1.69 +
    1.70 +            case Feature:
    1.71 +               /* Match 'FEATURE', ASCII case insensitive. */
    1.72 +               if ((ch & ~0x20) == ch_feature[counter])
    1.73 +               {
    1.74 +                  if (++counter == (sizeof ch_feature))
    1.75 +                     state = Colon;
    1.76 +                  break;
    1.77 +               }
    1.78 +               
    1.79 +               /* did not match 'feature' */
    1.80 +               state = SkipLine;
    1.81 +               /* FALL THROUGH */
    1.82 +
    1.83 +            case SkipLine:
    1.84 +            skipLine:
    1.85 +               /* Skip everything until we see linefeed or carriage return */
    1.86 +               if (ch != 10 && ch != 13)
    1.87 +                  break;
    1.88 +
    1.89 +               state = StartLine;
    1.90 +               break;
    1.91 +
    1.92 +            case Colon:
    1.93 +               /* Match any number of space or tab followed by ':' */
    1.94 +               if (ch == 32 || ch == 9)
    1.95 +                  break;
    1.96 +
    1.97 +               if (ch == 58) /* i.e. ':' */
    1.98 +               {
    1.99 +                  state = StartTag;
   1.100 +                  break;
   1.101 +               }
   1.102 +
   1.103 +               /* Either a bad line format or a 'feature' prefix followed by
   1.104 +                * other characters.
   1.105 +                */
   1.106 +               state = SkipLine;
   1.107 +               goto skipLine;
   1.108 +
   1.109 +            case StartTag:
   1.110 +               /* Skip space characters before a tag */
   1.111 +               if (ch == 32 || ch == 9)
   1.112 +                  break;
   1.113 +
   1.114 +               state = Neon;
   1.115 +               counter = 0;
   1.116 +               /* FALL THROUGH */
   1.117 +
   1.118 +            case Neon:
   1.119 +               /* Look for 'neon' tag */
   1.120 +               if ((ch & ~0x20) == ch_neon[counter])
   1.121 +               {
   1.122 +                  if (++counter == (sizeof ch_neon))
   1.123 +                     state = HaveNeon;
   1.124 +                  break;
   1.125 +               }
   1.126 +
   1.127 +               state = SkipTag;
   1.128 +               /* FALL THROUGH */
   1.129 +
   1.130 +            case SkipTag:
   1.131 +               /* Skip non-space characters */
   1.132 +               if (ch == 10 || ch == 13)
   1.133 +                  state = StartLine;
   1.134 +
   1.135 +               else if (ch == 32 || ch == 9)
   1.136 +                  state = StartTag;
   1.137 +               break;
   1.138 +
   1.139 +            case HaveNeon:
   1.140 +               /* Have seen a 'neon' prefix, but there must be a space or new
   1.141 +                * line character to terminate it.
   1.142 +                */
   1.143 +               if (ch == 10 || ch == 13 || ch == 32 || ch == 9)
   1.144 +               {
   1.145 +                  fclose(f);
   1.146 +                  return 1;
   1.147 +               }
   1.148 +
   1.149 +               state = SkipTag;
   1.150 +               break;
   1.151 +
   1.152 +            default:
   1.153 +               png_error(png_ptr, "png_have_neon: internal error (bug)");
   1.154 +         }
   1.155 +      }
   1.156 +   }
   1.157 +
   1.158 +   else
   1.159 +      png_warning(png_ptr, "/proc/cpuinfo open failed");
   1.160 +
   1.161 +   return 0;
   1.162 +}

mercurial