// decoding functions static int read_adpcm_block_headers(HMMIO rw, adpcm_fmt_t *fmt) { int i; int max = fmt->adpcm.wav.nChannels; if (fmt->bytes_remaining < fmt->adpcm.wav.nBlockAlign) { return 0; } fmt->bytes_remaining -= fmt->adpcm.wav.nBlockAlign; fmt->bytes_processed += fmt->adpcm.wav.nBlockAlign; for (i = 0; i < max; i++) { IF_ERR(!read_ubyte(rw, &fmt->header[i].bPredictor), 0); } for (i = 0; i < max; i++) { IF_ERR(!read_ushort(rw, &fmt->header[i].iDelta), 0); } for (i = 0; i < max; i++) { IF_ERR(!read_short(rw, &fmt->header[i].iSamp1), 0); } for (i = 0; i < max; i++) { IF_ERR(!read_short(rw, &fmt->header[i].iSamp2), 0); } fmt->samples_left_in_block = fmt->adpcm.wSamplesPerBlock; fmt->nibble_state = 0; return 1; }
static int bmpload(t_bmpfile *bmp, unsigned char *oct) { bmp->header.size = read_int(oct + 2); bmp->header.reserved = read_int(oct + 6); bmp->header.offset = read_int(oct + 10); bmp->bmp.size = read_int(oct + 14); bmp->bmp.width = read_int(oct + 18); bmp->bmp.height = read_int(oct + 22); bmp->bmp.plan = read_short(oct + 26); if ((bmp->bmp.deph = read_short(oct + 28)) != 24) return (0); bmp->bmp.comp = read_int(oct + 32); bmp->bmp.img_size = read_int(oct + 36); bmp->bmp.res_hor = read_int(oct + 40); bmp->bmp.res_vert = read_int(oct + 44); bmp->bmp.nb_palette = read_int(oct + 48); bmp->bmp.nb_palette_imp = read_int(oct + 52); bmp->pixels = (int *)malloc(sizeof(int) * bmp->bmp.width * bmp->bmp.height); if (bmp->pixels) { bmpload_pixel(bmp, oct); return (1); } return (0); }
int cgl_read_one_cano(struct cannon *cannon, FILE *fp) { int err; uint8_t buf[CANO_HDR_SIZE]; int16_t buf2[CANO_NUM_SHORTS]; size_t nread; nread = fread(buf, sizeof(uint8_t), CANO_HDR_SIZE, fp); if (nread < CANO_HDR_SIZE) return -EBADCANO; err = read_short((int16_t*)buf2, 1, fp); if (err) return -EBADCANO; cannon->fire_rate = buf2[0]; nread = fread(buf, sizeof(uint8_t), 2, fp); if (nread < 2) return -EBADCANO; cannon->speed_x = (int8_t)buf[0]; cannon->speed_y = (int8_t)buf[1]; err = read_short((int16_t*)buf2, CANO_NUM_SHORTS, fp); if (err) return -EBADCANO; cannon->dir = buf[0] & 0x03; parse_point(buf2 + 0x00, &cannon->beg, &cannon->end); parse_tile_minimal(buf2 + 0x04, cannon->beg_base, 24, 24, 512, 188); parse_tile_simple(buf2 + 0x06, cannon->beg_cano, 16, 16); cannon->beg_cano->collision_test = Bitmap; parse_tile_minimal(buf2 + 0x0a, cannon->end_base, 16, 16, 472, 196); parse_tile_normal(buf2 + 0x0c, cannon->end_catch); cannon->end_catch->collision_test = Bitmap; return 0; }
Slot * Slot_read(char *data, size_t *read){ logmsg(LOG_DEBUG, "Reading slot."); Slot *slot = malloc(sizeof(Slot)); size_t pos = 0; slot->id = read_short(data+pos, &pos); if (slot->id == -1){ slot->count = 0; slot->damage = 0; slot->nbt_len = -1; slot->nbt = NULL; *read = pos; return slot; } slot->count = read_char(data+pos, &pos); slot->damage = read_short(data+pos, &pos); slot->nbt_len = read_short(data+pos, &pos); if (slot->nbt_len == -1){ slot->nbt = NULL; *read = pos; return slot; } slot->nbt = malloc(sizeof(char) * slot->nbt_len); memcpy(slot->nbt, data+pos, slot->nbt_len); *read = pos; return slot; }
javacall_result bt_push_parse_url(const char *url, bt_port_t *port, bt_params_t *params) { int i; if (test_prefix(&url, "btl2cap://")) { port->protocol = BT_L2CAP; } else if (test_prefix(&url, "btspp://")) { port->protocol = BT_SPP; } else if (test_prefix(&url, "btgoep://")) { port->protocol = BT_GOEP; } else { return JAVACALL_FAIL; } if (!test_prefix(&url, "localhost:")) { return JAVACALL_FAIL; } for (i = 0; i < 16; i++) { int hex1, hex2; hex1 = get_hex(*url++); if (hex1 < 0) { return JAVACALL_FAIL; } hex2 = get_hex(*url++); if (hex2 < 0) { return JAVACALL_FAIL; } port->uuid[i] = hex1 << 4 | hex2; } if (params == NULL) { /* params parsing is not needed */ return JAVACALL_OK; } params->authenticate = JAVACALL_FALSE; params->authorize = JAVACALL_FALSE; params->encrypt = JAVACALL_FALSE; params->rmtu = DEFAULT_MTU; params->tmtu = -1; url = strchr(url, ';'); while (url != NULL) { if (test_prefix(&url, ";authenticate=")) { params->authenticate = read_bool(&url); } else if (test_prefix(&url, ";authorize=")) { params->authorize = read_bool(&url); } else if (test_prefix(&url, ";encrypt=")) { params->encrypt = read_bool(&url); } else if (test_prefix(&url, ";master=")) { params->master = read_bool(&url); } else if (test_prefix(&url, ";receiveMTU=")) { params->rmtu = read_short(&url); } else if (test_prefix(&url, ";transmitMTU=")) { params->tmtu = read_short(&url); } url = strchr(url + 1, ';'); } if (params->authorize || params->encrypt) { params->authenticate = JAVACALL_TRUE; } return JAVACALL_OK; }
bool LLImageDimensionsInfo::getImageDimensionsTga() { const S32 TGA_FILE_HEADER_SIZE = 12; mInfile.seek(APR_CUR,TGA_FILE_HEADER_SIZE); mWidth = read_short(); mHeight = read_short(); llinfos << "Tga header reads width: " << mWidth << " and height: " << mHeight << llendl; return true; }
static void read_pols(FILE *f, int nbytes, lwObject *lwo) { int guess_cnt = lwo->face_cnt; while (nbytes > 0) { lwFace *face; int i; /* allocate more memory for polygons if necessary */ if (guess_cnt <= lwo->face_cnt) { guess_cnt += guess_cnt + 4; lwo->face = (lwFace*) g_realloc(lwo->face, sizeof(lwFace)*guess_cnt); } face = lwo->face + lwo->face_cnt++; face->init(); /* number of points in this face */ face->index_cnt = read_short(f); nbytes -= 2; /* allocate space for points */ face->index = (int*) g_malloc0(sizeof(int)*face->index_cnt); /* read points in */ for (i=0; i<face->index_cnt; i++) { face->index[i] = read_short(f); nbytes -= 2; } /* read surface material */ face->material = read_short(f); nbytes -= 2; /* skip over detail polygons */ if (face->material < 0) { printf("face->material=%i ",face->material); int det_cnt; face->material = -face->material; det_cnt = read_short(f); nbytes -= 2; while (det_cnt-- > 0) { int cnt = read_short(f); fseek(f, cnt*2+2, SEEK_CUR); nbytes -= cnt*2+2; } } face->material -= 1; } /* readjust to true size */ lwo->face = (lwFace*) g_realloc(lwo->face, sizeof(lwFace)*lwo->face_cnt); }
int cgl_read_one_dist(struct airgen *airgen, FILE *fp) { int err; uint8_t buf[DIST_HDR_SIZE]; int16_t buf2[DIST_NUM_SHORTS]; size_t nread; nread = fread(buf, sizeof(uint8_t), DIST_HDR_SIZE, fp); if (nread < DIST_HDR_SIZE) return -EBADDIST; err = read_short((int16_t*)buf2, DIST_NUM_SHORTS, fp); if (err) return -EBADDIST; airgen->dir = (buf[0] >> 0) & 0x03; airgen->spin = (buf[0] >> 4) & 0x01; parse_tile_simple(buf2 + 0x00, airgen->base, 40, 40); airgen->tex_x = airgen->base->tex_x; parse_tile_normal(buf2 + 0x04, airgen->pipes); airgen->pipes->collision_test = Bitmap; struct rect r; parse_rect(buf2 + 0x0e, &r); rect_to_tile(&r, airgen->act); set_type(airgen->act, Transparent, RectPoint, AirgenAction, airgen); return 0; }
int cgl_read_one_vent(struct fan *fan, FILE *fp) { int err; uint8_t buf[VENT_HDR_SIZE]; int16_t buf2[VENT_NUM_SHORTS]; size_t nread; nread = fread(buf, sizeof(uint8_t), VENT_HDR_SIZE, fp); if (nread < VENT_HDR_SIZE) return -EBADVENT; err = read_short((int16_t*)buf2, VENT_NUM_SHORTS, fp); if (err) return -EBADVENT; fan->dir = (buf[0] >> 0) & 0x03; fan->power = (buf[0] >> 4) & 0x01; parse_tile_simple(buf2 + 0x00, fan->base, 48, 48); fan->tex_x = fan->base->tex_x; parse_tile_normal(buf2 + 0x04, fan->pipes); fan->pipes->collision_test = Bitmap; struct rect r; parse_rect(buf2 + 0x0e, &r); rect_to_tile(&r, fan->act); set_type(fan->act, Transparent, RectPoint, FanAction, fan); return 0; }
static void read_surf(FILE *f, int nbytes, lwObject *lwo) { int i; char name[LW_MAX_NAME_LEN]; lwMaterial *material = NULL; /* read surface name */ nbytes -= read_string(f,name); /* find material */ for (i=0; i< lwo->material_cnt; i++) { if (strcmp(lwo->material[i].name,name) == 0) { material = &lwo->material[i]; break; } } /* read values */ while (nbytes > 0) { int id = read_long(f); int len = read_short(f); nbytes -= 6 + len + (len%2); switch (id) { case ID_COLR: material->r = read_char(f) / 255.0; material->g = read_char(f) / 255.0; material->b = read_char(f) / 255.0; read_char(f); /* dummy */ break; default: fseek(f, len+(len%2), SEEK_CUR); } } }
static int read_counted_string (unsigned short *countp, char **stringp, FILE *file) { unsigned short len; char *data; if (read_short (&len, file) == 0) return 0; if (len == 0) { data = 0; } else { data = malloc ((unsigned) len); if (!data) return 0; for (;;) { if (fread (data, (int) sizeof (char), (int) len, file) != len) { if (errno == EINTR && ferror (file)) { perror ("Reading from auth file"); clearerr (file); continue; } bzero (data, len); free (data); return 0; } break; } } *stringp = data; *countp = len; return 1; }
img_dmap_t *img_dmap_read(FILE *f) { int count; u_int16_t w, h; char id[5]; img_dmap_t *dmap; short int has_uppers; /* Read the identifier */ read_word((u_int32_t *)id, f); id[4] = 0; if (strcmp(id, "DMAP") != 0) { printf("[img_read_distance_map] Invalid distance map file\n"); return NULL; } /* Read the width and height */ read_short(&w, f); read_short(&h, f); read_short(&has_uppers, f); /* Initialize the map */ dmap = img_dmap_new(w, h); /* Read the distances */ for (count = 0; count < w * h; count++) { read_double(&(dmap->dists[count]), f); } /* Read the nearest neighbors */ for (count = 0; count < w * h; count++) { read_double(&Vx(dmap->nns[count]), f); read_double(&Vy(dmap->nns[count]), f); } if (has_uppers) { dmap->uppers = (iv2_t *) malloc(w * h * sizeof(iv2_t)); /* Read the uppers */ for (count = 0; count < w * h; count++) { read_short(&(Vx(dmap->uppers[count])), f); read_short(&(Vy(dmap->uppers[count])), f); } } return dmap; }
void read_verts(int segnum,CFILE *LoadFile) { int i; // Read short Segments[segnum].verts[MAX_VERTICES_PER_SEGMENT] // cfread( Segments[segnum].verts, sizeof(short), MAX_VERTICES_PER_SEGMENT, LoadFile ); for (i = 0; i < MAX_VERTICES_PER_SEGMENT; i++) Segments[segnum].verts[i] = read_short(LoadFile); }
bool LLImageDimensionsInfo::getImageDimensionsTga() { const S32 TGA_FILE_HEADER_SIZE = 12; // Make sure the file is long enough. if (!checkFileLength(TGA_FILE_HEADER_SIZE + 1 /* width */ + 1 /* height */)) { llwarns << "Premature end of file" << llendl; return false; } mInfile.seek(APR_CUR,TGA_FILE_HEADER_SIZE); mWidth = read_short(); mHeight = read_short(); // KL for testing purposes. llinfos << "Tga header reads width: " << mWidth << " and height: " << mHeight << llendl; return true; }
void init_dict_search() { int fd = open(FILENAME, O_RDONLY); if(fd <= 0) { perror(FILENAME); exit(1); } off_t length = get_file_size(fd); dict_data = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0); close(fd); word_count = read_short(dict_data, 0); index_data = build_index(length); }
void serverlist_frame() { int i; for (i = 0; i < server_count; i++) { msg_t *msg = sock_recv(&serverlist[i].sock); if (msg) { serverlist[i].ping_end = millis(); skip_data(msg, strlen("info\n")); read_server(serverlist + i, read_string(msg)); if (partial_match(filter, serverlist[i].name) || partial_match(filter, serverlist[i].map) || partial_match(filter, serverlist[i].mod) || partial_match(filter, serverlist[i].gametype)) ui_output(output_client, "^5%i ^7(%i) %s %s ^5[^7%s^5] [^7%s:%s^5]\n", i, serverlist[i].ping_end - serverlist[i].ping_start, serverlist[i].players, serverlist[i].name, serverlist[i].map, serverlist[i].mod, serverlist[i].gametype); serverlist[i].received = qtrue; } if (serverlist[i].ping_retries > 0 && !serverlist[i].received && millis() >= serverlist[i].ping_start + PING_TIMEOUT) ping_server(serverlist + i); } master_t *master; for (master = masters; master->address; master++) { msg_t *msg = sock_recv(&master->sock); if (!msg) continue; char address_string[32]; qbyte address[4]; unsigned short port; skip_data(msg, strlen("getserversResponse")); while (msg->readcount + 7 <= msg->cursize) { char prefix = read_char(msg); port = 0; if (prefix == '\\') { read_data(msg, address, 4); port = ShortSwap(read_short(msg)); sprintf(address_string, "%u.%u.%u.%u", address[0], address[1], address[2], address[3]); } if (port != 0) { server_t *server = find_server(address_string, port); if (server != NULL) continue; server = serverlist + server_count++; sock_init(&server->sock); strcpy(server->address, address_string); server->port = port; server->received = qfalse; server->ping_retries = MAX_PING_RETRIES + 1; ping_server(server); } } } }
void i_generate_else() { /* set up a new branch to after the end of the if */ ins_f_byte(F_BRANCH); /* save the old saved value here */ ins_short(read_short(current_forward_branch)); /* update the old branch to point to this point */ upd_short(current_forward_branch, CURRENT_PROGRAM_SIZE - current_forward_branch); /* point current_forward_branch at the new branch we made */ current_forward_branch = CURRENT_PROGRAM_SIZE - 2; }
void i_update_forward_branch_links P2(char, kind, struct parse_node *, link_start){ int i; i = read_short(current_forward_branch); upd_short(current_forward_branch, CURRENT_PROGRAM_SIZE - current_forward_branch); current_forward_branch = i; do { i = link_start->line; upd_byte(i-1, kind); upd_short(i, CURRENT_PROGRAM_SIZE - i); link_start = link_start->l.expr; } while (link_start->kind == NODE_BRANCH_LINK); }
void read_children(int segnum,ubyte bit_mask,CFILE *LoadFile) { int bit; for (bit=0; bit<MAX_SIDES_PER_SEGMENT; bit++) { if (bit_mask & (1 << bit)) { Segments[segnum].children[bit] = read_short(LoadFile); // cfread( &Segments[segnum].children[bit], sizeof(short), 1, LoadFile ); } else Segments[segnum].children[bit] = -1; } }
static void read_field(FILE *f, const save_field_t *field, void *base) { void *p = (byte *)base + field->ofs; int i; switch (field->type) { case F_BYTE: read_data(p, field->size, f); break; case F_SHORT: for (i = 0; i < field->size; i++) { ((short *)p)[i] = read_short(f); } break; case F_INT: for (i = 0; i < field->size; i++) { ((int *)p)[i] = read_int(f); } break; case F_FLOAT: for (i = 0; i < field->size; i++) { ((float *)p)[i] = read_float(f); } break; case F_VECTOR: read_vector(f, (vec_t *)p); break; case F_LSTRING: *(char **)p = read_string(f); break; case F_ZSTRING: read_zstring(f, (char *)p, field->size); break; case F_EDICT: *(edict_t **)p = read_index(f, sizeof(edict_t), g_edicts, game.maxentities - 1); break; case F_CLIENT: *(gclient_t **)p = read_index(f, sizeof(gclient_t), game.clients, game.maxclients - 1); break; case F_ITEM: *(gitem_t **)p = read_index(f, sizeof(gitem_t), itemlist, game.num_items - 1); break; case F_POINTER: *(void **)p = read_pointer(f, field->size); break; default: gi.error("%s: unknown field type", __func__); } }
int read_object_basic(FILE *fp, int *index, object *obj) { int i; char str[10]; /* begin of object data */ read_int(fp, index); /* object # */ read_chars(fp, obj->name, sizeof(obj->name)); read_chars(fp, obj->description, sizeof(obj->description)); for (i = 0; i != 3; i++) read_chars(fp, obj->key[i], sizeof(obj->key[i])); read_chars(fp, obj->use_output, sizeof(obj->use_output)); read_long(fp, &obj->value); read_short(fp, &obj->weight); read_char(fp, &obj->type); read_char(fp, &obj->adjustment); read_short(fp, &obj->shotsmax); read_short(fp, &obj->shotscur); read_short(fp, &obj->ndice); read_short(fp, &obj->sdice); read_short(fp, &obj->pdice); read_char(fp, &obj->armor); read_char(fp, &obj->wearflag); read_char(fp, &obj->magicpower); read_char(fp, &obj->magicrealm); read_short(fp, &obj->special); read_chars(fp, obj->flags, sizeof(obj->flags)); read_char(fp, &obj->questnum); read_char(fp,&obj->strength); read_char(fp,&obj->dexterity); read_char(fp,&obj->constitution); read_char(fp,&obj->intelligence); read_char(fp,&obj->piety); for (i = 0; i != 16; i++) read_short(fp, &obj->sets_flag[i]); read_short(fp,&obj->special1); read_long(fp,&obj->special2); /* end of object data */ return(0); }
int read_integer(int32_t arr[], size_t num, FILE *fp) { /* FIXME: Add big-endian support */ int16_t buf[2]; int err; for (size_t i = 0; i < num; ++i) { err = read_short(buf, 2, fp); if (err) return -EBADINT; arr[i] = buf[0] + buf[1] * 65536; } return 0; }
// TODO elvis static int* build_index(int total_length) { int* index_data = (int*)malloc(sizeof(int) * word_count); int word_index = 0, next_count, index = 2; // ignore first 2 byte, that's word count while(index < total_length) { index_data[word_index++] = index; while(dict_data[index++]); // skip word, word is terminated by \0 next_count = read_short(dict_data, index); if (next_count > 0xe000) { // first bit: is gzipped next_count -= 0xe000; } index += next_count + 2; } return index_data; }
LispRef prevObject(LispRef stream, LispRef eos_error_p, LispRef eos_value) { WITH_DEBUG(fprintf(stderr, "prevObject\n")); short handle1; read_short(handle1); short handle2; read_short(handle2); WITH_DEBUG(fprintf(stderr, " handle: %x %x\n", handle1, handle2)); int handle = handle2; LispRef prev_objects = EUL_OBJECT_STREAM_CACHE(stream); int n = eul_fpi_as_c_int(object_size(prev_objects)); if (handle > n) { LispRef str; eul_allocate_string(str, "bad handle"); eul_serial_error(stream, str, eul_nil); return eul_nil; } LispRef obj = slot_ref(prev_objects, handle); fprintf(stderr, "*** CACHE GET (read) %d FOR ", handle); fprint_ref(stdout, obj); fflush(stdout); fprintf(stderr, "\n"); return obj; }
/* Read a string preceded by a char count. A buffer of the right size is allocated to hold the result. A return value of 1 means success, -1 means the result is undefined (*res is set to NULL), 0 means read or allocation error. */ static int read_allocstring(int fh, char **res, unsigned *len) { uint16_t count; char *buf; unsigned int nread; if(!read_short(fh,&count)) return 0; if(count==(uint16_t)(~0)) {*res=NULL; return -1;} if(!(buf=malloc(count+1))) return 0; nread=0; while(nread<count) { ssize_t m=read(fh,buf+nread,count-nread); if(m<=0) {free(buf); return 0;} nread+=m; } buf[count]=0; *res=buf; if(len) *len=count; return 1; }
static int wf1_read_history (FILE *fp, unsigned pos, DATASET *dset, int i) { char *htxt; unsigned hpos; int len, err = 0; #if EVDEBUG fseek(fp, pos, SEEK_SET); fprintf(stderr, "first short: %d\n", read_short(fp, &err)); #endif fseek(fp, pos + 2, SEEK_SET); len = read_int(fp, &err); if (err) { return 1; } #if EVDEBUG fprintf(stderr, "history length: %d\n", len); fprintf(stderr, "next int: %d\n", read_int(fp, &err)); #endif fseek(fp, pos + 10, SEEK_SET); hpos = read_unsigned(fp, &err); if (err) { return 1; } htxt = calloc(len + 1, 1); if (htxt != NULL) { fseek(fp, hpos, SEEK_SET); if (fread(htxt, 1, len, fp) == len) { series_set_label(dset, i, htxt); } free(htxt); } return 0; }
void dbf_file::read_header() { char c=file_.get(); if (c=='\3' || c=='\131') { skip(3); num_records_=read_int(); assert(num_records_>0); num_fields_=read_short(); assert(num_fields_>0); num_fields_=(num_fields_-33)/32; skip(22); int offset=0; char name[11]; memset(&name,0,11); fields_.reserve(num_fields_); for (int i=0;i<num_fields_;++i) { field_descriptor desc; desc.index_=i; file_.read(name,10); desc.name_=boost::trim_left_copy(std::string(name)); skip(1); desc.type_=file_.get(); skip(4); desc.length_=file_.get(); desc.dec_=file_.get(); skip(14); desc.offset_=offset; offset+=desc.length_; fields_.push_back(desc); } record_length_=offset; if (record_length_>0) { record_=static_cast<char*>(::operator new (sizeof(char)*record_length_)); } } }
Xauth * XauReadAuth (FILE *auth_file) { Xauth local; Xauth *ret; if (read_short (&local.family, auth_file) == 0) return NULL; if (read_counted_string (&local.address_length, &local.address, auth_file) == 0) return NULL; if (read_counted_string (&local.number_length, &local.number, auth_file) == 0) { if (local.address) free (local.address); return NULL; } if (read_counted_string (&local.name_length, &local.name, auth_file) == 0) { if (local.address) free (local.address); if (local.number) free (local.number); return NULL; } if (read_counted_string (&local.data_length, &local.data, auth_file) == 0) { if (local.address) free (local.address); if (local.number) free (local.number); if (local.name) free (local.name); return NULL; } ret = (Xauth *) malloc (sizeof (Xauth)); if (!ret) { if (local.address) free (local.address); if (local.number) free (local.number); if (local.name) free (local.name); if (local.data) { bzero (local.data, local.data_length); free (local.data); } return NULL; } *ret = local; return ret; }
/* Read a string preceded by a char count. Place it in a buffer of size buflen and terminate with a null char. A return value of 1 means success, -1 means not defined, 0 means error (read error, buffer too small). */ static int read_domain(int fh, char *buf, unsigned int buflen) { uint16_t count; unsigned int nread; if(!read_short(fh,&count)) return 0; if(count==(uint16_t)(~0)) return -1; if(count >=buflen) return 0; nread=0; while(nread<count) { ssize_t m=read(fh,buf+nread,count-nread); if(m<=0) return 0; nread+=m; } buf[count]=0; #if 0 if(count==0 || buf[count-1]!='.') { if(count+1>=buflen) return 0; buf[count]='.'; buf[count+1]=0; } #endif return 1; }
static cairo_bool_t do_grayscale(IDWriteFontFace *dwface, unsigned int ppem) { void *tableContext; char *tableData; UINT32 tableSize; BOOL exists; dwface->TryGetFontTable(GASP_TAG, (const void**)&tableData, &tableSize, &tableContext, &exists); if (exists) { if (tableSize < 4) { dwface->ReleaseFontTable(tableContext); return true; } struct gaspRange { unsigned short maxPPEM; // Stored big-endian unsigned short behavior; // Stored big-endian }; unsigned short numRanges = read_short(tableData + 2); if (tableSize < (UINT)4 + numRanges * 4) { dwface->ReleaseFontTable(tableContext); return true; } gaspRange *ranges = (gaspRange *)(tableData + 4); for (int i = 0; i < numRanges; i++) { if (be16_to_cpu(ranges[i].maxPPEM) > ppem) { if (!(be16_to_cpu(ranges[i].behavior) & GASP_DOGRAY)) { dwface->ReleaseFontTable(tableContext); return false; } break; } } dwface->ReleaseFontTable(tableContext); } return true; }