| |
---|
| | this.control = Discripter.NEXT; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | Discripter procImageFile(File image, long delta, ElementMapTRKSEG mapTRKSEG, boolean exifWrite, Node gpx) throws ParseException, ImageReadException, IOException, ImageWriteException { |
---|
| | DecimalFormat yearFormatter = new DecimalFormat("0000"); |
---|
| | DecimalFormat monthFormatter = new DecimalFormat("00"); |
---|
| | DecimalFormat dayFormatter = new DecimalFormat("00"); |
---|
| | |
---|
| | Discripter procImageFile(File imageFile, long delta, ElementMapTRKSEG mapTRKSEG, boolean exifWrite, Node gpx) throws ParseException, ImageReadException, IOException, ImageWriteException { |
---|
| | Discripter result = new Discripter(false); |
---|
| | |
---|
| | // itime <-- 画像ファイルの撮影時刻 |
---|
| | // ファイルの更新日時/EXIFの撮影日時 |
---|
| | Date itime = new Date(image.lastModified()); |
---|
| | Date itime = new Date(imageFile.lastModified()); |
---|
| | if (this.exifBase) { |
---|
| | ImageMetadata meta = Imaging.getMetadata(image); |
---|
| | ImageMetadata meta = Imaging.getMetadata(imageFile); |
---|
| | JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; |
---|
| | if (jpegMetadata == null) { |
---|
| | System.out.println("'"+ image.getAbsolutePath() +"' にEXIF情報がありません"); |
---|
| | System.out.println("'"+ imageFile.getAbsolutePath() +"' にEXIF情報がありません"); |
---|
| | result.control = Discripter.CONTINUE; |
---|
| | return result; |
---|
| | } |
---|
| | TiffImageMetadata exif = jpegMetadata.getExif(); |
---|
| | if (exif == null) { |
---|
| | System.out.println("'"+ image.getAbsolutePath() +"' にEXIF情報がありません"); |
---|
| | System.out.println("'"+ imageFile.getAbsolutePath() +"' にEXIF情報がありません"); |
---|
| | result.control = Discripter.CONTINUE; |
---|
| | return result; |
---|
| | } |
---|
| | String dateTimeOriginal = exif.getFieldValue(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL)[0]; |
---|
| |
---|
| | String magvarStr = "-"; |
---|
| | String speedStr = "-"; |
---|
| | double latitude = 90.5D; |
---|
| | double longitude = 180.5D; |
---|
| | //Element trkptE = null; |
---|
| | TagTrkpt trkptT = null; |
---|
| | |
---|
| | for (Map.Entry<Date,ElementMapTRKPT> map : mapTRKSEG.entrySet()) { |
---|
| | ElementMapTRKPT mapTRKPT = map.getValue(); |
---|
| |
---|
| | System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr)); |
---|
| | } |
---|
| | |
---|
| | result.ret = true; |
---|
| | FileOutputStream fos = null; |
---|
| | outDir.mkdir(); |
---|
| | |
---|
| | if (exifWrite) { |
---|
| | TiffOutputSet outputSet = null; |
---|
| | |
---|
| | ImageMetadata meta = Imaging.getMetadata(image); |
---|
| | JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; |
---|
| | if (jpegMetadata != null) { |
---|
| | TiffImageMetadata exif = jpegMetadata.getExif(); |
---|
| | if (exif != null) { |
---|
| | outputSet = exif.getOutputSet(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | if (outputSet == null) { |
---|
| | System.out.println("added : new tiff output set"); |
---|
| | outputSet = new TiffOutputSet(); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF_TAG_DATE_TIME_ORIGINAL / 「撮影日時/オリジナル画像の生成日時」---- |
---|
| | TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory(); |
---|
| | { |
---|
| | Calendar cal = GregorianCalendar.getInstance(); |
---|
| | cal.setTimeZone(TimeZone.getTimeZone("UTC")); |
---|
| | cal.setTime(correctedtime); |
---|
| | exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); |
---|
| | exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, ImportPicture.toEXIFString(cal.getTime())); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS_TIME_STAMP ---- |
---|
| | TiffOutputDirectory gpsDir = outputSet.getOrCreateGPSDirectory(); |
---|
| | { |
---|
| | Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC")); |
---|
| | cal.setTimeZone(TimeZone.getTimeZone("GMT+00")); |
---|
| | cal.setTime(correctedtime); |
---|
| | final String yearStr = yearFormatter.format(cal.get(Calendar.YEAR)); |
---|
| | final String monthStr = monthFormatter.format(cal.get(Calendar.MONTH) + 1); |
---|
| | final String dayStr = dayFormatter.format(cal.get(Calendar.DAY_OF_MONTH)); |
---|
| | final String dateStamp = yearStr +":"+ monthStr +":"+ dayStr; |
---|
| | |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_TIME_STAMP); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_TIME_STAMP, |
---|
| | RationalNumber.valueOf(cal.get(Calendar.HOUR_OF_DAY)), |
---|
| | RationalNumber.valueOf(cal.get(Calendar.MINUTE)), |
---|
| | RationalNumber.valueOf(cal.get(Calendar.SECOND))); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP, dateStamp); |
---|
| | } |
---|
| | |
---|
| | if (trkptT != null) { |
---|
| | //---- EXIF GPS elevation/ALTITUDE ---- |
---|
| | if (eleStr.equals("-") == false) { |
---|
| | final double altitude = Double.parseDouble(eleStr); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, RationalNumber.valueOf(altitude)); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS magvar/IMG_DIRECTION ---- |
---|
| | if (magvarStr.equals("-") == false) { |
---|
| | final double magvar = Double.parseDouble(magvarStr); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, RationalNumber.valueOf(magvar)); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS_ ---- |
---|
| | longitude = Math.abs(longitude); |
---|
| | latitude = Math.abs(latitude); |
---|
| | outputSet.setGPSInDegrees(longitude, latitude); |
---|
| | } |
---|
| | |
---|
| | ExifRewriter rewriter = new ExifRewriter(); |
---|
| | try { |
---|
| | fos = new FileOutputStream(new File(outDir, image.getName())); |
---|
| | rewriter.updateExifMetadataLossy(image, fos, outputSet); |
---|
| | } |
---|
| | finally { |
---|
| | if (fos != null) { |
---|
| | fos.close(); |
---|
| | } |
---|
| | } |
---|
| | exifWrite(imageFile, correctedtime, trkptT); |
---|
| | |
---|
| | if (Boolean.parseBoolean(params.getProperty(AppParameters.GPX_OUTPUT_WPT))) { |
---|
| | if (trkptT != null) { |
---|
| | Element temp = createWptTag(image, itime.getTime(), trkptT.trkpt); |
---|
| | Element temp = createWptTag(imageFile, itime.getTime(), trkptT.trkpt); |
---|
| | gpx.appendChild(temp); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | else { |
---|
| | if (this.param_ImgOutputAll) { |
---|
| | // EXIFの変換を伴わない単純なファイルコピー |
---|
| | FileInputStream sStream = new FileInputStream(image); |
---|
| | FileInputStream dStream = new FileInputStream(new File(outDir, image.getName())); |
---|
| | FileInputStream sStream = new FileInputStream(imageFile); |
---|
| | FileInputStream dStream = new FileInputStream(new File(outDir, imageFile.getName())); |
---|
| | FileChannel srcChannel = sStream.getChannel(); |
---|
| | FileChannel destChannel = dStream.getChannel(); |
---|
| | try { |
---|
| | srcChannel.transferTo(0, srcChannel.size(), destChannel); |
---|
| |
---|
| | } |
---|
| | result.control = Discripter.NEXT; |
---|
| | return result; |
---|
| | } |
---|
| | |
---|
| | void exifWrite(File imageFile, Date correctedtime, TagTrkpt trkptT) throws ImageReadException, IOException, ImageWriteException { |
---|
| | DecimalFormat yearFormatter = new DecimalFormat("0000"); |
---|
| | DecimalFormat monthFormatter = new DecimalFormat("00"); |
---|
| | DecimalFormat dayFormatter = new DecimalFormat("00"); |
---|
| | |
---|
| | TiffOutputSet outputSet = null; |
---|
| | |
---|
| | ImageMetadata meta = Imaging.getMetadata(imageFile); |
---|
| | JpegImageMetadata jpegMetadata = (JpegImageMetadata)meta; |
---|
| | if (jpegMetadata != null) { |
---|
| | TiffImageMetadata exif = jpegMetadata.getExif(); |
---|
| | if (exif != null) { |
---|
| | outputSet = exif.getOutputSet(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | if (outputSet == null) { |
---|
| | System.out.println("added : new tiff output set"); |
---|
| | outputSet = new TiffOutputSet(); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF_TAG_DATE_TIME_ORIGINAL / 「撮影日時/オリジナル画像の生成日時」---- |
---|
| | TiffOutputDirectory exifDir = outputSet.getOrCreateExifDirectory(); |
---|
| | { |
---|
| | Calendar cal = GregorianCalendar.getInstance(); |
---|
| | cal.setTimeZone(TimeZone.getTimeZone("UTC")); |
---|
| | cal.setTime(correctedtime); |
---|
| | exifDir.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); |
---|
| | exifDir.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL, ImportPicture.toEXIFString(cal.getTime())); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS_TIME_STAMP ---- |
---|
| | TiffOutputDirectory gpsDir = outputSet.getOrCreateGPSDirectory(); |
---|
| | { |
---|
| | Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC")); |
---|
| | cal.setTimeZone(TimeZone.getTimeZone("GMT+00")); |
---|
| | cal.setTime(correctedtime); |
---|
| | final String yearStr = yearFormatter.format(cal.get(Calendar.YEAR)); |
---|
| | final String monthStr = monthFormatter.format(cal.get(Calendar.MONTH) + 1); |
---|
| | final String dayStr = dayFormatter.format(cal.get(Calendar.DAY_OF_MONTH)); |
---|
| | final String dateStamp = yearStr +":"+ monthStr +":"+ dayStr; |
---|
| | |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_TIME_STAMP); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_TIME_STAMP, |
---|
| | RationalNumber.valueOf(cal.get(Calendar.HOUR_OF_DAY)), |
---|
| | RationalNumber.valueOf(cal.get(Calendar.MINUTE)), |
---|
| | RationalNumber.valueOf(cal.get(Calendar.SECOND))); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_DATE_STAMP, dateStamp); |
---|
| | } |
---|
| | |
---|
| | if (trkptT != null) { |
---|
| | //---- EXIF GPS elevation/ALTITUDE ---- |
---|
| | if (trkptT.eleStr != null) { |
---|
| | final double altitude = Double.parseDouble(trkptT.eleStr); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_ALTITUDE); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_ALTITUDE, RationalNumber.valueOf(altitude)); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS magvar/IMG_DIRECTION ---- |
---|
| | if (trkptT.magvarStr != null) { |
---|
| | final double magvar = Double.parseDouble(trkptT.magvarStr); |
---|
| | gpsDir.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION); |
---|
| | gpsDir.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION, RationalNumber.valueOf(magvar)); |
---|
| | } |
---|
| | |
---|
| | //---- EXIF GPS_ ---- |
---|
| | outputSet.setGPSInDegrees(Math.abs(trkptT.lon), Math.abs(trkptT.lat)); |
---|
| | } |
---|
| | |
---|
| | ExifRewriter rewriter = new ExifRewriter(); |
---|
| | try (FileOutputStream fos = new FileOutputStream(new File(outDir, imageFile.getName()))) { |
---|
| | rewriter.updateExifMetadataLossy(imageFile, fos, outputSet); |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * 対象は '*.JPG' のみ対象とする |
---|
| | * @return |
---|
| |
---|
| | |