Exemplo n.º 1
0
int R2Image::
Read(const char *filename)
{
  // Initialize everything
  if (pixels) { delete [] pixels; pixels = NULL; }
  width = height = 0;

  // Parse input filename extension
  const char *input_extension;
  if (!(input_extension = strrchr(filename, '.'))) {
    fprintf(stderr, "Input file has no extension (e.g., .jpg).\n");
    return 0;
  }
  
  // Read file of appropriate type
  if (!strncmp(input_extension, ".bmp", 4)) return ReadBMP(filename);
  else if (!strncmp(input_extension, ".ppm", 4)) return ReadPPM(filename);
  else if (!strncmp(input_extension, ".pfm", 4)) return ReadPFM(filename);
  else if (!strncmp(input_extension, ".jpg", 4)) return ReadJPEG(filename);
  else if (!strncmp(input_extension, ".jpeg", 5)) return ReadJPEG(filename);
  else if (!strncmp(input_extension, ".tif", 4)) return ReadTIFF(filename);
  else if (!strncmp(input_extension, ".tiff", 5)) return ReadTIFF(filename);
  else if (!strncmp(input_extension, ".raw", 4)) return ReadRAW(filename);
  else if (!strncmp(input_extension, ".grd", 4)) return ReadGRD(filename);
  
  // Should never get here
  fprintf(stderr, "Unrecognized image file extension");
  return 0;
}
Exemplo n.º 2
0
Arquivo: azura.cpp Projeto: kyuu/azura
    //--------------------------------------------------------------
    Image::Ptr ReadImage(File* file, FileFormat::Enum ff, PixelFormat::Enum pf)
    {
        if (!file || (pf != PixelFormat::DontCare && pf < 0)) {
            return 0;
        }

        Image::Ptr image;

        switch (ff)
        {
            case FileFormat::BMP:
            {
                image = ReadBMP(file);
                break;
            }
            case FileFormat::PNG:
            {
                image = ReadPNG(file);
                break;
            }
            case FileFormat::JPEG:
            {
                image = ReadJPEG(file);
                break;
            }
            case FileFormat::AutoDetect:
            {
                int initial_pos = file->tell();

                // try reading as BMP
                image = ReadBMP(file);
                if (image) {
                    break;
                }

                file->seek(initial_pos);

                // try reading as PNG
                image = ReadPNG(file);
                if (image) {
                    break;
                }

                file->seek(initial_pos);

                // try reading as JPEG
                image = ReadJPEG(file);

                break;
            }
            default:
                return 0;
        }

        if (image && pf != PixelFormat::DontCare && image->getPixelFormat() != pf) {
            image = image->convert(pf);
        }

        return image;
    }
Exemplo n.º 3
0
static int ReadPicture(const char* const filename, WebPPicture* const pic,
                       int keep_alpha, Metadata* const metadata) {
  int ok = 0;
  FILE* in_file = fopen(filename, "rb");
  if (in_file == NULL) {
    fprintf(stderr, "Error! Cannot open input file '%s'\n", filename);
    return ok;
  }

  if (pic->width == 0 || pic->height == 0) {
    // If no size specified, try to decode it as PNG/JPEG (as appropriate).
    const InputFileFormat format = GetImageType(in_file);
    if (format == PNG_) {
      ok = ReadPNG(in_file, pic, keep_alpha, metadata);
    } else if (format == JPEG_) {
      ok = ReadJPEG(in_file, pic, metadata);
    } else if (format == TIFF_) {
      ok = ReadTIFF(filename, pic, keep_alpha, metadata);
    } else if (format == WEBP_) {
      ok = ReadWebP(filename, pic, keep_alpha, metadata);
    }
  } else {
    // If image size is specified, infer it as YUV format.
    ok = ReadYUV(in_file, pic);
  }
  if (!ok) {
    fprintf(stderr, "Error! Could not process file %s\n", filename);
  }

  fclose(in_file);
  return ok;
}
Exemplo n.º 4
0
int jpegtest()
{
	char *infilename = (char*) "test.jpg", *outfilename = (char*) "test_out.jpg";

	/* Try opening a jpeg*/
	if( ReadJPEG( infilename , 0  , 0 ) > 0 )
	{
		/* then copy it to another file */
		if( WriteJPEGFile( 0 , outfilename ) < 0 ) return -1;
	}
	else return -1;
	return 0;
}
Exemplo n.º 5
0
LDraw::Bitmap* BitmapLoader::Load(IO::ISequentialByteStream* stream)
{
	int n;
	for (n = 0; n < 5; n++)
	{
		int ret = -1;

		switch (n)
		{
		case 0:
			{
				ret = ReadJPEG(this, stream);
			}
			break;

		case 1:
			{
				ret = ReadGIF(this, stream);
			}
			break;

		case 2:
			{
				ret = ReadPNG(this, stream);
			}
			break;

		case 3:
			{
				ret = ReadBMP(this, stream);
			}
			break;

		case 4:
			{
				ret = ReadTGA(this, stream);
			}
			break;
		}

		if (ret == 0)
			break;

		stream->Seek(0, System::IO::STREAM_SEEK_SET);
	}

	return m_bitmap;
}
Exemplo n.º 6
0
/**
 * Read a image file into the DIB.  This method will check to see if the
 * file is a BMP or JPEG and call the appropriate reader.
 */
bool vtDIB::Read(const char *fname, bool progress_callback(int))
{
	FILE *fp = vtFileOpen(fname, "rb");
	if (!fp)
		return false;
	uchar buf[2];
	if (fread(buf, 2, 1, fp) != 1)
		return false;
	fclose(fp);
	if (buf[0] == 0x42 && buf[1] == 0x4d)
		return ReadBMP(fname, progress_callback);
	else if (buf[0] == 0xFF && buf[1] == 0xD8)
		return ReadJPEG(fname, progress_callback);
	else if (buf[0] == 0x89 && buf[1] == 0x50)
		return ReadPNG(fname, progress_callback);
	return false;
}