Esempio n. 1
0
/* import_bitmap_font_mono:
 *  Helper for import_bitmap_font, below.
 */
static int import_bitmap_font_mono(FONT_GLYPH** gl, int num)
{
  int w = 1, h = 1, i;

  for(i = 0; i < num; i++) {
    if(w > 0 && h > 0) datedit_find_character(import_bmp, &import_x, &import_y, &w, &h);
    if(w <= 0 || h <= 0) {
      int j;

      gl[i] = (FONT_GLYPH*)_al_malloc(sizeof(FONT_GLYPH) + 8);
      gl[i]->w = 8;
      gl[i]->h = 8;

      for(j = 0; j < 8; j++) gl[i]->dat[j] = 0;
    } else {
      int sx = ((w + 7) / 8), j, k;

      gl[i] = (FONT_GLYPH*)_al_malloc(sizeof(FONT_GLYPH) + sx * h);
      gl[i]->w = w;
      gl[i]->h = h;

      for(j = 0; j < sx * h; j++) gl[i]->dat[j] = 0;
      for(j = 0; j < h; j++) {
        for(k = 0; k < w; k++) {
          if(getpixel(import_bmp, import_x + k + 1, import_y + j + 1))
            gl[i]->dat[(j * sx) + (k / 8)] |= 0x80 >> (k & 7);
        }
      }

      import_x += w;
    }
  }

  return 0;
}
Esempio n. 2
0
SAMPLE* logg_load(const char* filename)
{
	OggVorbis_File ovf;
	FILE* file;
	vorbis_info* vi;
	SAMPLE* samp;
	int numRead;
	int offset = 0;
	int bitstream;
	char *buf = malloc(logg_bufsize);

	file = fopen(filename, "rb");
	if (!file) {
		uszprintf(allegro_error, ALLEGRO_ERROR_SIZE, "Unable to open file: %s", filename);
		free(buf);
		return 0;
	}

	if (ov_open_callbacks(file, &ovf, 0, 0, OV_CALLBACKS_DEFAULT) != 0) {
		strncpy(allegro_error, "ov_open_callbacks failed.", ALLEGRO_ERROR_SIZE);
		fclose(file);
		free(buf);
		return 0;
	}

	vi = ov_info(&ovf, -1);

	samp = (SAMPLE*)_al_malloc(sizeof(SAMPLE));
	if (!samp) {
		ov_clear(&ovf);
		free(buf);
		return 0;
	}

	samp->bits = 16;
	samp->stereo = vi->channels > 1 ? 1 : 0;
	samp->freq = vi->rate;
	samp->priority = 128;
	samp->len = ov_pcm_total(&ovf, -1);
	samp->loop_start = 0;
	samp->loop_end = samp->len;
	samp->data = _al_malloc(sizeof(unsigned short) * samp->len * 2);

	while ((numRead = ov_read(&ovf, buf, logg_bufsize,
				ENDIANNESS, 2, 0, &bitstream)) != 0) {
		memcpy((unsigned char*)samp->data+offset, buf, numRead);
		offset += numRead;
	}

	ov_clear(&ovf);
	free(buf);

	return samp;
}
Esempio n. 3
0
/* import routine for the Allegro .pcx font format */
FONT* create_font()
{
  FONT *f;
  FONT_MONO_DATA* mf = _al_malloc(sizeof(FONT_MONO_DATA));

  f = _al_malloc(sizeof(FONT));

  mf->glyphs = _al_malloc(sizeof(FONT_GLYPH*) * (192));

  if( convert_8x8_tiles_to_mono_font(mf->glyphs, 10920, 192) )
  {
    free(mf->glyphs);
    free(mf);
    free(f);
    f = 0;
  }
  else
  {
    f->data = mf;
    f->vtable = font_vtable_mono;
    f->height = mf->glyphs[0]->h;
    mf->begin = 0;
    mf->end = 192;
    mf->next = 0;
  }

  //delete this.  only added to keep compiler from whining
  if( convert_16x16_tiles_to_mono_font(mf->glyphs, 10920, 192) )
  {
    free(mf->glyphs);
    free(mf);
    free(f);
    f = 0;
  }
  else
  {
    f->data = mf;
    f->vtable = font_vtable_mono;
    f->height = mf->glyphs[0]->h;
    mf->begin = 0;
    mf->end = 192;
    mf->next = 0;
  }

  return f;

}
Esempio n. 4
0
static int convert_16x16_tiles_to_mono_font(FONT_GLYPH** gl, int start, int num)
{
  int w = 8, h = 8, i;

  for(i = 0; i < 32; i++)
  {
    int sx = ((w + 7) / 8), j;
    gl[i] = _al_malloc(sizeof(FONT_GLYPH) + sx * h);
    gl[i]->w = w;
    gl[i]->h = h;

    for(j = 0; j < sx * h; j++) gl[i]->dat[j] = 0;
  }
  for(i = 32; i < num+32; i++)
  {
    int tile=(((i-32)/16)*20)+((i-32)%16);

    int sx = ((w + 7) / 8), j, k;

    unpack_tile(start+tile);
    gl[i] = _al_malloc(sizeof(FONT_GLYPH) + sx * h);
    gl[i]->w = w;
    gl[i]->h = h;

    for(j = 0; j < sx * h; j++) gl[i]->dat[j] = 0;

    for(j = 0; j < h; j++)
    {
      for(k = 0; k < w; k++)
      {
        if(unpackbuf[j*16+k])
        {
          gl[i]->dat[(j * sx) + (k / 8)] |= 0x80 >> (k & 7);
        }
      }
    }
  }
  return 0;
}
/* creates a new bitmap object */
static void *makenew_jpeg(long *size)
{
	BITMAP *bmp = create_bitmap_ex(8, 32, 32);
	int buffer_size = 32 * 32 * 3;
	char *buffer = (char *)_al_malloc(buffer_size);

	clear_bitmap(bmp);
#if (ALLEGRO_VERSION >= 4 && ALLEGRO_SUB_VERSION >= 1 && ALLEGRO_WIP_VERSION >= 4)
	textout_centre_ex(bmp, font, "JPG", 16, 12, 1, -1);
#else
	text_mode(-1);
	textout_centre(bmp, font, "JPG", 16, 12, 1);
#endif
	save_memory_jpg(buffer, &buffer_size, bmp, NULL);
	destroy_bitmap(bmp);

	*size = buffer_size;

	return buffer;
}
Esempio n. 6
0
FONT *_ji_bitmap2font(BITMAP *bmp)
{
  FONT *f;
  int begin = ' ';
  int end = -1;

  import_bmp = bmp;
  import_x = 0;
  import_y = 0;

  if(bitmap_color_depth(import_bmp) != 8) {
    import_bmp = NULL;
    return 0;
  }

  f = (FONT*)_al_malloc(sizeof(FONT));
  if(end == -1) end = bitmap_font_count(import_bmp) + begin;

  if (bitmap_font_ismono(import_bmp)) {

    FONT_MONO_DATA* mf = (FONT_MONO_DATA*)_al_malloc(sizeof(FONT_MONO_DATA));

    mf->glyphs = (FONT_GLYPH**)_al_malloc(sizeof(FONT_GLYPH*) * (end - begin));

    if( import_bitmap_font_mono(mf->glyphs, end - begin) ) {

      free(mf->glyphs);
      free(mf);
      free(f);
      f = 0;

    } else {

      f->data = mf;
      f->vtable = font_vtable_mono;
      f->height = mf->glyphs[0]->h;

      mf->begin = begin;
      mf->end = end;
      mf->next = 0;
    }

  } else {

    FONT_COLOR_DATA* cf = (FONT_COLOR_DATA*)_al_malloc(sizeof(FONT_COLOR_DATA));
    cf->bitmaps = (BITMAP**)_al_malloc(sizeof(BITMAP*) * (end - begin));

    if( import_bitmap_font_color(cf->bitmaps, end - begin) ) {

      free(cf->bitmaps);
      free(cf);
      free(f);
      f = 0;

    } else {

      f->data = cf;
      f->vtable = font_vtable_color;
      f->height = cf->bitmaps[0]->h;

      cf->begin = begin;
      cf->end = end;
      cf->next = 0;

    }

  }

  import_bmp = NULL;

  return f;
}