Exemplo n.º 1
0
/* jpeg_load_hdr:
 * Load the header of a JPEG file. */
int jpeg_load_hdr(img I) {
    struct jpeg_decompress_struct *cinfo;
    struct my_error_mgr *jerr;
    alloc_struct(jpeg_decompress_struct, cinfo);
    I->us = cinfo;
    alloc_struct(my_error_mgr, jerr);
    cinfo->err = jpeg_std_error(&jerr->pub);
    jerr->pub.error_exit = my_error_exit;
    if (setjmp(jerr->jb)) {
        /* Oops, something went wrong. */
        I->err = IE_HDRFORMAT;
        jpeg_destroy_decompress(cinfo);
        return 0;
    }

    jpeg_create_decompress(cinfo);
    jpeg_stdio_src(cinfo, I->fp);

    /* Read the header of the image. */
    jpeg_read_header(cinfo, TRUE);

    jpeg_start_decompress(cinfo);

    I->width = cinfo->output_width;
    I->height = cinfo->output_height;

    return 1;
}
Exemplo n.º 2
0
void REJMAP::remove_pos(           //Cut out an element
                        inT16 pos  //element to remove
                       ) {
  REJ *new_ptr;                  //new, smaller map
  int i;

  ASSERT_HOST (pos >= 0);
  ASSERT_HOST (pos < len);
  ASSERT_HOST (len > 0);

  len--;
  if (len > 0)
    new_ptr = (REJ *) memset (alloc_struct (len * sizeof (REJ), "REJ"),
      0, len * sizeof (REJ));
  else
    new_ptr = NULL;

  for (i = 0; i < pos; i++)
    new_ptr[i] = ptr[i];         //copy pre pos

  for (; pos < len; pos++)
    new_ptr[pos] = ptr[pos + 1]; //copy post pos

                                 //delete old map
  free_struct (ptr, (len + 1) * sizeof (REJ), "REJ");
  ptr = new_ptr;
}
Exemplo n.º 3
0
void * sec_object_init(char * uuid,struct struct_elem_attr *  share_data_desc)
{
	int ret;
	SEC_OBJECT * sec_object;

	sec_object=kmalloc(sizeof(SEC_OBJECT),GFP_KERNEL);
	if(sec_object==NULL)
		return NULL;
	memset(sec_object,0,sizeof(SEC_OBJECT));

	if(uuid==NULL)
		return NULL;
	strncpy(sec_object->uuid,uuid,DIGEST_SIZE*2);

	if(share_data_desc!=NULL)
	{
		sec_object->struct_template=create_struct_template(share_data_desc);
		if((sec_object->struct_template == NULL)
			&& IS_ERR(sec_object->struct_template))
			return NULL;
		ret=alloc_struct(&(sec_object->share_data),sec_object->struct_template);	
		if(ret<0)
		{
			kfree(sec_object);
			return NULL;
		}
	}
	ret=pthread_rwlock_init(&(sec_object->rwlock),NULL);
	if(ret<0)
	{
		free_struct(sec_object->share_data,sec_object->struct_template);
		return -EINVAL;
	}
	return sec_object;
}
Exemplo n.º 4
0
Arquivo: Node.c Projeto: kr094/c
node_t node_new() {
	node_t node;

	alloc_struct(sizeof(struct Node),(void **) &node);
	node->id = guid_new();
	return node_init(node);
}
Exemplo n.º 5
0
void REJMAP::initialise(  //Redefine map
                        inT16 length) {
  if (ptr != NULL)
    free_struct (ptr, len * sizeof (REJ), "REJ");
  len = length;
  if (len > 0)
    ptr = (REJ *) memset (alloc_struct (len * sizeof (REJ), "REJ"),
      0, len * sizeof (REJ));
  else
    ptr = NULL;
}
Exemplo n.º 6
0
	fn Scene* 
	new_scene(memory::Block* storage, i32 entity_count, i32 camera_count)
	{
		auto s = alloc_struct(storage, Scene);
		s->num_entities = 0;
		s->entities = alloc_array(storage, Entity, entity_count);
		s->num_cameras = 0;
		s->cameras = alloc_array(storage, Camera, camera_count);
		scene::set_context(s);
		scene::new_entity();
		scene::new_camera();
		return s;
	}
Exemplo n.º 7
0
/**
 * Read a permanent configuration description from File
 * and return a ptr to it.
 *
 * @param File  open file to read permanent config from
 * @return Ptr to new permanent configuration description.
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Tue Mar 19 14:25:26 1991, DSJ, Created.
 */
PERM_CONFIG ReadPermConfig(FILE *File) {
  PERM_CONFIG Config = (PERM_CONFIG) alloc_struct(sizeof(PERM_CONFIG_STRUCT),
                                                  "PERM_CONFIG_STRUCT");
  uinT8 NumAmbigs;
  fread ((char *) &NumAmbigs, sizeof(uinT8), 1, File);
  Config->Ambigs = (UNICHAR_ID *)Emalloc(sizeof(UNICHAR_ID) * (NumAmbigs + 1));
  fread(Config->Ambigs, sizeof(UNICHAR_ID), NumAmbigs, File);
  Config->Ambigs[NumAmbigs] = -1;
  fread(&(Config->FontinfoId), sizeof(int), 1, File);

  return (Config);

}                                /* ReadPermConfig */
Exemplo n.º 8
0
/**
 * Read a temporary configuration description from File
 * and return a ptr to it.
 *
 * @param File  open file to read temporary config from
 * @return Ptr to new temporary configuration description.
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Tue Mar 19 14:29:59 1991, DSJ, Created.
 */
TEMP_CONFIG ReadTempConfig(FILE *File) {
  TEMP_CONFIG Config;

  Config =
    (TEMP_CONFIG) alloc_struct (sizeof (TEMP_CONFIG_STRUCT),
    "TEMP_CONFIG_STRUCT");
  fread ((char *) Config, sizeof (TEMP_CONFIG_STRUCT), 1, File);

  Config->Protos = NewBitVector (Config->ProtoVectorSize * BITSINLONG);
  fread ((char *) Config->Protos, sizeof (uinT32),
    Config->ProtoVectorSize, File);

  return (Config);

}                                /* ReadTempConfig */
Exemplo n.º 9
0
/* skiplist_new COMPAREFUNC
 * Initialise a new skiplist using COMPAREFUNC to compare the values of keys;
 * or, if COMPAREFUNC is NULL, use the generic comparison function. */
skiplist skiplist_new(int(*compare)(const void *, const size_t, const void *, const size_t)) {
    skiplist S;
    alloc_struct(tag_skiplist, S);

    S->compare = compare;
    if (!S->compare)
        S->compare = generic_compare;

    S->P = pool_new_size(32);

    /* First pair of nodes. */
    S->min    = node_new(S, MINUSINF, 0, NULL, 0);
    S->max    = node_new(S, PLUSINF, 0, NULL, 0);
    S->min->more[0] = S->max;
    S->max->less    = S->min;

    return S;
}
Exemplo n.º 10
0
		fn Mesh*
		quad(memory::Block* storage, f32 width, f32 height, f32 depth)
		{
			auto w = width * 0.5f;
			auto h = height * 0.5f;
			auto d = depth * 0.5f;
			float verts[] = 
			{ 
				-w, -h, d,
				 w, -h, d,
				-w,  h, d,
				 w,  h, d,

				0.0f, 1.0f,
				1.0f, 1.0f,
				0.0f, 0.0f,
				1.0f, 0.0f
			};

			u16 indices[] = 
			{
				0,1,3,0,3,2
			};

			auto mask = VertexAttribute::POSITION |
						VertexAttribute::UV;

			auto m = alloc_struct(storage, Mesh);
			m->vertex_count = 4;
			m->index_count = 6;
			m->draw_type = mesh::DrawType::TRIANGLES;
			m->update_mode = mesh::UpdateMode::STATIC;
			m->attribute_mask = VertexAttribute::POSITION |
								VertexAttribute::UV;

			mesh::alloc_array_buffers(storage, m);
			mesh::set_data(m, &verts[0], &indices[0]);

			m->linked = false;
			m->dirty = true;

			return m;
		}
Exemplo n.º 11
0
adlb_data_code xlb_new_struct(adlb_struct_type type, adlb_struct **s)
{
  check_valid_type(type);

  xlb_struct_type_info *t = &struct_types[type];

  adlb_struct *tmp = alloc_struct(t);
  ADLB_CHECK_MSG_CODE(tmp != NULL, ADLB_DATA_ERROR_OOM, "Out of memory");

  tmp->type = type;
  for (int i = 0; i < t->field_count; i++)
  {
    tmp->fields[i].initialized = false;
    tmp->fields[i].reserved = false;
  }
  *s = tmp;

  return ADLB_DATA_SUCCESS;
}
Exemplo n.º 12
0
/**
 * This routine allocates and returns a new temporary config.
 *
 * @param MaxProtoId  max id of any proto in new config
 * @param FontinfoId font information from pre-trained templates
 * @return Ptr to new temp config.
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Thu Mar 14 13:28:21 1991, DSJ, Created.
 */
TEMP_CONFIG NewTempConfig(int MaxProtoId, int FontinfoId) {
  TEMP_CONFIG Config;
  int NumProtos = MaxProtoId + 1;

  Config =
    (TEMP_CONFIG) alloc_struct (sizeof (TEMP_CONFIG_STRUCT),
    "TEMP_CONFIG_STRUCT");
  Config->Protos = NewBitVector (NumProtos);

  Config->NumTimesSeen = 1;
  Config->MaxProtoId = MaxProtoId;
  Config->ProtoVectorSize = WordsInVectorOfSize (NumProtos);
  Config->ContextsSeen = NIL_LIST;
  zero_all_bits (Config->Protos, Config->ProtoVectorSize);
  Config->FontinfoId = FontinfoId;

  return (Config);

}                                /* NewTempConfig */
Exemplo n.º 13
0
REJMAP::REJMAP(  //classwise copy
               const REJMAP &source) {
  REJ *to;
  REJ *from = source.ptr;
  int i;

  len = source.length ();

  if (len > 0) {
    ptr = (REJ *) alloc_struct (len * sizeof (REJ), "REJ");
    to = ptr;
    for (i = 0; i < len; i++) {
      *to = *from;
      to++;
      from++;
    }
  }
  else
    ptr = NULL;
}
Exemplo n.º 14
0
/**
 * Read an adapted class description from File and return
 * a ptr to the adapted class.
 *
 * @param File  open file to read adapted class from
 * @return Ptr to new adapted class.
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Tue Mar 19 14:11:01 1991, DSJ, Created.
 */
ADAPT_CLASS ReadAdaptedClass(FILE *File) {
  int NumTempProtos;
  int NumConfigs;
  int i;
  ADAPT_CLASS Class;
  TEMP_PROTO TempProto;

  /* first read high level adapted class structure */
  Class = (ADAPT_CLASS) Emalloc (sizeof (ADAPT_CLASS_STRUCT));
  fread ((char *) Class, sizeof (ADAPT_CLASS_STRUCT), 1, File);

  /* then read in the definitions of the permanent protos and configs */
  Class->PermProtos = NewBitVector (MAX_NUM_PROTOS);
  Class->PermConfigs = NewBitVector (MAX_NUM_CONFIGS);
  fread ((char *) Class->PermProtos, sizeof (uinT32),
    WordsInVectorOfSize (MAX_NUM_PROTOS), File);
  fread ((char *) Class->PermConfigs, sizeof (uinT32),
    WordsInVectorOfSize (MAX_NUM_CONFIGS), File);

  /* then read in the list of temporary protos */
  fread ((char *) &NumTempProtos, sizeof (int), 1, File);
  Class->TempProtos = NIL_LIST;
  for (i = 0; i < NumTempProtos; i++) {
    TempProto =
      (TEMP_PROTO) alloc_struct (sizeof (TEMP_PROTO_STRUCT),
      "TEMP_PROTO_STRUCT");
    fread ((char *) TempProto, sizeof (TEMP_PROTO_STRUCT), 1, File);
    Class->TempProtos = push_last (Class->TempProtos, TempProto);
  }

  /* then read in the adapted configs */
  fread ((char *) &NumConfigs, sizeof (int), 1, File);
  for (i = 0; i < NumConfigs; i++)
    if (test_bit (Class->PermConfigs, i))
      Class->Config[i].Perm = ReadPermConfig (File);
    else
      Class->Config[i].Temp = ReadTempConfig (File);

  return (Class);

}                                /* ReadAdaptedClass */
Exemplo n.º 15
0
/*---------------------------------------------------------------------------*/
FEATURE NewFeature(const FEATURE_DESC_STRUCT* FeatureDesc) {
/*
 **	Parameters:
 **		FeatureDesc	description of feature to be created.
 **	Globals: none
 **	Operation: Allocate and return a new feature of the specified
 **		type.
 **	Return: New feature.
 **	Exceptions: none
 **	History: Mon May 21 14:06:42 1990, DSJ, Created.
 */
  FEATURE Feature;

  Feature = (FEATURE) alloc_struct (sizeof (FEATURE_STRUCT) +
    (FeatureDesc->NumParams - 1) *
    sizeof (FLOAT32),
    "sizeof(FEATURE_STRUCT)+sizeof(FLOAT32)*(NumParamsIn(Feature)-1)");
  Feature->Type = FeatureDesc;
  return (Feature);

}                                /* NewFeature */
Exemplo n.º 16
0
DLLSYM char *alloc_string(             //allocate string
                          inT32 count  //no of chars required
                         ) {
#ifdef RAYS_MALLOC
  char *string;                  //allocated string

  if (count < 1 || count > MAX_CHUNK) {
    tprintf ("Invalid size %d requested of alloc_string", count);
    return NULL;
  }

  count++;                       //add size byte
  if (count <= MAX_STRUCTS * sizeof (MEMUNION)) {
    string = (char *) alloc_struct (count, "alloc_string");
    //get a fast structure
    if (string == NULL) {
      tprintf ("No memory for alloc_string");
      return NULL;
    }
    string[0] = (inT8) count;    //save its length
  }
  else {
                                 //get a big block
    string = (char *) alloc_mem (count);
    if (string == NULL) {
      tprintf ("No memory for alloc_string");
      return NULL;
    }
    string[0] = 0;               //mark its id
  }
  return &string[1];             //string for user
#else
  // Round up the amount allocated to a multiple of 4
  return static_cast<char*>(malloc((count + 3) & ~3));
#endif
}
Exemplo n.º 17
0
Arquivo: List.c Projeto: kr094/c
list_t list_new() {
	list_t list;

	alloc_struct(sizeof(struct List), (void **) &list);
	return list_init(list);
}
Exemplo n.º 18
0
/** Return a new edge point for a micro-feature outline. */
MFEDGEPT *NewEdgePoint() {
  return ((MFEDGEPT *) alloc_struct(sizeof(MFEDGEPT), "MFEDGEPT"));
}
Exemplo n.º 19
0
adlb_data_code
ADLB_Unpack_struct(adlb_struct **s, const void *data, size_t length,
                   adlb_refc refcounts, bool init_struct)
{
  adlb_data_code dc;

  assert(s != NULL);
  ADLB_CHECK_MSG_CODE(length >= sizeof(adlb_packed_struct_hdr), ADLB_DATA_ERROR_INVALID,
                "buffer too small for serialized struct");
  const adlb_packed_struct_hdr *hdr = data;
  check_valid_type(hdr->type);
  xlb_struct_type_info *t = &struct_types[hdr->type];
  size_t min_length = sizeof(adlb_packed_struct_hdr) +
                sizeof(hdr->field_offsets[0]) * (size_t)t->field_count;
  ADLB_CHECK_MSG_CODE((size_t)length >= min_length, ADLB_DATA_ERROR_INVALID,
                "buffer too small for header of struct type %s: is %zub, "
                "but expected >= %zub", t->type_name, length, min_length);

  if (init_struct)
  {
    *s = alloc_struct(t);
    ADLB_CHECK_MSG_CODE(*s != NULL, ADLB_DATA_ERROR_OOM, "Couldn't allocate struct");
    (*s)->type = hdr->type;

    for (int i = 0; i < t->field_count; i++)
    {
      // Need to mark fields as uninitialized
      (*s)->fields[i].initialized = false;
    }
  }
  else
  {
    assert(is_valid_type((*s)->type));
    ADLB_CHECK_MSG_CODE((*s)->type == hdr->type, ADLB_DATA_ERROR_TYPE,
             "Type of target struct doesn't match source data: %s vs. %s",
              struct_types[(*s)->type].type_name, t->type_name);
  }

  // Go through and assign all of the datums from the data in the buffer
  for (int i = 0; i < t->field_count; i++)
  {
    size_t init_offset = hdr->field_offsets[i];
    size_t data_offset = init_offset + 1;

    bool field_init = (((char*)data)[init_offset] != 0);

    if (field_init)
    {
      const void *field_start = ((const char*)data) + data_offset;
      size_t field_len;
      if (i == t->field_count - 1)
      {
        // Remainder of buffer
        field_len = length - data_offset;
      }
      else
      {
        field_len = hdr->field_offsets[i + 1] - data_offset;
      }

      if ((*s)->fields[i].initialized)
      {
        // Free any existing data
        dc = ADLB_Free_storage(&(*s)->fields[i].data,
                               t->field_types[i].type);
        ADLB_DATA_CHECK_CODE(dc);
      }

      ADLB_Unpack(&(*s)->fields[i].data, t->field_types[i].type,
                  field_start, field_len, refcounts);
      (*s)->fields[i].initialized = true;
    }
  }

  return ADLB_DATA_SUCCESS;
}
Exemplo n.º 20
0
void *c_alloc_struct(                  //allocate memory
                     INT32 count,      //no of chars required
                     const char *name  //class name
                    ) {
  return alloc_struct (count, name);
}
Exemplo n.º 21
0
Arquivo: Node.c Projeto: kr094/c
node_t node_blank() {
	node_t node;

	alloc_struct(sizeof(struct Node),(void **) &node);
	return node_init(node);
}
Exemplo n.º 22
0
/**
 * This routine allocates and returns a new temporary proto.
 *
 * @return Ptr to new temporary proto.
 *
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Thu Mar 14 13:31:31 1991, DSJ, Created.
 */
TEMP_PROTO NewTempProto() {
  return ((TEMP_PROTO)
    alloc_struct (sizeof (TEMP_PROTO_STRUCT), "TEMP_PROTO_STRUCT"));
}                                /* NewTempProto */