void pullPaletteData(ALLEGRO_FILE *file, unsigned char *red, unsigned char *grn, unsigned char *blu, int num) { al_fseek(file,0x0004, ALLEGRO_SEEK_SET); int counter = 0; for (int i = 0; i < num * 4 * 3; i++) { switch (counter) { case 0: red[i/3] = (unsigned char)al_fgetc(file); break; case 1: grn[i/3] = (unsigned char)al_fgetc(file); break; case 2: blu[i/3] = (unsigned char)al_fgetc(file); break; } counter++; if (counter == 3) { counter = 0; } } }
/* read_palette: * Loads the color palette for 1,4,8 bit formats. * OS/2 bitmaps take 3 bytes per color. * Windows bitmaps take 4 bytes per color. */ static void read_palette(int ncolors, PalEntry *pal, ALLEGRO_FILE *f, int win_flag) { int i; for (i = 0; i < ncolors; i++) { pal[i].b = al_fgetc(f); pal[i].g = al_fgetc(f); pal[i].r = al_fgetc(f); if (win_flag) { al_fgetc(f); } } }
Cursor::Cursor( Palette* ColourPalette ) { ALLEGRO_FILE* f = al_fopen( "data/TACDATA/MOUSE.DAT", "rb" ); while( images.size() < al_fsize( f ) / 576 ) { ALLEGRO_BITMAP* b = al_create_bitmap( 24, 24 ); ALLEGRO_LOCKED_REGION* r = al_lock_bitmap( b, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, 0 ); for( int y = 0; y < 24; y++ ) { for( int x = 0; x < 24; x++ ) { int palidx = al_fgetc( f ); Colour* rowptr = (Colour*)(&((char*)r->data)[ (y * r->pitch) + (x * 4) ]); Colour* palcol = ColourPalette->GetColour( palidx ); rowptr->a = palcol->a; rowptr->r = palcol->r; rowptr->g = palcol->g; rowptr->b = palcol->b; } } al_unlock_bitmap( b ); images.push_back( b ); } CurrentType = CursorType::Normal; cursorx = 0; cursory = 0; }
/* vector object IO */ T3F_VECTOR_OBJECT * t3f_load_vector_object_f(ALLEGRO_FILE * fp) { T3F_VECTOR_OBJECT * vp = NULL; T3F_VECTOR_SEGMENT segment; int r, g, b, a; char header[16] = {0}; int i; int segments = 0; if(al_fread(fp, header, 16) != 16) { return NULL; } if(stricmp(header, "T3FV")) { return NULL; } vp = t3f_create_vector_object(); if(!vp) { return NULL; } segments = al_fread32le(fp); for(i = 0; i < segments; i++) { segment.point[0].x = t3f_fread_float(fp); segment.point[0].y = t3f_fread_float(fp); segment.point[0].z = t3f_fread_float(fp); segment.point[1].x = t3f_fread_float(fp); segment.point[1].y = t3f_fread_float(fp); segment.point[1].z = t3f_fread_float(fp); r = al_fgetc(fp); g = al_fgetc(fp); b = al_fgetc(fp); a = al_fgetc(fp); segment.color = al_map_rgba(r, g, b, a); segment.thickness = t3f_fread_float(fp); if(!t3f_add_vector_segment(vp, segment.point[0].x, segment.point[0].y, segment.point[0].z, segment.point[1].x, segment.point[1].y, segment.point[1].z, segment.color, segment.thickness)) { return NULL; } } return vp; }
bool validateTplFile(ALLEGRO_FILE *file) { for (int i = 0; i < 4; i++) { unsigned char bit = al_fgetc(file); if ((i == 0 && bit != 0x54) || (i == 1 && bit != 0x50) || (i == 2 && bit != 0x4C)) { return false; } } return true; }
static bool curl_file_fseek(ALLEGRO_FILE *f, int64_t offset, int whence) { if (whence != ALLEGRO_SEEK_CUR || offset < 0) { /* Not implemented. */ al_set_errno(ENOSYS); return false; } while (offset > 0) { if (al_fgetc(f) == EOF) break; offset--; } return offset == 0; }
/* vector font IO */ T3F_VECTOR_FONT * t3f_load_vector_font_f(ALLEGRO_FILE * fp) { T3F_VECTOR_FONT * vfp = NULL; T3F_VECTOR_OBJECT * vp; float w; float max_y = 0.0; char header[16] = {0}; int i, j; if(al_fread(fp, header, 16) != 16) { return NULL; } if(stricmp(header, "T3FVF")) { return NULL; } vfp = t3f_create_vector_font(); if(!vfp) { return NULL; } for(i = 0; i < T3F_VECTOR_FONT_MAX_CHARACTERS; i++) { if(al_fgetc(fp)) { vp = t3f_load_vector_object_f(fp); w = t3f_fread_float(fp); t3f_add_vector_character(vfp, i, vp, w); for(j = 0; j < vp->segments; j++) { if(vp->segment[j]->point[0].y > max_y) { max_y = vp->segment[j]->point[0].y; } if(vp->segment[j]->point[1].y > max_y) { max_y = vp->segment[j]->point[1].y; } } } } vfp->height = max_y; return vfp; }
bool File::readAll( std::string& buff ) { buff = ""; if(eof() || !isOpen()) { return false; } int c = 0; while((c = al_fgetc(m_file)) != EOF) { if(c > 13 || c == '\n') buff += (char)c; } return true; }
// Method to Initialize Level void level1() { Pacman.image = al_load_bitmap("Pacman_Sprite_Sheet.PNG"); // Loading pacman sprite sheet Pacman.X = SCREEN_W / 2; // Starting x-coordinate of pacman on the screen Pacman.Y = SCREEN_H / 2; // Starting y-coordinate of pacman on the screen Pacman.S = 2.0; // Movement S of pacman Pacman.NumbOfFrames = 2; // Total number of pacman animation frames in the sprite sheet Pacman.frameDelay = 7; // S of pacman animation Pacman.InitObject(); // Initialize pacman gameObject = new GameObject[(SCREEN_W / TILE_SIZE) * (SCREEN_H / TILE_SIZE)]; gameObjectCount = 0; Food = al_load_bitmap("food.png"); Block = al_load_bitmap("block.png"); Level = al_fopen("level_1.data", "r"); // Loading and initializing Level & Game Objects for (int R = 0; R < SCREEN_H / TILE_SIZE; R++) { for (int C = 0; C < SCREEN_W / TILE_SIZE; C++) { levelGrid[R][C] = al_fgetc(Level); switch (levelGrid[R][C]) { case 10: C--; break; case 49: gameObject[gameObjectCount].InitObject(Block, C * TILE_SIZE, R * TILE_SIZE, BLOCK); gameObjectCount++; break; case 48: gameObject[gameObjectCount].InitObject(Food, C * TILE_SIZE, R * TILE_SIZE, FOOD); gameObjectCount++; break; } } } }
static int dfs_getc(void *f) { return al_fgetc(f); }
ALLEGRO_SAMPLE *_al_load_voc_f(ALLEGRO_FILE *file) { AL_VOC_DATA *vocdata; ALLEGRO_SAMPLE *sample = NULL; size_t pos = 0; /* where to write in the buffer */ size_t read = 0; /*bytes read during last operation */ char* buffer; size_t bytestoread = 0; bool endofvoc = false; vocdata = al_malloc(sizeof(AL_VOC_DATA)); memset(vocdata, 0, sizeof(*vocdata)); /* * Open file and populate VOC DATA, then create a buffer for the number of * samples of the frst block. * Iterate on the following blocks till EOF or terminator block */ vocdata = voc_open(file); if (!vocdata) return NULL; ALLEGRO_DEBUG("channels %d\n", vocdata->channels); ALLEGRO_DEBUG("word_size %d\n", vocdata->sample_size); ALLEGRO_DEBUG("rate %d\n", vocdata->samplerate); ALLEGRO_DEBUG("first_block_samples %d\n", vocdata->samples); ALLEGRO_DEBUG("first_block_size %d\n", vocdata->samples * vocdata->sample_size); /* * Let's allocate at least the first block's bytes; */ buffer = al_malloc(vocdata->samples * vocdata->sample_size); if (!buffer) { return NULL; } /* * We now need to iterate over data blocks till either we hit end of file * or we find a terminator block. */ bytestoread = vocdata->samples * vocdata->sample_size; while(!endofvoc && !al_feof(vocdata->file)) { uint32_t blocktype = 0; uint32_t x = 0, len = 0; read = al_fread(vocdata->file, buffer, bytestoread); pos += read; READNBYTES(vocdata->file, blocktype, 1, NULL); // read next block type if (al_feof(vocdata->file)) break; switch (blocktype) { case 0:{ /* we found a terminator block */ endofvoc = true; break; } case 2:{ /*we found a continuation block: unlikely but handled */ x = 0; bytestoread = 0; READNBYTES(vocdata->file, bytestoread, 2, NULL); READNBYTES(vocdata->file, x, 1, NULL); bytestoread += x<<16; /* increase subsequently storage */ buffer = al_realloc(buffer, sizeof(buffer) + bytestoread); break; } case 1: // we found a NEW data block starter, I assume this is wrong case 8: // and let the so far read sample data correctly in the case 9:{ // already allocated buffer. endofvoc = true; break; } case 3: /* we found a pause block */ case 4: /* we found a marker block */ case 5: /* we found an ASCII c-string block */ case 6: /* we found a repeat block */ case 7:{ /* we found an end repeat block */ /* all these blocks will be skipped */ unsigned int ii; len = 0; x = 0; READNBYTES(vocdata->file, len, 2, NULL); READNBYTES(vocdata->file, x, 1, NULL); len += x<<16; // this is the length what's left to skip */ for (ii = 0; ii < len ; ++ii) { al_fgetc(vocdata->file); } bytestoread = 0; //should let safely check for the next block */ break; } default: break; } } sample = al_create_sample(buffer, pos, vocdata->samplerate, _al_word_size_to_depth_conf(vocdata->sample_size), _al_count_to_channel_conf(vocdata->channels), true); if (!sample) al_free(buffer); voc_close(vocdata); return sample; }