Ejemplo n.º 1
0
int main(int argc, char *argv[]) {
	// Read the JPEG file into a buffer
	FILE *fp = fopen(argv[1], "rb");
	if(!fp) { printf("Can't open file.\n"); return -1; }
	fseek(fp, 0, SEEK_END);
	unsigned long fsize = ftell(fp);
	rewind(fp);
	unsigned char *buf = new unsigned char[fsize];
	if(fread(buf, 1, fsize, fp) != fsize) {
		printf("Can't read file.\n");
		return -2;
	}
	fclose(fp);

	// Parse exif
	EXIFInfo result;
	ParseEXIF(buf, fsize, result);

	// Dump whatever information is available
	if(result.cameraModel)
		printf("Camera model      : %s\n", result.cameraModel);
	if(result.cameraMake)
		printf("Camera make       : %s\n", result.cameraMake);
	if(result.focalLength) 
		printf("Lens focal length : %umm\n", result.focalLength);
	if(result.FStop) 
		printf("Lens F-number     : f/%g\n", result.FStop);
	if(result.exposureTime) 
		printf("Exposure          : 1/%gs\n", 1.0/result.exposureTime);
	if(result.imgDescription)
		printf("Image description : %s\n", result.imgDescription);
	if(result.dateTimeModified)
		printf("Date/time modified: %s\n", result.dateTimeModified);
	if(result.dateTimeOriginal)
		printf("Date/time original: %s\n", result.dateTimeOriginal);

	delete[] buf;
	return 0;
}
Ejemplo n.º 2
0
// Loads the next image in the set, deletes the "last image" and
// moves the currently decoded one to last image.
int ISSImages::loadNextImage()
{
	if ( filenames.size() <= 0 )
	{
		printf("ERROR, no files to load\n");
		return -1;
	}

	// Iterate our image safely
	if ( current_image + 1 == filenames.end() )
		current_image = filenames.begin();
	else
		current_image++;

	// Rotate decoded images
	if ( previous_image_surface )
		SDL_FreeSurface(previous_image_surface);
	if ( current_image_surface )
		previous_image_surface = current_image_surface;

	// Begin our load
	std::cout << "Loading image " << *current_image << "...";

	FILE *fp = fopen((*current_image).c_str(), "rb");
	if ( !fp )
	{
		printf("Can't open file.\n");
		return -1;
	}

	// Determine the size of the file for our buffer
	fseek(fp, 0, SEEK_END);
	unsigned long fsize = ftell(fp);
	rewind(fp);

	// Make a memory buffer the size of the image on our heap
	unsigned char *buf = new unsigned char[fsize];

	// Read the file into our buffer
	if ( fread(buf, 1, fsize, fp) != fsize)
	{
		printf("Can't read file.\n");
		return -1;
	}
	fclose(fp);

	// Parse the exif data to get the rotation
	EXIFInfo result;
	ParseEXIF(buf, fsize, result);

	// Create an SDL_RWops since we already have the file loaded, we don't
	// need another buffer with it, we'll load it and create a surface
	// from the buffer already containing the JPEG
	SDL_RWops *file;
	file = SDL_RWFromMem( buf, fsize );
	current_image_surface = IMG_Load_RW( file, 0 );
	SDL_FreeRW(file);

	if ( ! current_image_surface )
	{
		printf("ERROR Loading image!\n");
		return -1;
	}
	delete[] buf;
	printf("done\n");


	// rotate the image if necessary
	// we want to do this before scaling because it will change whether it's
	// scaled to the W or the H to fit our display
	// -----------------------------------------------------------------------------
	int rotation = 0;
	bool mirrored = false;
	switch (result.orientation)
	{
		case 7:
			mirrored = true;
		case 8:
			rotation = 270;
			break;

		case 5:
			mirrored = true;
		case 6:
			rotation = 90;
			break;

		case 4:
			mirrored = true;
		case 3:
			rotation = 180;
			break;

		case 2:
			mirrored = true;
		case 1:
			rotation = 0;
			break;
	}

	if ( mirrored || rotation )
	{
		printf("Rotating image...");
		if ( rotateImage(rotation, mirrored) )
			printf("ERROR Rotating image!\n");
		else
			printf("done\n");
	}

	// scale the image if necessary
	// -----------------------------------------------------------------------------

	int w = current_image_surface->w;
	int h = current_image_surface->h;

	if (w != 800)
	{
		h = (h * 800) / w;
		w = 800;
	}

	if (h > 600)
	{
		w = (w * 600) / h;
		h = 600;
	}

	if ( w != current_image_surface->w || h != current_image_surface->h)
	{
		printf("Scaling image...");
		if ( scaleImage(w, h) )
			printf("ERROR Scaling image!\n");
		else
			printf("done\n");
	}

	// frame the scaled image, if necessary
	// -----------------------------------------------------------------------------

	if ( 800 != current_image_surface->w || 600 != current_image_surface->h)
	{
		printf("Framing image...");
		if ( frameImage(800, 600) )
			printf("ERROR Framing image!\n");
		else
			printf("done\n");
	}

	// return success
	// -----------------------------------------------------------------------------
	return 0;
}
DLGSavePicture::DLGSavePicture(wxWindow* parent, wxImage *img, const wxRect *select, const wxString &filePath, StripeCode &sc, MultiScaleHistogram &mrh, bool newAnimal) : SaveImageDialog(parent) {
	// NOTE: the image frame owns the image, and will destroy it when done
    ifFinalPreview->reset();
	ifFinalPreview->loadImage(img);

    originalPath = filePath;
	stripeCode = sc;
	MRHisto = mrh;
    if (select) {
        ifFinalPreview->setSelectionBox(select);
        sprintf(roi, "%d %d %d %d", select->GetLeft(), select->GetTop(), select->GetWidth(), select->GetHeight());
    } else
        roi[0] = 0;
    txtAnimalID->SetFocus();
	if(!newAnimal) {
		txtAnimalID->SetValue(DLGSavePicture::lastAnimalID);
		txtAge->SetValue(DLGSavePicture::lastAge);
		txtReproductive->SetValue(DLGSavePicture::lastReproductive);
		switch(DLGSavePicture::lastSex) {
			case MALE:
				rbSexMale->SetValue(true);
				break;
			case FEMALE:
				rbSexFemale->SetValue(true);
				break;
			default:
				rbSexUnknown->SetValue(true);
				break;
		}
	}
    txtSightingID->SetValue(DLGSavePicture::lastSighting);
	txtSightingLocation->SetValue(DLGSavePicture::lastSightingLocation);
	txtGPSLat->SetValue(DLGSavePicture::lastGPSLat);
	txtGPSLon->SetValue(DLGSavePicture::lastGPSLon);
	wxString tmp;
	tmp.Printf(_("%d"), DLGSavePicture::lastGroupSize);
	txtGroupSize->SetValue(tmp);
	txtSightingNotes->SetValue(DLGSavePicture::lastNotes);
    switch (lastFlank) {
    case 0:
        rbFlankLeft->SetValue(true);
        break;
    case 1:
        rbFlankRight->SetValue(true);
        break;
    case 2:
        rbFlankFront->SetValue(true);
        break;
    case 3:
        rbFlankRear->SetValue(true);
        break;
    }
    switch (lastPhotoQuality) {
    case 0:
        rbPicBad->SetValue(true);
        break;
    case 1:
        rbPicOK->SetValue(true);
        break;
    case 2:
        rbPicGood->SetValue(true);
        break;
    case 3:
        rbPicBest->SetValue(true);
        break;
    }

    // Get EXIF information from the file
    wxFile file((const wxChar*)filePath, wxFile::read);
    if (file.IsOpened()) {
        wxFileOffset fsize = file.SeekEnd();
        file.Seek(0);
        unsigned char *buf = new unsigned char[fsize];
        if (buf) {
            file.Read(buf, fsize);
            ParseEXIF(buf, fsize, exif);
            exif.breakDownTimestamp();
        }
        delete[] buf;
        file.Close();
    }

    // Set the date/time information for this image
    if (exif.year) {
		wxDateTime tstamp = wxDateTime::Now();
        switch (exif.month) {
        case 1:
            tstamp.SetMonth(wxDateTime::Jan);
            break;
        case 2:
            tstamp.SetMonth(wxDateTime::Feb);
            break;
        case 3:
            tstamp.SetMonth(wxDateTime::Mar);
            break;
        case 4:
            tstamp.SetMonth(wxDateTime::Apr);
            break;
        case 5:
            tstamp.SetMonth(wxDateTime::May);
            break;
        case 6:
            tstamp.SetMonth(wxDateTime::Jun);
            break;
        case 7:
            tstamp.SetMonth(wxDateTime::Jul);
            break;
        case 8:
            tstamp.SetMonth(wxDateTime::Aug);
            break;
        case 9:
            tstamp.SetMonth(wxDateTime::Sep);
            break;
        case 10:
            tstamp.SetMonth(wxDateTime::Oct);
            break;
        case 11:
            tstamp.SetMonth(wxDateTime::Nov);
            break;
        case 12:
            tstamp.SetMonth(wxDateTime::Dec);
            break;
        }
        tstamp.SetDay(exif.day);
        tstamp.SetYear(exif.year);
        calSightDate->SetDate(tstamp);

        // set the time
        spinHour->SetValue(exif.hour);
        spinMin->SetValue(exif.min);

        // save values
        sprintf(sightdate, "%4d-%02d-%02d", exif.year, exif.month, exif.day);
        sprintf(sighttime, "%02d:%02d", exif.hour, exif.min);
        exposure[0] = aperture[0] = focallen[0] = makemodel[0] = 0;
        if(exif.exposureTime)
            sprintf(exposure, "1/%d", (int) (1.0/exif.exposureTime));
        if(exif.FStop)
            sprintf(aperture, "f/%g", exif.FStop);
        if(exif.focalLength)
            sprintf(focallen, "%d", exif.focalLength);
        sprintf(makemodel, "%s %s", exif.cameraMake, exif.cameraModel);
    } else {
        sightdate[0] = sighttime[0] = focallen[0] = aperture[0] = exposure[0] = makemodel[0] = 0;
    }
}