Пример #1
0
	bool Image::load_dds( const char* filename )
	{
		FileIn fi(filename);
		if( fi.valid() )
		{			
			return read_dds(fi);
		}
		else
		{	
            Log::error("File not found: '%s'", filename);
			return false;
		}
	}
Пример #2
0
static void
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
{
  static GimpParam  values[2];
  GimpRunMode       run_mode;
  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
  gint32            imageID;
  gint32            drawableID;
  GimpExportReturn  export = GIMP_EXPORT_CANCEL;

  gegl_init (NULL, NULL);

  run_mode = param[0].data.d_int32;

  *nreturn_vals = 1;
  *return_vals = values;

  values[0].type = GIMP_PDB_STATUS;
  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;

  if (!strcmp (name, LOAD_PROC))
    {
      switch (run_mode)
        {
        case GIMP_RUN_INTERACTIVE:
          gimp_ui_init ("dds", 0);
          gimp_get_data (LOAD_PROC, &dds_read_vals);
          break;
        case GIMP_RUN_NONINTERACTIVE:
          dds_read_vals.mipmaps = param[3].data.d_int32;
          dds_read_vals.decode_images = param[4].data.d_int32;
          if (nparams != G_N_ELEMENTS (load_args))
            status = GIMP_PDB_CALLING_ERROR;
          break;
        default:
          break;
        }

      if (status == GIMP_PDB_SUCCESS)
        {
          status = read_dds (param[1].data.d_string, &imageID,
                             run_mode == GIMP_RUN_INTERACTIVE);
          if (status == GIMP_PDB_SUCCESS && imageID != -1)
            {
              *nreturn_vals = 2;
              values[1].type = GIMP_PDB_IMAGE;
              values[1].data.d_image = imageID;
              if (run_mode == GIMP_RUN_INTERACTIVE)
                gimp_set_data (LOAD_PROC, &dds_read_vals, sizeof (dds_read_vals));
            }
          else if (status != GIMP_PDB_CANCEL)
            status = GIMP_PDB_EXECUTION_ERROR;
        }
    }
  else if (!strcmp (name, SAVE_PROC))
    {
      imageID = param[1].data.d_int32;
      drawableID = param[2].data.d_int32;

      switch (run_mode)
        {
        case GIMP_RUN_INTERACTIVE:
        case GIMP_RUN_WITH_LAST_VALS:
          gimp_ui_init ("dds", 0);
          export = gimp_export_image (&imageID, &drawableID, "DDS",
                                     (GIMP_EXPORT_CAN_HANDLE_RGB |
                                      GIMP_EXPORT_CAN_HANDLE_GRAY |
                                      GIMP_EXPORT_CAN_HANDLE_INDEXED |
                                      GIMP_EXPORT_CAN_HANDLE_ALPHA |
                                      GIMP_EXPORT_CAN_HANDLE_LAYERS));
          if (export == GIMP_EXPORT_CANCEL)
            {
              values[0].data.d_status = GIMP_PDB_CANCEL;
              return;
            }
        default:
          break;
        }
Пример #3
0
Uint32 load_dds(el_file_ptr file, const Uint32 compression,
	const Uint32 unpack, const Uint32 strip_mipmaps, Uint32 base_level,
	image_t* image)
{
	DdsHeader header;
	Uint32 format_unpack, mipmap_count, start_mipmap;

	if (file == 0)
	{
		return 0;
	}

	if (init_dds_image(file, &header) != 0)
	{
		start_mipmap = min2u(base_level, header.m_mipmap_count - 1);

		if (strip_mipmaps != 0)
		{
			mipmap_count = 1;
		}
		else
		{
			mipmap_count = header.m_mipmap_count - start_mipmap;
		}

		assert(mipmap_count > 0);
		assert(start_mipmap < header.m_mipmap_count);
		assert(mipmap_count <= header.m_mipmap_count);

		image->width = max2u(header.m_width >> start_mipmap, 1);
		image->height = max2u(header.m_height >> start_mipmap, 1);
		image->mipmaps = mipmap_count;
		image->format = detect_dds_file_format(&header, &image->alpha,
			&format_unpack);

		if (decompression_needed(&header, compression, unpack) == 1)
		{
			image->image = decompress_dds(file, &header,
				strip_mipmaps, start_mipmap);
			image->format = ift_rgba8;

			get_dds_sizes_and_offsets(&header, 1, 1,
				strip_mipmaps, start_mipmap, image);
		}
		else
		{
			if ((unpack != 0) || (format_unpack != 0))
			{
				image->image = unpack_dds(file, &header,
					strip_mipmaps, start_mipmap);
				image->format = ift_rgba8;

				get_dds_sizes_and_offsets(&header, 0, 1,
					strip_mipmaps, start_mipmap, image);
			}
			else
			{
				image->image = read_dds(file, &header,
					strip_mipmaps, start_mipmap);

				get_dds_sizes_and_offsets(&header, 0, 0,
					strip_mipmaps, start_mipmap, image);
			}
		}

		assert(image->width > 0);
		assert(image->width > 0);
		assert(image->sizes[0] > 0);
		assert(image->width > 0);
		assert(image->height > 0);
		assert(image->mipmaps > 0);

		if (image->image != 0)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}