コード例 #1
0
ファイル: bitmap.c プロジェクト: dpt/PrivateEye
int bitmap_unload(image_t *image)
{
  if (image != NULL)
    if (image->image != NULL)
      flex_free(&image->image);

  return FALSE; /* success */
}
コード例 #2
0
ファイル: buf.c プロジェクト: bonzini/flex
/** Append a line directive to the string buffer.
 * @param buf A string buffer.
 * @param filename file name
 * @param lineno line number
 * @return buf
 */
struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
{
    char   *t, *fmt = "#line %d \"%s\"\n";

    t = flex_alloc (strlen (fmt) + strlen (filename) + (int)(1 + log10(lineno>=0?lineno:-lineno)) + 1);
    sprintf (t, fmt, lineno, filename);
    buf = buf_strappend (buf, t);
    flex_free (t);
    return buf;
}
コード例 #3
0
ファイル: buf.c プロジェクト: bonzini/flex
/* Append a "%s" formatted string to a string buffer */
struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s)
{
    char   *t;

    t = flex_alloc (strlen (fmt) + strlen (s) + 1);
    sprintf (t, fmt, s);
    buf = buf_strappend (buf, t);
    flex_free (t);
    return buf;
}
コード例 #4
0
ファイル: buf.c プロジェクト: sparkhom/openbsd-flex
/* Append a "%s" formatted string to a string buffer */
struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s)
{
	char   *t;
        size_t tsz;

	t = flex_alloc (tsz = strlen (fmt) + strlen (s) + 1);
	if (!t)
	    flexfatal (_("Allocation of buffer to print string failed"));
	snprintf (t, tsz, fmt, s);
	buf = buf_strappend (buf, t);
	flex_free (t);
	return buf;
}
コード例 #5
0
ファイル: buf.c プロジェクト: DmitrySigaev/winflexbison
/** Append a line directive to the string buffer.
 * @param buf A string buffer.
 * @param filename file name
 * @param lineno line number
 * @return buf
 */
struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
{
    char *dst, *src, *t;

    t = flex_alloc (strlen ("#line \"\"\n")          +   /* constant parts */
                    2 * strlen (filename)            +   /* filename with possibly all backslashes escaped */
                    (int) (1 + log10 (abs (lineno))) +   /* line number */
                    1);                                  /* NUL */
    if (!t)
      flexfatal (_("Allocation of buffer for line directive failed"));
    for (dst = t + sprintf (t, "#line %d \"", lineno), src = filename; *src; *dst++ = *src++)
      if (*src == '\\')   /* escape backslashes */
        *dst++ = '\\';
    *dst++ = '"';
    *dst++ = '\n';
    *dst   = '\0';
    buf = buf_strappend (buf, t);
    flex_free (t);
    return buf;
}
コード例 #6
0
ファイル: bitmap.c プロジェクト: dpt/PrivateEye
/* 1,3,5,7: hard rotation */
static int rotate_hard(image_t *image, int angle)
{
  osspriteop_area      *area;
  osspriteop_header    *header;
  osspriteop_area      *newarea;
  osspriteop_header    *newheader;
  int                   w,h;
  int                   neww,newh;
  size_t                sprimgbytes;
  size_t                sprrowbytes;
  int                   c0,c1,c2,c3;
  os_trfm               t;
  osspriteop_trans_tab *trans_tab;
  int                   log2bpp;
  int                   xeig,yeig;

  area   = (osspriteop_area *) image->image;
  header = sprite_select(area, 0);

  w = image->display.dims.bm.width;
  h = image->display.dims.bm.height;

  /* work out sprite area size */

  read_mode_vars(header->mode, &xeig, &yeig, &log2bpp);

  neww = (h << yeig) >> xeig;
  newh = (w << xeig) >> yeig;

  sprrowbytes = (((neww << log2bpp) + 31) & ~31) >> 3;
  sprimgbytes = sizeof(osspriteop_area) + sizeof(osspriteop_header);
  sprimgbytes += sprrowbytes * newh;

  /* alloc area */

  if (flex_alloc((flex_ptr) &newarea, sprimgbytes) == 0)
    goto NoMem;

  /* HEAP HAS MOVED! - update pointers */
  area   = (osspriteop_area *) image->image;
  header = sprite_select(area, 0);

  /* init area */

  newarea->size  = sprimgbytes;
  newarea->first = 16;
  osspriteop_clear_sprites(osspriteop_USER_AREA, newarea);

  /* create sprite */
  /* this should be identical to the original, save for dimensions */

  /* ### masks won't work yet */

  osspriteop_create_sprite(osspriteop_NAME,
                           newarea,
                           header->name,
                           0, /* no palette */ /* ### */
                           neww, newh,
                           header->mode);

  /* redirect to sprite */

  newheader = sprite_select(newarea, 0);

  osspriteop_switch_output_to_sprite(osspriteop_PTR,
                                     newarea,
                     (osspriteop_id) newheader,
                                     0,
                                     &c0, &c1, &c2, &c3);

  /* set up drawing stuff */

  if (sprite_colours((osspriteop_area **) &image->image, header, &trans_tab))
    goto NoMem;

  /* problem: we're switched to a sprite which _may_ have moved now
   * so as a work-around, unswitch output and update pointers, then switch
   * back */

  /* redirect back */

  osspriteop_unswitch_output(c0, c1, c2, c3);

  /* HEAP HAS MOVED! - update pointers */
  area   = (osspriteop_area *) image->image;
  header = sprite_select(area, 0);

  /* redirect to sprite */

  newheader = sprite_select(newarea, 0);

  osspriteop_switch_output_to_sprite(osspriteop_PTR,
                                     newarea,
                     (osspriteop_id) newheader,
                                     0,
                                     &c0, &c1, &c2, &c3);

  /* dimensions need to be in OS units now */

  w <<= xeig;
  h <<= yeig;

  neww <<= xeig; /* these might be the wrong way around */
  newh <<= yeig;

  /* set up our transform */

  trfm_set_identity(&t);

  /* flip horizontally */
  if (angle >= 4)
  {
    t.entries[0][0] = -t.entries[0][0];
    t.entries[2][0] += w;
  }

  trfm_translate(&t, -w / 2, -h / 2);

  trfm_rotate_degs(&t, (angle & 3) * 90 * 65536);

  trfm_translate(&t, neww / 2, newh / 2);

  t.entries[0][0] *= 256;
  t.entries[0][1] *= 256;
  t.entries[1][0] *= 256;
  t.entries[1][1] *= 256;
  t.entries[2][0] *= 256;
  t.entries[2][1] *= 256;

  /* draw */

  osspriteop_put_sprite_trfm(osspriteop_PTR,
                             area,
             (osspriteop_id) header,
                             0, /* trfm_flags */
                             NULL, /* source_rect */
                             osspriteop_USE_MASK, /* action */
                            &t,
                             trans_tab);

  /* redirect back */

  osspriteop_unswitch_output(c0, c1, c2, c3);

  if (trans_tab)
    flex_free((flex_ptr) &trans_tab);

  /* replace previous sprite */

  flex_free((flex_ptr) &image->image);

  image->display.dims.bm.width  = neww >> xeig; /* see note above */
  image->display.dims.bm.height = newh >> yeig;

  flex_reanchor((flex_ptr) &image->image, (flex_ptr) &newarea);
  image->display.file_size = sprimgbytes;

  return FALSE; /* success */


NoMem:

  oserror_report(0, "error.no.mem");
  return TRUE; /* failure */
}
コード例 #7
0
ファイル: buf.c プロジェクト: stefanreinauer/flex
/* frees memory */
void buf_destroy (struct Buf *buf)
{
	if (buf && buf->elts)
		flex_free (buf->elts);
	buf->elts = (void *) 0;
}