Esempio n. 1
0
void ShiftImageTimesDialog::syncCameraClicked()
{
	struct memblock mem;
	EXIFInfo exiv;
	int retval;
	QPixmap picture;
	QDateTime dcDateTime = QDateTime();
	QStringList fileNames = QFileDialog::getOpenFileNames(this,
							      tr("Open image file"),
							      DiveListView::lastUsedImageDir(),
							      tr("Image files (*.jpg *.jpeg *.pnm *.tif *.tiff)"));
	if (fileNames.isEmpty())
		return;

	picture.load(fileNames.at(0));
	ui.displayDC->setEnabled(true);
	QGraphicsScene *scene = new QGraphicsScene(this);

	scene->addPixmap(picture.scaled(ui.DCImage->size()));
	ui.DCImage->setScene(scene);
	if (readfile(fileNames.at(0).toUtf8().data(), &mem) <= 0)
		return;
	retval = exiv.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
	free(mem.buffer);
	if (retval != PARSE_EXIF_SUCCESS)
		return;
	dcImageEpoch = exiv.epoch();
	dcDateTime.setTime_t(dcImageEpoch);
	ui.dcTime->setDateTime(dcDateTime);
	connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &)));
}
Esempio n. 2
0
extern "C" timestamp_t picture_get_timestamp(char *filename)
{
	EXIFInfo exif;
	memblock mem;
	int retval;

	// filename might not be the actual filename, so let's go via the hash.
	if (readfile(localFilePath(QString(filename)).toUtf8().data(), &mem) <= 0)
		return 0;
	retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
	free(mem.buffer);
	if (retval != PARSE_EXIF_SUCCESS)
		return 0;
	return exif.epoch();
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Usage: demo <JPEG file>\n");
    return -1;
  }

  // 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");
    delete[] buf;
    return -2;
  }
  fclose(fp);

  // Parse EXIF
  EXIFInfo result;
  int code = result.parseFrom(buf, fsize);
  delete[] buf;
  if (code) {
    printf("Error parsing EXIF: code %d\n", code);
    return -3;
  }

  // Dump EXIF information
  printf("Camera make       : %s\n", result.Make.c_str());
  printf("Camera model      : %s\n", result.Model.c_str());
  printf("Software          : %s\n", result.Software.c_str());
  printf("Bits per sample   : %d\n", result.BitsPerSample);
  printf("Image width       : %d\n", result.ImageWidth);
  printf("Image height      : %d\n", result.ImageHeight);
  printf("Image description : %s\n", result.ImageDescription.c_str());
  printf("Image orientation : %d\n", result.Orientation);
  printf("Image copyright   : %s\n", result.Copyright.c_str());
  printf("Image date/time   : %s\n", result.DateTime.c_str());
  printf("Original date/time: %s\n", result.DateTimeOriginal.c_str());
  printf("Digitize date/time: %s\n", result.DateTimeDigitized.c_str());
  printf("Subsecond time    : %s\n", result.SubSecTimeOriginal.c_str());
  printf("Exposure time     : 1/%d s\n", (unsigned) (1.0/result.ExposureTime));
  printf("F-stop            : f/%.1f\n", result.FNumber);
  printf("ISO speed         : %d\n", result.ISOSpeedRatings);
  printf("Subject distance  : %f m\n", result.SubjectDistance);
  printf("Exposure bias     : %f EV\n", result.ExposureBiasValue);
  printf("Flash used?       : %d\n", result.Flash);
  printf("Metering mode     : %d\n", result.MeteringMode);
  printf("Lens focal length : %f mm\n", result.FocalLength);
  printf("35mm focal length : %u mm\n", result.FocalLengthIn35mm);
  printf("GPS Latitude      : %f deg (%f deg, %f min, %f sec %c)\n", 
          result.GeoLocation.Latitude,
          result.GeoLocation.LatComponents.degrees,
          result.GeoLocation.LatComponents.minutes,
          result.GeoLocation.LatComponents.seconds,
          result.GeoLocation.LatComponents.direction);
  printf("GPS Longitude     : %f deg (%f deg, %f min, %f sec %c)\n", 
          result.GeoLocation.Longitude,
          result.GeoLocation.LonComponents.degrees,
          result.GeoLocation.LonComponents.minutes,
          result.GeoLocation.LonComponents.seconds,
          result.GeoLocation.LonComponents.direction);
  printf("GPS Altitude      : %f m\n", result.GeoLocation.Altitude);

  return 0;
}
Esempio n. 4
0
result_t Image::load(Buffer_base *data)
{
    std::string strBuf;
    data->toString(strBuf);

    if (strBuf.length() < 2)
        return CHECK_ERROR(CALL_E_INVALIDARG);

    int32_t format;
    unsigned char ch1 = (unsigned char) strBuf[0];
    unsigned char ch2 = (unsigned char) strBuf[1];

    if (ch1 == 0x47 && ch2 == 0x49)
        format = gd_base::_GIF;
    else if (ch1 == 0x89 && ch2 == 0x50)
        format = gd_base::_PNG;
    else if (ch1 == 0xff && ch2 == 0xd8)
        format = gd_base::_JPEG;
    else if ((ch1 == 0x49 && ch2 == 0x49) || (ch1 == 0x4d && ch2 == 0x4d))
        format = gd_base::_TIFF;
    else if (ch1 == 0x42 && ch2 == 0x4d)
        format = gd_base::_BMP;
    else if (ch1 == 0x52 && ch2 == 0x49)
        format = gd_base::_WEBP;
    else
        return CHECK_ERROR(CALL_E_INVALID_DATA);

    switch (format)
    {
    case gd_base::_GIF:
        m_image = gdImageCreateFromGifPtr((int32_t) strBuf.length(),
                                          (void *) strBuf.c_str());
        break;
    case gd_base::_PNG:
        m_image = gdImageCreateFromPngPtr((int32_t) strBuf.length(),
                                          (void *) strBuf.c_str());
        break;
    case gd_base::_JPEG:
        m_image = gdImageCreateFromJpegPtr((int32_t) strBuf.length(),
                                           (void *) strBuf.c_str());
        if (m_image != NULL)
        {
            EXIFInfo result;
            result.parseFrom((const unsigned char *) strBuf.c_str(),
                             (uint32_t)strBuf.length());

            switch (result.Orientation)
            {
            case 2:
                gdImageFlipHorizontal(m_image);
                break;
            case 3:
                gdImageFlipBoth(m_image);
                break;
            case 4:
                gdImageFlipVertical(m_image);
                break;
            case 5:
                gdImageFlipVertical(m_image);
            case 6:
                rotate(gd_base::_RIGHT);
                break;
            case 7:
                gdImageFlipVertical(m_image);
            case 8:
                rotate(gd_base::_LEFT);
                break;
            }
        }

        break;
    case gd_base::_TIFF:
        m_image = gdImageCreateFromTiffPtr((int32_t) strBuf.length(),
                                           (void *) strBuf.c_str());
        break;
    case gd_base::_BMP:
        m_image = gdImageCreateFromBmpPtr((int32_t) strBuf.length(),
                                          (void *) strBuf.c_str());
        break;
    case gd_base::_WEBP:
        m_image = gdImageCreateFromWebpPtr((int32_t) strBuf.length(),
                                           (void *) strBuf.c_str());
        break;
    }

    if (m_image == NULL)
        return CHECK_ERROR(CALL_E_INVALIDARG);

    setExtMemory();
    m_type = format;

    return 0;
}