void test1() {
  int p1fd, p1pfd, err1;

  unsigned char key[KEY_LENGTH];
  int i;
  for (i = 0; i < KEY_LENGTH; ++i)
    key[i] = (unsigned char) 10;
  pyramid *p1 = pyramid_open("../access_file/bestoftimes.txt", O_RDWR, &p1fd, &p1pfd, &err1, key);
  if (!p1) {
    printf("pyramid open returned NULL\nerr=%d\n", err1);
    return;
  }

  pyramid *this = p1;
  while (this) {
    for (i = 0; i < how_many_ids(this); ++i) {
      printf("%ld\t", this->identifiers[i]);
    }
    putchar(10);
    this = this->next_level;
  }

  int closeret = pyramid_close(p1fd, p1);
  if (closeret) {
    printf("pyramid close failed; returned %d\n", closeret);
    pyramid_free(p1);
    return;
  }

  printf("test1 passed\n");
  pyramid_free(p1);
  return;
}
void closeit(int file_fd, pyramid* p, int i) {
  int closeret = pyramid_close(file_fd, p);
  if (closeret) {
    printf("test2: close %d failed; returned %d\n", i, closeret);
  }
  pyramid_free(p);
}
Ejemplo n.º 3
0
/* Free an entire pyramid.
 */
static void
pyramid_free( Layer *layer )
{
	if( layer->below ) 
		pyramid_free( layer->below );

	layer_free( layer );
}
Ejemplo n.º 4
0
// transform gradients to luminance
static void transform_to_luminance(pyramid_t* pp, float* const x, pfstmo_progress_callback progress_cb, const bool bcg, const int itmax, const float tol)
{
  pyramid_t* pC = pyramid_allocate(pp->cols, pp->rows);
  pyramid_calculate_scale_factor(pp, pC); // calculate (Cx,Cy)
  pyramid_scale_gradient(pp, pC); // scale small gradients by (Cx,Cy);

  float* b = matrix_alloc(pp->cols * pp->rows);
  pyramid_calculate_divergence_sum(pp, b); // calculate the sum of divergences (equal to b)
  
  // calculate luminances from gradients
  if (bcg)
    linbcg(pp, pC, b, x, itmax, tol, progress_cb);
  else
    lincg(pp, pC, b, x, itmax, tol, progress_cb);
  
  matrix_free(b);
  pyramid_free(pC);
}
Ejemplo n.º 5
0
// tone mapping
int tmo_mantiuk06_contmap(const int c, const int r, float* const R, float* const G, float* const B, float* const Y, const float contrastFactor, const float saturationFactor, const bool bcg, const int itmax, const float tol, pfstmo_progress_callback progress_cb)
{
  
  const int n = c*r;
  
  /* Normalize */
  float Ymax = Y[0];
  for (int j = 1; j < n; j++)
    if (Y[j] > Ymax)
      Ymax = Y[j];

  const float clip_min = 1e-7f*Ymax;
#pragma omp parallel for schedule(static)
  for (int j = 0; j < n; j++)
    {
      if( unlikely(R[j] < clip_min) ) R[j] = clip_min;
      if( unlikely(G[j] < clip_min) ) G[j] = clip_min;
      if( unlikely(B[j] < clip_min) ) B[j] = clip_min;
      if( unlikely(Y[j] < clip_min) ) Y[j] = clip_min;    
    }
	
#pragma omp parallel for schedule(static)
  for(int j=0;j<n;j++)
    {
      R[j] /= Y[j];
      G[j] /= Y[j];
      B[j] /= Y[j];
      Y[j] = log10f(Y[j]);
    }
	
  pyramid_t* pp = pyramid_allocate(c,r); // create pyramid
  float* tY = matrix_alloc(n);
  matrix_copy(n, Y, tY); // copy Y to tY
  pyramid_calculate_gradient(pp,tY); // calculate gradients for pyramid, destroys tY
  matrix_free(tY);
  pyramid_transform_to_R(pp); // transform gradients to R

  /* Contrast map */
  if( contrastFactor > 0.0f )
    pyramid_gradient_multiply(pp, contrastFactor); // Contrast mapping
  else
    contrast_equalization(pp, -contrastFactor); // Contrast equalization
	
  pyramid_transform_to_G(pp); // transform R to gradients
  transform_to_luminance(pp, Y, progress_cb, bcg, itmax, tol); // transform gradients to luminance Y
  pyramid_free(pp);

  /* Renormalize luminance */
  float* temp = matrix_alloc(n);
	
  matrix_copy(n, Y, temp); // copy Y to temp
  qsort(temp, n, sizeof(float), sort_float); // sort temp in ascending order
	
  // const float median = (temp[(int)((n-1)/2)] + temp[(int)((n-1)/2+1)]) * 0.5f; // calculate median
  const float CUT_MARGIN = 0.1f;
	
  float trim = (n-1) * CUT_MARGIN * 0.01f;
  float delta = trim - floorf(trim);
  const float l_min = temp[(int)floorf(trim)] * delta + temp[(int)ceilf(trim)] * (1.0f-delta);	

  trim = (n-1) * (100.0f - CUT_MARGIN) * 0.01f;
  delta = trim - floorf(trim);
  const float l_max = temp[(int)floorf(trim)] * delta + temp[(int)ceilf(trim)] * (1.0f-delta);	
	
  matrix_free(temp);
	
  const float disp_dyn_range = 2.3f;
#pragma omp parallel for schedule(static)
  for(int j=0;j<n;j++)
    Y[j] = (Y[j] - l_min) / (l_max - l_min) * disp_dyn_range - disp_dyn_range; // x scaled
                                                                               // 
  /* Transform to linear scale RGB */
#pragma omp parallel for schedule(static)
  for(int j=0;j<n;j++)
    {
      Y[j] = powf(10,Y[j]);
      R[j] = powf( R[j], saturationFactor) * Y[j];
      G[j] = powf( G[j], saturationFactor) * Y[j];
      B[j] = powf( B[j], saturationFactor) * Y[j];
    }

  return PFSTMO_OK;
}
Ejemplo n.º 6
0
int 
vips__tiff_write( VipsImage *in, const char *filename, 
	VipsForeignTiffCompression compression, int Q, 
	VipsForeignTiffPredictor predictor,
	char *profile,
	gboolean tile, int tile_width, int tile_height,
	gboolean pyramid,
	gboolean squash,
	gboolean miniswhite,
	VipsForeignTiffResunit resunit, double xres, double yres,
	gboolean bigtiff,
	gboolean rgbjpeg,
	gboolean properties, gboolean strip )
{
	Write *write;

#ifdef DEBUG
	printf( "tiff2vips: libtiff version is \"%s\"\n", TIFFGetVersion() );
#endif /*DEBUG*/

	vips__tiff_init();

	if( vips_check_coding_known( "vips2tiff", in ) )
		return( -1 );

	/* Make output image. 
	 */
	if( !(write = write_new( in, filename,
		compression, Q, predictor, profile,
		tile, tile_width, tile_height, pyramid, squash,
		miniswhite, resunit, xres, yres, bigtiff, rgbjpeg, 
		properties, strip )) )
		return( -1 );

	if( vips_sink_disc( write->im, write_strip, write ) ) {
		write_free( write );
		return( -1 );
	}

	if( !TIFFWriteDirectory( write->layer->tif ) ) 
		return( -1 );

	if( write->pyramid ) { 
		/* Free lower pyramid resources ... this will TIFFClose() (but
		 * not delete) the smaller layers ready for us to read from 
		 * them again.
		 */
		if( write->layer->below )
			pyramid_free( write->layer->below );

		/* Append smaller layers to the main file.
		 */
		if( write_gather( write ) ) {
			write_free( write );
			return( -1 );
		}
	}

	write_free( write );

	return( 0 );
}