double getFrameSharpnessValue(unsigned char *data, int len) { int Gpos = 0; char c; unsigned short int cnt; int i; int cnt2 = 0; unsigned char uc; assert(sizeof(cnt) == 2); assert(sizeof(int) == 4); unsigned char *buffer; double sumAC[64]; double sumSqrAC[64]; int width = -1; int height = -1; int huffman_DCY = -1; int huffman_ACY = -1; int quant_Y = -1; int scaleH_Y = 0; int scaleV_Y = 0; unsigned char dht_lookup_bitlen[4][162]; unsigned int dht_lookup_bits[4][162]; unsigned int dht_lookup_mask[4][162]; unsigned char dht_lookup_code[4][162]; unsigned char dht_lookup_size[4]; float *QT[4] = { NULL, NULL, NULL, NULL }; unsigned int mask[17] = { 0x00000000, 0x00000001, 0x00000003, 0x00000007, 0x0000000f, 0x0000001f, 0x0000003f, 0x0000007f, 0x000000ff, 0x000001ff, 0x000003ff, 0x000007ff, 0x00000fff, 0x00001fff, 0x00003fff, 0x00007fff, 0x0000ffff }; char fgetc_(void) { return data[Gpos++]; } while(!(Gpos >= len)) { c = fgetc_(); while(c != '\xff') { c = fgetc_(); } c = fgetc_(); if(c == '\xd8' || c == '\xe0' || c == '\x00') { continue; } else if(c == '\xdb') { // read in quantization table c = fgetc_(); cnt = (unsigned char)(c) * 256; c = fgetc_(); cnt += (unsigned char)(c); assert(cnt == 67); uc = fgetc_(); if((uc >> 4) != 0) { fprintf(stderr, "16bit quantization table not supported\n"); exit(-1); } int tab = uc & 0x0f; QT[tab] = (float *)malloc(64 * sizeof(float)); unsigned char hc = 0; int j; for(j = 0; j < 64; j++) { uc = fgetc_(); QT[tab][j] = (float)uc; hc ^= uc; } } else if(c == '\xc4') { // read in huffmann table
/* return next token from input */ int get_next_token(FILE* in) { char current; /* current character */ int i, lexlen = 0; /* length of lexeme */ while (isspace(current = fgetc_(in)))/* skip whitespace */ if (current == '\n') { ++lineno; charno = 1; } while (current == '#') { /* skip comments */ while ((current = fgetc_(in)) != '\n'); ++lineno; charno = 1; while (isspace(current = fgetc_(in))) if (current == '\n') { ++lineno; charno = 1; } } if (isalpha(current)) { /* tokenize names */ do { if (lexlen < 65) /* lexeme holds first 64 chars */ buffer[lexlen++] = current; /* construct lexeme */ } while (isalnum(current = fgetc_(in))); ungetc_(current, in); /* ungetc_ current */ buffer[lexlen] = '\0'; /* terminate string */ for (i=0; i<num_rids; i++) { /* check for reserved names */ if (!strcmp(buffer, rids[i].name)) return rids[i].type; } return T_ID; } switch (current) { /* tokenize smbolic operators */ case ':': /* ambiguous symbols */ if ((current = fgetc_(in)) == '=') return T_ASSIGN; ungetc_(current, in); return T_COLON; case '=': if ((current = fgetc_(in)) == '>') return T_IMPL; ungetc_(current, in); return T_EQ; case '|': if ((current = fgetc_(in)) == '|') return T_CONCUR; ungetc_(current, in); return T_OR; case ';': /* unique symbols */ return T_SEMI; case '!': return T_NOT; case '&': return T_AND; case '(': return T_L_PAREN; case ')': return T_R_PAREN; case '{': return T_L_BRACE; case '}': return T_R_BRACE; case '[': return T_L_BRACK; case ']': return T_R_BRACK; case EOF: return T_EOF; default: /* unrecognized symbol */ fprintf(stderr, "Scan error on line %i:%i invalid character '%c'\n", lineno, charno, current); exit(1); } }
c = fgetc_(); cnt += (unsigned char)(c); assert(cnt == 67); uc = fgetc_(); if((uc >> 4) != 0) { fprintf(stderr, "16bit quantization table not supported\n"); exit(-1); } int tab = uc & 0x0f; QT[tab] = (float *)malloc(64 * sizeof(float)); unsigned char hc = 0; int j; for(j = 0; j < 64; j++) { uc = fgetc_(); QT[tab][j] = (float)uc; hc ^= uc; } } else if(c == '\xc4') { // read in huffmann table // 0 and 2 are DC tables (0-15), 1 and 3 are AC tables (0-255) c = fgetc_(); cnt = (unsigned char)(c) * 256; c = fgetc_(); cnt += (unsigned char)(c); buffer = data + Gpos; Gpos += cnt - 2; // parse huffman table... int pos = 0; unsigned short int tab = 0; do { uc = buffer[pos]; pos++; tab = (uc >> 4) + (uc & 0x0f) * 2; tab = (uc & 0x0f) * 2 + (uc >> 4); int pos2 = pos + 16; unsigned char DhtCodesLen[16]; int i_len; int table_ind = 0; int code_val = 0; int ind_code; for(i_len = 1; i_len <= 16; i_len++) { DhtCodesLen[i_len-1] = (unsigned char)(buffer[pos+i_len-1]);