mirror of
https://github.com/vanitasvitae/Spherical
synced 2024-11-21 20:02:06 +01:00
Add PhotoSphereMetadata and parser
This commit is contained in:
parent
c74c40dc7c
commit
55fda0364a
3 changed files with 322 additions and 11 deletions
|
@ -12,6 +12,7 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import de.trac.spherical.parser.PhotoSphereMetadata;
|
||||
import de.trac.spherical.parser.SphereParser;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
@ -82,14 +83,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
try {
|
||||
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||
String xml = SphereParser.getXMLContent(inputStream);
|
||||
PhotoSphereMetadata metadata = SphereParser.parse(xml);
|
||||
|
||||
boolean sphere = true; //TODO: parser.
|
||||
|
||||
if (sphere) {
|
||||
if (metadata.isUsePanoramaViewer()) {
|
||||
displayPhotoSphere(uri);
|
||||
} else {
|
||||
displayFlatImage(uri);
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
|
@ -105,12 +106,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
try {
|
||||
InputStream inputStream = getContentResolver().openInputStream(uri);
|
||||
String xml = SphereParser.getXMLContent(inputStream);
|
||||
PhotoSphereMetadata metadata = SphereParser.parse(xml);
|
||||
|
||||
if (xml != null) {
|
||||
text.setText(xml);
|
||||
} else {
|
||||
text.setText("null");
|
||||
}
|
||||
displayPhotoSphere(getContentResolver().openInputStream(uri), metadata);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(TAG, "File not found.", e);
|
||||
|
@ -121,6 +119,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void displayPhotoSphere(InputStream inputStream, PhotoSphereMetadata metadata) {
|
||||
//Please fill me!
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a flat image.
|
||||
* @param uri
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.trac.spherical.parser;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 12.09.17.
|
||||
*/
|
||||
|
@ -28,4 +30,210 @@ public class PhotoSphereMetadata {
|
|||
public static final String CROPPED_AREA_LEFT_PIXELS = "GPano:CroppedAreaLeftPixels";
|
||||
public static final String CROPPED_AREA_TOP_PIXELS = "GPano:CroppedAreaTopPixels";
|
||||
public static final String INITIAL_CAMERA_DOLLY = "GPano:InitialCameraDolly";
|
||||
|
||||
private static final String pf = "=\"";
|
||||
|
||||
enum TYPE {
|
||||
equirectangular
|
||||
}
|
||||
|
||||
private boolean usePanoramaViewer = true;
|
||||
private String captureSoftware = null;
|
||||
private String stitichingSoftware = null;
|
||||
private TYPE projectionType = TYPE.equirectangular;
|
||||
private Float poseHeadingDegrees = null;
|
||||
private float posePitchDegrees = 0;
|
||||
private float poseRollDegrees = 0;
|
||||
private int initialViewHeadingDegrees = 0;
|
||||
private int initialViewPitchDegrees = 0;
|
||||
private int initialViewRollDegrees = 0;
|
||||
private Float initialHorizontalFOVDegrees = null;
|
||||
private Date firstPhotoDate = null;
|
||||
private Date lastPhotoDate = null;
|
||||
private Integer sourcePhotosCount = null;
|
||||
private boolean exposureLockUsed = false;
|
||||
private Integer croppedAreaImageWidthPixels = null;
|
||||
private Integer croppedAreaImageHeightPixels = null;
|
||||
private Integer fullPanoWidthPixels = null;
|
||||
private Integer fullPanoHeightPixels = null;
|
||||
private Integer croppedAreaLeftPixels = null;
|
||||
private Integer croppedAreaTopPixels = null;
|
||||
private float initialCameraDolly = 0;
|
||||
|
||||
public void setUsePanoramaViewer(boolean usePanoramaViewer) {
|
||||
this.usePanoramaViewer = usePanoramaViewer;
|
||||
}
|
||||
|
||||
public void setCaptureSoftware(String captureSoftware) {
|
||||
this.captureSoftware = captureSoftware;
|
||||
}
|
||||
|
||||
public void setStitichingSoftware(String stitichingSoftware) {
|
||||
this.stitichingSoftware = stitichingSoftware;
|
||||
}
|
||||
|
||||
public void setProjectionType(TYPE projectionType) {
|
||||
this.projectionType = projectionType;
|
||||
}
|
||||
|
||||
public void setPoseHeadingDegrees(Float poseHeadingDegrees) {
|
||||
this.poseHeadingDegrees = poseHeadingDegrees;
|
||||
}
|
||||
|
||||
public void setPosePitchDegrees(float posePitchDegrees) {
|
||||
this.posePitchDegrees = posePitchDegrees;
|
||||
}
|
||||
|
||||
public void setPoseRollDegrees(float poseRollDegrees) {
|
||||
this.poseRollDegrees = poseRollDegrees;
|
||||
}
|
||||
|
||||
public void setInitialViewHeadingDegrees(int initialViewHeadingDegrees) {
|
||||
this.initialViewHeadingDegrees = initialViewHeadingDegrees;
|
||||
}
|
||||
|
||||
public void setInitialViewPitchDegrees(int initialViewPitchDegrees) {
|
||||
this.initialViewPitchDegrees = initialViewPitchDegrees;
|
||||
}
|
||||
|
||||
public void setInitialViewRollDegrees(int initialViewRollDegrees) {
|
||||
this.initialViewRollDegrees = initialViewRollDegrees;
|
||||
}
|
||||
|
||||
public void setInitialHorizontalFOVDegrees(Float initialHorizontalFOVDegrees) {
|
||||
this.initialHorizontalFOVDegrees = initialHorizontalFOVDegrees;
|
||||
}
|
||||
|
||||
public void setFirstPhotoDate(Date firstPhotoDate) {
|
||||
this.firstPhotoDate = firstPhotoDate;
|
||||
}
|
||||
|
||||
public void setLastPhotoDate(Date lastPhotoDate) {
|
||||
this.lastPhotoDate = lastPhotoDate;
|
||||
}
|
||||
|
||||
public void setSourcePhotosCount(Integer sourcePhotosCount) {
|
||||
this.sourcePhotosCount = sourcePhotosCount;
|
||||
}
|
||||
|
||||
public void setExposureLockUsed(boolean exposureLockUsed) {
|
||||
this.exposureLockUsed = exposureLockUsed;
|
||||
}
|
||||
|
||||
public void setCroppedAreaImageWidthPixels(Integer croppedAreaImageWidthPixels) {
|
||||
this.croppedAreaImageWidthPixels = croppedAreaImageWidthPixels;
|
||||
}
|
||||
|
||||
public void setCroppedAreaImageHeightPixels(Integer croppedAreaImageHeightPixels) {
|
||||
this.croppedAreaImageHeightPixels = croppedAreaImageHeightPixels;
|
||||
}
|
||||
|
||||
public void setFullPanoWidthPixels(Integer fullPanoWidthPixels) {
|
||||
this.fullPanoWidthPixels = fullPanoWidthPixels;
|
||||
}
|
||||
|
||||
public void setFullPanoHeightPixels(Integer fullPanoHeightPixels) {
|
||||
this.fullPanoHeightPixels = fullPanoHeightPixels;
|
||||
}
|
||||
|
||||
public void setCroppedAreaLeftPixels(Integer croppedAreaLeftPixels) {
|
||||
this.croppedAreaLeftPixels = croppedAreaLeftPixels;
|
||||
}
|
||||
|
||||
public void setCroppedAreaTopPixels(Integer croppedAreaTopPixels) {
|
||||
this.croppedAreaTopPixels = croppedAreaTopPixels;
|
||||
}
|
||||
|
||||
public void setInitialCameraDolly(float initialCameraDolly) {
|
||||
this.initialCameraDolly = initialCameraDolly;
|
||||
}
|
||||
|
||||
public boolean isUsePanoramaViewer() {
|
||||
|
||||
return usePanoramaViewer;
|
||||
}
|
||||
|
||||
public String getCaptureSoftware() {
|
||||
return captureSoftware;
|
||||
}
|
||||
|
||||
public String getStitichingSoftware() {
|
||||
return stitichingSoftware;
|
||||
}
|
||||
|
||||
public TYPE getProjectionType() {
|
||||
return projectionType;
|
||||
}
|
||||
|
||||
public Float getPoseHeadingDegrees() {
|
||||
return poseHeadingDegrees;
|
||||
}
|
||||
|
||||
public float getPosePitchDegrees() {
|
||||
return posePitchDegrees;
|
||||
}
|
||||
|
||||
public float getPoseRollDegrees() {
|
||||
return poseRollDegrees;
|
||||
}
|
||||
|
||||
public int getInitialViewHeadingDegrees() {
|
||||
return initialViewHeadingDegrees;
|
||||
}
|
||||
|
||||
public int getInitialViewPitchDegrees() {
|
||||
return initialViewPitchDegrees;
|
||||
}
|
||||
|
||||
public int getInitialViewRollDegrees() {
|
||||
return initialViewRollDegrees;
|
||||
}
|
||||
|
||||
public Float getInitialHorizontalFOVDegrees() {
|
||||
return initialHorizontalFOVDegrees;
|
||||
}
|
||||
|
||||
public Date getFirstPhotoDate() {
|
||||
return firstPhotoDate;
|
||||
}
|
||||
|
||||
public Date getLastPhotoDate() {
|
||||
return lastPhotoDate;
|
||||
}
|
||||
|
||||
public Integer getSourcePhotosCount() {
|
||||
return sourcePhotosCount;
|
||||
}
|
||||
|
||||
public boolean isExposureLockUsed() {
|
||||
return exposureLockUsed;
|
||||
}
|
||||
|
||||
public Integer getCroppedAreaImageWidthPixels() {
|
||||
return croppedAreaImageWidthPixels;
|
||||
}
|
||||
|
||||
public Integer getCroppedAreaImageHeightPixels() {
|
||||
return croppedAreaImageHeightPixels;
|
||||
}
|
||||
|
||||
public Integer getFullPanoWidthPixels() {
|
||||
return fullPanoWidthPixels;
|
||||
}
|
||||
|
||||
public Integer getFullPanoHeightPixels() {
|
||||
return fullPanoHeightPixels;
|
||||
}
|
||||
|
||||
public Integer getCroppedAreaLeftPixels() {
|
||||
return croppedAreaLeftPixels;
|
||||
}
|
||||
|
||||
public Integer getCroppedAreaTopPixels() {
|
||||
return croppedAreaTopPixels;
|
||||
}
|
||||
|
||||
public float getInitialCameraDolly() {
|
||||
return initialCameraDolly;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.trac.spherical.parser;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -7,8 +9,36 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.CAPTURE_SOFTWARE;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.CROPPED_AREA_IMAGE_HEIGHT_PIXELS;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.CROPPED_AREA_IMAGE_WIDTH_PIXELS;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.CROPPED_AREA_LEFT_PIXELS;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.CROPPED_AREA_TOP_PIXELS;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.EXPOSURE_LOCK_USED;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.FIRST_PHOTO_DATE;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.FULL_PANO_HEIGHT_PIXELS;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.FULL_PANO_WIDTH_PIXELS;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.INITIAL_CAMERA_DOLLY;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.INITIAL_HORIZONTAL_POV_DEGREES;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.INITIAL_VIEW_HEADING_DEGREES;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.INITIAL_VIEW_PITCH_DEGREES;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.INITIAL_VIEW_ROLL_DEGREES;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.LAST_PHOTO_DATE;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.POSE_HEADING_DEGREES;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.POSE_PITCH_DEGREES;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.POSE_ROLL_DEGREES;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.PROJECTION_TYPE;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.SOURCE_PHOTOS_COUNT;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.STITCHING_SOFTWARE;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.TYPE;
|
||||
import static de.trac.spherical.parser.PhotoSphereMetadata.USE_PANORAMA_VIEWER;
|
||||
|
||||
/**
|
||||
* ParserUtil that does stuff.
|
||||
|
@ -17,7 +47,7 @@ public class SphereParser {
|
|||
|
||||
public static final String TAG = "SphereParser";
|
||||
|
||||
public static final String USE_PANORAMA_VIEWER = "GPano:UsePanoramaViewer=\"True\"";
|
||||
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'", Locale.US);
|
||||
|
||||
/*
|
||||
* 0 FF
|
||||
|
@ -57,7 +87,7 @@ public class SphereParser {
|
|||
byte[] r = new byte[FFD8FFE1.length];
|
||||
int i = inputStream.read(r);
|
||||
if (i != FFD8FFE1.length || !Arrays.equals(FFD8FFE1, r)) {
|
||||
System.out.println("Unexpected Image header: " + hex(r) + " (" + hex(FFD8FFE1) + " expected)");
|
||||
Log.d(TAG, "Unexpected Image header: " + hex(r) + " (" + hex(FFD8FFE1) + " expected)");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -77,7 +107,7 @@ public class SphereParser {
|
|||
r = new byte[2];
|
||||
i = inputStream.read(r);
|
||||
if (!Arrays.equals(FFE1, r)) {
|
||||
System.out.println("Image does not contain XML data.");
|
||||
Log.d(TAG, "Image does not contain XML data.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -97,6 +127,77 @@ public class SphereParser {
|
|||
return new String(xml);
|
||||
}
|
||||
|
||||
public static PhotoSphereMetadata parse(String xmp) {
|
||||
PhotoSphereMetadata meta = new PhotoSphereMetadata();
|
||||
meta.setUsePanoramaViewer(parseBoolean(USE_PANORAMA_VIEWER, xmp, true));
|
||||
meta.setCaptureSoftware(getStringValue(CAPTURE_SOFTWARE, xmp));
|
||||
meta.setStitichingSoftware(getStringValue(STITCHING_SOFTWARE, xmp));
|
||||
meta.setProjectionType(parseType(PROJECTION_TYPE, xmp, TYPE.equirectangular));
|
||||
meta.setPoseHeadingDegrees(parseFloat(POSE_HEADING_DEGREES, xmp, null));
|
||||
meta.setPosePitchDegrees(parseFloat(POSE_PITCH_DEGREES, xmp, 0f));
|
||||
meta.setPoseRollDegrees(parseFloat(POSE_ROLL_DEGREES, xmp, 0f));
|
||||
meta.setInitialViewHeadingDegrees(parseInteger(INITIAL_VIEW_HEADING_DEGREES, xmp, 0));
|
||||
meta.setInitialViewPitchDegrees(parseInteger(INITIAL_VIEW_PITCH_DEGREES, xmp, 0));
|
||||
meta.setInitialViewRollDegrees(parseInteger(INITIAL_VIEW_ROLL_DEGREES, xmp, 0));
|
||||
meta.setInitialHorizontalFOVDegrees(parseFloat(INITIAL_HORIZONTAL_POV_DEGREES, xmp, null));
|
||||
meta.setFirstPhotoDate(parseDate(FIRST_PHOTO_DATE, xmp, null));
|
||||
meta.setLastPhotoDate(parseDate(LAST_PHOTO_DATE, xmp, null));
|
||||
meta.setSourcePhotosCount(parseInteger(SOURCE_PHOTOS_COUNT, xmp, null));
|
||||
meta.setExposureLockUsed(parseBoolean(EXPOSURE_LOCK_USED, xmp, false));
|
||||
meta.setCroppedAreaImageWidthPixels(parseInteger(CROPPED_AREA_IMAGE_WIDTH_PIXELS, xmp, null));
|
||||
meta.setCroppedAreaImageHeightPixels(parseInteger(CROPPED_AREA_IMAGE_HEIGHT_PIXELS, xmp, null));
|
||||
meta.setFullPanoWidthPixels(parseInteger(FULL_PANO_WIDTH_PIXELS, xmp, null));
|
||||
meta.setFullPanoHeightPixels(parseInteger(FULL_PANO_HEIGHT_PIXELS, xmp, null));
|
||||
meta.setCroppedAreaLeftPixels(parseInteger(CROPPED_AREA_LEFT_PIXELS, xmp, null));
|
||||
meta.setCroppedAreaTopPixels(parseInteger(CROPPED_AREA_TOP_PIXELS, xmp, null));
|
||||
meta.setInitialCameraDolly(parseFloat(INITIAL_CAMERA_DOLLY, xmp, 0f));
|
||||
return meta;
|
||||
}
|
||||
|
||||
public static String getStringValue(String key, String xmp) {
|
||||
if (!xmp.contains(key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String query = key + "=\"";
|
||||
String value = xmp.substring(xmp.indexOf(query) + query.length());
|
||||
value = value.substring(0, value.indexOf("\""));
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Integer parseInteger(String key, String xmp, Integer defaultValue) {
|
||||
String value = getStringValue(key, xmp);
|
||||
return value == null ? defaultValue : Integer.parseInt(value);
|
||||
}
|
||||
|
||||
public static Float parseFloat(String key, String xmp, Float defaultValue) {
|
||||
String value = getStringValue(key, xmp);
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean parseBoolean(String key, String xmp, Boolean defaultValue) {
|
||||
String value = getStringValue(key, xmp);
|
||||
return value == null ? defaultValue : Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
public static TYPE parseType(String key, String xmp, TYPE defaultValue) {
|
||||
String value = getStringValue(key, xmp);
|
||||
return value == null ? defaultValue : TYPE.equirectangular;
|
||||
}
|
||||
|
||||
public static Date parseDate(String key, String xmp, Date defaultValue) {
|
||||
String value = getStringValue(key, xmp);
|
||||
try {
|
||||
return value == null ? defaultValue : dateFormat.parse(value);
|
||||
} catch (ParseException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
File file = new File(args[0]);
|
||||
System.out.println(getXMLContent(new FileInputStream(file)));
|
||||
|
|
Loading…
Reference in a new issue