Skip to content

Commit

Permalink
Merge pull request #57 from kinow/todos-commented-code
Browse files Browse the repository at this point in the history
[IMAGING-241] Fix TODO markers for byte arrays
  • Loading branch information
kinow committed Nov 17, 2019
2 parents 0aa5c81 + 344597e commit 31a0733
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 199 deletions.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Expand Up @@ -45,6 +45,9 @@ The <action> type attribute can be add,update,fix,remove.
</properties>
<body>
<release version="1.0-alpha2" date="2019-??-??" description="Second 1.0 alpha release">
<action issue="241" dev="kinow" type="fix">
Copy byte arrays fixing TODO markers
</action>
<action issue="IMAGING-136" dev="kinow" type="fix" due-to="Michael Groß">
Imaging.getImageInfo() fails to read JPEG file
</action>
Expand Down
Expand Up @@ -105,11 +105,12 @@ public byte[] getEXIFThumbnailData() throws ImageReadException, IOException {

byte[] data = null;
if (dir.getJpegImageData() != null) {
data = dir.getJpegImageData().getData(); // TODO clone?
data = dir.getJpegImageData().getData();
}
// Support other image formats here.

if (data != null) {
// already cloned, safe to return this copy
return data;
}
}
Expand Down
Expand Up @@ -953,175 +953,6 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Obj
usesPalette, colorType, compressionAlgorithm);
}

// public ImageInfo getImageInfo(ByteSource byteSource, Map params)
// throws ImageReadException, IOException
// {
//
// List allSegments = readSegments(byteSource, null, false);
//
// final int SOF_MARKERS[] = new int[]{
// SOF0_MARKER, SOF1_MARKER, SOF2_MARKER, SOF3_MARKER, SOF5_MARKER,
// SOF6_MARKER, SOF7_MARKER, SOF9_MARKER, SOF10_MARKER, SOF11_MARKER,
// SOF13_MARKER, SOF14_MARKER, SOF15_MARKER,
// };
//
// List sofMarkers = new ArrayList();
// for(int i=0;i<SOF_MARKERS.length;i++)
// sofMarkers.add(new Integer(SOF_MARKERS[i]));
// List SOFSegments = filterSegments(allSegments, sofMarkers);
// if (SOFSegments == null || SOFSegments.size()<1)
// throw new ImageReadException("No SOFN Data Found.");
//
// List jfifMarkers = new ArrayList();
// jfifMarkers.add(new Integer(JFIF_MARKER));
// List jfifSegments = filterSegments(allSegments, jfifMarkers);
//
// SofnSegment firstSOFNSegment = (SofnSegment) SOFSegments.get(0);
//
// int Width = firstSOFNSegment.width;
// int Height = firstSOFNSegment.height;
//
// JfifSegment jfifSegment = null;
//
// if (jfifSegments != null && jfifSegments.size() > 0)
// jfifSegment = (JfifSegment) jfifSegments.get(0);
//
// double x_density = -1.0;
// double y_density = -1.0;
// double units_per_inch = -1.0;
// // int JFIF_major_version;
// // int JFIF_minor_version;
// String FormatDetails;
//
// if (jfifSegment != null)
// {
// x_density = jfifSegment.xDensity;
// y_density = jfifSegment.yDensity;
// int density_units = jfifSegment.densityUnits;
// // JFIF_major_version = fTheJFIFSegment.JFIF_major_version;
// // JFIF_minor_version = fTheJFIFSegment.JFIF_minor_version;
//
// FormatDetails = "Jpeg/JFIF v." + jfifSegment.jfifMajorVersion
// + "." + jfifSegment.jfifMinorVersion;
//
// switch (density_units)
// {
// case 0 :
// break;
// case 1 : // inches
// units_per_inch = 1.0;
// break;
// case 2 : // cms
// units_per_inch = 2.54;
// break;
// default :
// break;
// }
// }
// else
// {
// JpegImageMetadata metadata = (JpegImageMetadata) getMetadata(byteSource,
// params);
//
// {
// TiffField field = metadata
// .findEXIFValue(TiffField.TIFF_TAG_XRESOLUTION);
// if (field == null)
// throw new ImageReadException("No XResolution");
//
// x_density = ((Number) field.getValue()).doubleValue();
// }
// {
// TiffField field = metadata
// .findEXIFValue(TiffField.TIFF_TAG_YRESOLUTION);
// if (field == null)
// throw new ImageReadException("No YResolution");
//
// y_density = ((Number) field.getValue()).doubleValue();
// }
// {
// TiffField field = metadata
// .findEXIFValue(TiffField.TIFF_TAG_RESOLUTION_UNIT);
// if (field == null)
// throw new ImageReadException("No ResolutionUnits");
//
// int density_units = ((Number) field.getValue()).intValue();
//
// switch (density_units)
// {
// case 1 :
// break;
// case 2 : // inches
// units_per_inch = 1.0;
// break;
// case 3 : // cms
// units_per_inch = 2.54;
// break;
// default :
// break;
// }
//
// }
//
// FormatDetails = "Jpeg/DCM";
//
// }
//
// int PhysicalHeightDpi = -1;
// float PhysicalHeightInch = -1;
// int PhysicalWidthDpi = -1;
// float PhysicalWidthInch = -1;
//
// if (units_per_inch > 0)
// {
// PhysicalWidthDpi = (int) Math.round((double) x_density
// / units_per_inch);
// PhysicalWidthInch = (float) ((double) Width / (x_density *
// units_per_inch));
// PhysicalHeightDpi = (int) Math.round((double) y_density
// * units_per_inch);
// PhysicalHeightInch = (float) ((double) Height / (y_density *
// units_per_inch));
// }
//
// List Comments = new ArrayList();
// // TODO: comments...
//
// int Number_of_components = firstSOFNSegment.numberOfComponents;
// int Precision = firstSOFNSegment.precision;
//
// int BitsPerPixel = Number_of_components * Precision;
// ImageFormat Format = ImageFormat.IMAGE_FORMAT_JPEG;
// String FormatName = "JPEG (Joint Photographic Experts Group) Format";
// String MimeType = "image/jpeg";
// // we ought to count images, but don't yet.
// int NumberOfImages = -1;
// // not accurate ... only reflects first
// boolean progressive = firstSOFNSegment.marker == SOF2_MARKER;
//
// boolean transparent = false; // TODO: inaccurate.
// boolean usesPalette = false; // TODO: inaccurate.
// int ColorType;
// if (Number_of_components == 1)
// ColorType = ImageInfo.ColorType.BW;
// else if (Number_of_components == 3)
// ColorType = ImageInfo.ColorType.RGB;
// else if (Number_of_components == 4)
// ColorType = ImageInfo.ColorType.CMYK;
// else
// ColorType = ImageInfo.ColorType.UNKNOWN;
//
// String compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_JPEG;
//
// ImageInfo result = new ImageInfo(FormatDetails, BitsPerPixel, Comments,
// Format, FormatName, Height, MimeType, NumberOfImages,
// PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi,
// PhysicalWidthInch, Width, progressive, transparent,
// usesPalette, ColorType, compressionAlgorithm);
//
// return result;
// }

@Override
public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource)
throws ImageReadException, IOException {
Expand Down
Expand Up @@ -87,13 +87,6 @@ public int compareTo(final App2Segment other) {
* @return the iccBytes
*/
public byte[] getIccBytes() {
return iccBytes; // TODO clone?
return iccBytes.clone();
}

// public String getDescription()
// {
// return "APPN (APP"
// + (marker - JpegImageParser.JPEG_APP0)
// + ") (" + getDescription() + ")";
// }
}
Expand Up @@ -90,7 +90,7 @@ public JFIFPieceSegment(final int marker, final byte[] segmentData) {
this.marker = marker;
this.markerBytes = markerBytes;
this.segmentLengthBytes = segmentLengthBytes;
this.segmentData = segmentData; // TODO clone?
this.segmentData = segmentData.clone();
}

@Override
Expand Down Expand Up @@ -145,7 +145,7 @@ public boolean isXmpSegment() {
}

public byte[] getSegmentData() {
return segmentData; // TODO clone?
return segmentData.clone();
}

}
Expand Down
Expand Up @@ -24,7 +24,7 @@ class BitParser {
private final int bitDepth;

BitParser(final byte[] bytes, final int bitsPerPixel, final int bitDepth) {
this.bytes = bytes; // TODO clone?
this.bytes = bytes.clone();
this.bitsPerPixel = bitsPerPixel;
this.bitDepth = bitDepth;
}
Expand Down
Expand Up @@ -25,7 +25,7 @@ public abstract class TransparencyFilter extends BinaryFileParser {
private final byte[] bytes;

public TransparencyFilter(final byte[] bytes) {
this.bytes = bytes; // TODO clone?
this.bytes = bytes.clone();

}

Expand Down
Expand Up @@ -396,7 +396,7 @@ public byte[] getICCProfileBytes(final ByteSource byteSource, final Map<String,
if ((bytes == null) || (bytes.length < 1)) {
return null;
}
return bytes; // TODO clone?
return bytes.clone();
}

@Override
Expand Down Expand Up @@ -508,19 +508,6 @@ public ImageInfo getImageInfo(final ByteSource byteSource, final Map<String, Obj
usesPalette, colorType, compressionAlgorithm);
}

// // TODO not used
// private ImageResourceBlock findImageResourceBlock(
// final List<ImageResourceBlock> blocks, final int ID) {
// for (int i = 0; i < blocks.size(); i++) {
// final ImageResourceBlock block = blocks.get(i);
//
// if (block.id == ID) {
// return block;
// }
// }
// return null;
// }

@Override
public boolean dumpImageFile(final PrintWriter pw, final ByteSource byteSource)
throws ImageReadException, IOException {
Expand Down
Expand Up @@ -48,7 +48,7 @@ public DataElement(final long offset, final int length, final byte[] data) {
}

public byte[] getData() {
return data;
return data.clone();
}

public int getDataLength() {
Expand Down
Expand Up @@ -72,11 +72,11 @@ public IccProfileInfo(final byte[] data, final int profileSize, final int cmmTyp
}

public byte[] getData() {
return data; // TODO clone? does not appear to be used
return data.clone();
}

public byte[] getProfileId() {
return profileId; // TODO clone? does not appear to be used
return profileId.clone();
}

public IccTag[] getTags() {
Expand Down

0 comments on commit 31a0733

Please sign in to comment.