void WorkerPersistentArrayManager::save_marked_arrays(Interpreter* runner) {
		ArrayIdLabelMap::iterator it;
		for (it = persistent_array_map_.begin();
				it != persistent_array_map_.end(); ++it) {
			int array_id = it->first;
			int string_slot = it->second;
			//DEBUG
			SIP_LOG(std::cout << "\nsave marked: array= " << runner->array_name(array_id) << ", label=" << runner->string_literal(string_slot) << std::endl);
			const std::string label = runner->sip_tables().string_literal(string_slot);
			if (runner->sip_tables().is_scalar(array_id)) {
				double value = runner->scalar_value(array_id);
				SIP_LOG(std::cout << "saving scalar with label " << label << " value is " << value << std::endl);
				save_scalar(label, value);
			} else if (runner->sip_tables().is_contiguous(array_id)) {
				Block* contiguous_array = runner->get_and_remove_contiguous_array(array_id);
				SIP_LOG(std::cout << "saving contiguous array with label  "<<  label << " with contents "<< std::endl << *contiguous_array << std::endl);
				save_contiguous(label, contiguous_array);
			} else {
				//in parallel implementation, there won't be any of these on worker.
				IdBlockMap<Block>::PerArrayMap* per_array_map = runner->get_and_remove_per_array_map(array_id);
				SIP_LOG(std::cout << " saving distributed array  with label " << label << " and map with " << per_array_map->size() << " blocks" << std::endl);
				save_distributed(label, per_array_map);
			}
		}
		persistent_array_map_.clear();
	}
Ejemplo n.º 2
0
static int
export_tiff (GeglOperation *operation,
             GeglBuffer *input,
             const GeglRectangle *result)
{
  GeglProperties *o = GEGL_PROPERTIES(operation);
  Priv *p = (Priv*) o->user_data;
  gshort color_space, compression = COMPRESSION_NONE;
  gushort bits_per_sample, samples_per_pixel;
  gboolean has_alpha, alpha_is_premultiplied = FALSE;
  gushort sample_format, predictor = 0;
  gushort extra_types[1];
  glong rows_per_stripe = 1;
  gint bytes_per_row;
  const Babl *type, *model;
  gchar format_string[32];
  const Babl *format;

  g_return_val_if_fail(p->tiff != NULL, -1);

  TIFFSetField(p->tiff, TIFFTAG_SUBFILETYPE, 0);
  TIFFSetField(p->tiff, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);

  TIFFSetField(p->tiff, TIFFTAG_IMAGEWIDTH, result->width);
  TIFFSetField(p->tiff, TIFFTAG_IMAGELENGTH, result->height);

  format = gegl_buffer_get_format(input);

  model = babl_format_get_model(format);
  type = babl_format_get_type(format, 0);

  if (model == babl_model("Y") || model == babl_model("Y'"))
    {
      has_alpha = FALSE;
      color_space = PHOTOMETRIC_MINISBLACK;
      model = babl_model("Y'");
      samples_per_pixel = 1;
    }
  else if (model == babl_model("YA") || model == babl_model("Y'A"))
    {
      has_alpha = TRUE;
      alpha_is_premultiplied = FALSE;
      color_space = PHOTOMETRIC_MINISBLACK;
      model = babl_model("Y'A");
      samples_per_pixel = 2;
    }
  else if (model == babl_model("YaA") || model == babl_model("Y'aA"))
    {
      has_alpha = TRUE;
      alpha_is_premultiplied = TRUE;
      color_space = PHOTOMETRIC_MINISBLACK;
      model = babl_model("Y'aA");
      samples_per_pixel = 2;
    }
  else if (model == babl_model("RGB") || model == babl_model("R'G'B'"))
    {
      has_alpha = FALSE;
      color_space = PHOTOMETRIC_RGB;
      model = babl_model("R'G'B'");
      samples_per_pixel = 3;
      predictor = 2;
    }
  else if (model == babl_model("RGBA") || model == babl_model("R'G'B'A"))
    {
      has_alpha = TRUE;
      alpha_is_premultiplied = FALSE;
      color_space = PHOTOMETRIC_RGB;
      model = babl_model("R'G'B'A");
      samples_per_pixel = 4;
      predictor = 2;
    }
  else if (model == babl_model("RaGaBaA") || model == babl_model("R'aG'aB'aA"))
    {
      has_alpha = TRUE;
      alpha_is_premultiplied = TRUE;
      color_space = PHOTOMETRIC_RGB;
      model = babl_model("R'aG'aB'aA");
      samples_per_pixel = 4;
      predictor = 2;
    }
  else
    {
      g_warning("color space not supported: %s", babl_get_name(model));

      has_alpha = TRUE;
      alpha_is_premultiplied = TRUE;
      color_space = PHOTOMETRIC_RGB;
      model = babl_model("R'aG'aB'aA");
      samples_per_pixel = 4;
      predictor = 2;
    }

  TIFFSetField(p->tiff, TIFFTAG_PHOTOMETRIC, color_space);
  TIFFSetField(p->tiff, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel);
  TIFFSetField(p->tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);

  if (has_alpha)
    {
      if (alpha_is_premultiplied)
        extra_types[0] = EXTRASAMPLE_ASSOCALPHA;
      else
        extra_types[0] = EXTRASAMPLE_UNASSALPHA;

      TIFFSetField(p->tiff, TIFFTAG_EXTRASAMPLES, 1, extra_types);
    }

  if (predictor != 0)
    {
      if (compression == COMPRESSION_LZW)
        TIFFSetField(p->tiff, TIFFTAG_PREDICTOR, predictor);
      else if (compression == COMPRESSION_ADOBE_DEFLATE)
        TIFFSetField(p->tiff, TIFFTAG_PREDICTOR, predictor);
    }

  if (type == babl_type("u8"))
    {
      sample_format = SAMPLEFORMAT_UINT;
      bits_per_sample = 8;
    }
  else if (type == babl_type("half"))
    {
      sample_format = SAMPLEFORMAT_IEEEFP;
      bits_per_sample = 16;
    }
  else if (type == babl_type("u16"))
    {
      sample_format = SAMPLEFORMAT_UINT;
      bits_per_sample = 16;
    }
  else if (type == babl_type("float"))
    {
      sample_format = SAMPLEFORMAT_IEEEFP;
      bits_per_sample = 32;
    }
  else if (type == babl_type("u32"))
    {
      sample_format = SAMPLEFORMAT_UINT;
      bits_per_sample = 32;
    }
  else  if (type == babl_type("double"))
    {
      sample_format = SAMPLEFORMAT_IEEEFP;
      bits_per_sample = 64;
    }
  else
    {
      g_warning("sample format not supported: %s", babl_get_name(type));

      sample_format = SAMPLEFORMAT_UINT;
      type = babl_type("u8");
      bits_per_sample = 8;
    }

  TIFFSetField(p->tiff, TIFFTAG_BITSPERSAMPLE, bits_per_sample);
  TIFFSetField(p->tiff, TIFFTAG_SAMPLEFORMAT, sample_format);

  TIFFSetField(p->tiff, TIFFTAG_COMPRESSION, compression);

  if ((compression == COMPRESSION_CCITTFAX3 ||
       compression == COMPRESSION_CCITTFAX4) &&
       (bits_per_sample != 1 || samples_per_pixel != 1))
    {
      g_critical("only monochrome pictures can be compressed "
                 "with \"CCITT Group 4\" or \"CCITT Group 3\"");
      return -1;
    }

  g_snprintf(format_string, 32, "%s %s",
             babl_get_name(model), babl_get_name(type));

  format = babl_format(format_string);

  /* "Choose RowsPerStrip such that each strip is about 8K bytes." */
  bytes_per_row = babl_format_get_bytes_per_pixel(format) * result->width;
  while (bytes_per_row * rows_per_stripe <= 8192)
    rows_per_stripe++;

  rows_per_stripe = MIN(rows_per_stripe, result->height);

  TIFFSetField(p->tiff, TIFFTAG_ROWSPERSTRIP, rows_per_stripe);

  return save_contiguous(operation, input, result, format);
}