Example #1
0
File: hfile.c Project: pipul/lab
index_t *index_load(int32_t fd, int32_t offset, int32_t size)
{
	int32_t id;
	int32_t len;
	index_t *l;
	int8_t *buffer, *ptr;
	meta_t *o;
	
	if (fd < 0 || offset < 0 || size < 0)
		return(NULL);
	if ((l = index_new()) == NULL)
		return(NULL);
	if ((buffer = malloc(size)) == NULL)
		__ERROR_LOG(B_ERROR);
	lseek(fd,offset,SEEK_SET);
	if (size != read(fd,buffer,size))
		__ERROR_LOG(R_ERROR);

	ptr = buffer;
	l->magic = *(uint64_t *)ptr;
	ptr = ptr + sizeof(uint64_t);
	if (l->magic != crc32_encode(ptr,size - sizeof(uint64_t)))
		__ERROR_LOG(C_ERROR);

	id = 0;		/* inode id */
	while (ptr - buffer < size) {
		if ((o = meta_new()) == NULL)
			break;
		o->offset = *(int32_t *)ptr;
		ptr = ptr + sizeof(int32_t);

		o->blocksize = *(int32_t *)ptr;
		ptr = ptr + sizeof(int32_t);

		len = *(int32_t *)ptr;
		ptr = ptr + sizeof(int32_t);
		o->key = sdsnnew(ptr,len);
		ptr = ptr + len;

		if (o->key == NULL) {
			meta_free(o);
			continue;
		}
		o->id = id++;
		index_add(l,o);
	}

	free(buffer);
	return(l);

C_ERROR:
R_ERROR:
	free(buffer);
B_ERROR:
	index_free(l);
	return(NULL);
}
Example #2
0
/** 
 * vips_image_set:
 * @image: image to set the metadata on
 * @field: the name to give the metadata
 * @value: the %GValue to copy into the image
 *
 * Set a piece of metadata on @image. Any old metadata with that name is
 * destroyed. The %GValue is copied into the image, so you need to unset the
 * value when you're done with it.
 *
 * For example, to set an integer on an image (though you would use the
 * convenience function vips_image_set_int() in practice), you would do:
 *
 * |[
 * GValue value = { 0 };
 *
 * g_value_init (&amp;value, G_TYPE_INT);
 * g_value_set_int (&amp;value, 42);
 * vips_image_set (image, field, &amp;value);
 * g_value_unset (&amp;value);
 * ]|
 *
 * See also: vips_image_get().
 */
void
vips_image_set( VipsImage *image, const char *field, GValue *value )
{
	g_assert( field );
	g_assert( value );

	meta_init( image );
	(void) meta_new( image, field, value );

#ifdef DEBUG
	meta_sanity( image );
#endif /*DEBUG*/
}
Example #3
0
struct sst *sst_new(const char *basedir)
{
	struct sst *s;
	s = malloc(sizeof(struct sst));
	s->lsn = 0;
	s->meta = meta_new();
	memcpy(s->basedir, basedir, FILE_PATH_SIZE);

	s->mutexer.lsn = -1;
	pthread_mutex_init(&s->mutexer.mutex, NULL);

	_sst_load(s);

	return s;
}
Example #4
0
struct silopit *silopit_new(const char *basedir)
{
	struct silopit *s;

	s = calloc(1, sizeof(struct silopit));

	s->meta = meta_new();
	memcpy(s->basedir, basedir, FILE_PATH_SIZE);

	s->hiraishin = hiraishin_new();
	s->mutexer.lsn = -1;
	pthread_mutex_init(&s->mutexer.mutex, NULL);
	s->buf= buffer_new(1024*1024*4);
	_silopit_load(s);
	return s;
}
Example #5
0
static void *
meta_cp_field( VipsMeta *meta, VipsImage *dst )
{
#ifdef DEBUG
{
	char *str_value;

	str_value = g_strdup_value_contents( &meta->value );
	printf( "vips__meta_cp: copying field %s, value = %s\n", 
		meta->field, str_value );
	g_free( str_value );
}
#endif /*DEBUG*/

	(void) meta_new( dst, meta->field, &meta->value );

#ifdef DEBUG
	meta_sanity( dst );
#endif /*DEBUG*/

	return( NULL );
}
Example #6
0
Filter *filter_gauss_blur_new(void)
{
  Filter *filter = filter_new(&filter_core_gauss);
  Meta *in, *out, *channel, *bitdepth, *color[3], *setting, *bound;
  Meta *ch_out[3];
  _Data *data = calloc(sizeof(_Data), 1);
  data->sigma = calloc(sizeof(float), 1);
  data->buf1 = malloc(BLURBUF);
  data->buf2 = malloc(BLURBUF);
  filter->fixme_outcount = 3;
  ea_push(filter->data, data);
  
  *data->sigma = 5.0;
  
  filter->mode_buffer = filter_mode_buffer_new();
  filter->mode_buffer->worker = &_worker;
  filter->mode_buffer->threadsafe = 1;
  filter->mode_buffer->area_calc = &_area_calc;
  filter->mode_buffer->data_new = &_gauss_data_new;
  
  bitdepth = meta_new_data(MT_BITDEPTH, filter, malloc(sizeof(int)));
  *(int*)(bitdepth->data) = BD_U8;
  bitdepth->replace = bitdepth;
  
  out = meta_new(MT_BUNDLE, filter);
  eina_array_push(filter->out, out);
  
  channel = meta_new_channel(filter, 1);
  color[0] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(color[0]->data) = CS_LAB_L;
  meta_attach(channel, color[0]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[0] = channel;
  
  channel = meta_new_channel(filter, 2);
  color[1] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(color[1]->data) = CS_LAB_A;
  meta_attach(channel, color[1]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[1] = channel;
  
  channel = meta_new_channel(filter, 3);
  color[2] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(color[2]->data) = CS_LAB_B;
  meta_attach(channel, color[2]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[2] = channel;
  
  in = meta_new(MT_BUNDLE, filter);
  in->replace = out;
  eina_array_push(filter->in, in);
  
  channel = meta_new_channel(filter, 1);
  color[0]->replace = color[0];
  channel->replace = ch_out[0];
  meta_attach(channel, color[0]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
  
  channel = meta_new_channel(filter, 2);
  color[1]->replace = color[1];
  channel->replace = ch_out[1];
  meta_attach(channel, color[1]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
  
  channel = meta_new_channel(filter, 3);
  color[2]->replace = color[2];
  color[2]->replace = color[2];
  channel->replace = ch_out[2];
  meta_attach(channel, color[2]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
    
  setting = meta_new_data(MT_FLOAT, filter, data->sigma);
  meta_name_set(setting, "sigma");
  eina_array_push(filter->settings, setting);
  
  bound = meta_new_data(MT_FLOAT, filter, malloc(sizeof(int)));
  *(float*)bound->data = 0;
  meta_name_set(bound, "PARENT_SETTING_MIN");
  meta_attach(setting, bound);
  
  bound = meta_new_data(MT_FLOAT, filter, malloc(sizeof(int)));
  *(float*)bound->data = MAX_SIGMA;
  meta_name_set(bound, "PARENT_SETTING_MAX");
  meta_attach(setting, bound);
  
  return filter;
}
Filter *filter_down_new(void)
{
  Filter *filter = filter_new(&filter_core_down);
  Meta *in, *out, *channel, *bitdepth, *setting, *bound;
  Meta *ch_out[3];
  _Data *data = calloc(sizeof(_Data), 1);
  filter->fixme_outcount = 3;
  ea_push(filter->data, data);
  
  filter->mode_buffer = filter_mode_buffer_new();
  filter->mode_buffer->worker = &_worker_linear;
  filter->mode_buffer->area_calc = &_area_calc;
  filter->setting_changed = &_setting_changed;
  
  bitdepth = meta_new_data(MT_BITDEPTH, filter, malloc(sizeof(int)));
  *(int*)(bitdepth->data) = BD_U8;
  bitdepth->replace = bitdepth;
  
  out = meta_new(MT_BUNDLE, filter);
  eina_array_push(filter->out, out);
  
  channel = meta_new_channel(filter, 1);
  data->color[0] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(data->color[0]->data) = CS_LAB_L;
  meta_attach(channel, data->color[0]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[0] = channel;
  
  channel = meta_new_channel(filter, 2);
  data->color[1] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(data->color[1]->data) = CS_LAB_A;
  meta_attach(channel, data->color[1]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[1] = channel;
  
  channel = meta_new_channel(filter, 3);
  data->color[2] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(data->color[2]->data) = CS_LAB_B;
  meta_attach(channel, data->color[2]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[2] = channel;
  
  in = meta_new(MT_BUNDLE, filter);
  in->replace = out;
  eina_array_push(filter->in, in);
  
  channel = meta_new_channel(filter, 1);
  data->color[0]->replace = data->color[0];
  channel->replace = ch_out[0];
  meta_attach(channel, data->color[0]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
  
  channel = meta_new_channel(filter, 2);
  data->color[1]->replace = data->color[1];
  channel->replace = ch_out[1];
  meta_attach(channel, data->color[1]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
  
  channel = meta_new_channel(filter, 3);
  data->color[2]->replace = data->color[2];
  channel->replace = ch_out[2];
  meta_attach(channel, data->color[2]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
    
  setting = meta_new_data(MT_INT, filter, &data->colorspace);
  meta_name_set(setting, "colorspace");
  eina_array_push(filter->settings, setting);
  
  bound = meta_new_data(MT_INT, filter, malloc(sizeof(int)));
  *(int*)bound->data = 0;
  meta_name_set(bound, "PARENT_SETTING_MIN");
  meta_attach(setting, bound);
  
  bound = meta_new_data(MT_INT, filter, malloc(sizeof(int)));
  *(int*)bound->data = 1;
  meta_name_set(bound, "PARENT_SETTING_MAX");
  meta_attach(setting, bound);
  
  return filter;
}