Skip to content
Permalink
Browse files

8227816: More Colorful ICC profiles

Reviewed-by: serb, psadhukhan, mschoene, rhalade
  • Loading branch information
Phil Race committed Oct 1, 2019
1 parent 7c32a6a commit af20c6b9c4a3a21c1e2c7f56721e1077e7d8f388
Showing with 13 additions and 29 deletions.
  1. +13 −29 src/java.desktop/share/classes/java/awt/color/ICC_Profile.java
@@ -35,6 +35,7 @@

package java.awt.color;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -1017,42 +1018,25 @@ public static ICC_Profile getInstance(InputStream s) throws IOException {


static byte[] getProfileDataFromStream(InputStream s) throws IOException {
byte[] profileData;
int profileSize;

byte[] header = new byte[128];
int bytestoread = 128;
int bytesread = 0;
int n;
BufferedInputStream bis = new BufferedInputStream(s);
bis.mark(128);

while (bytestoread != 0) {
if ((n = s.read(header, bytesread, bytestoread)) < 0) {
return null;
}
bytesread += n;
bytestoread -= n;
}
byte[] header = bis.readNBytes(128);
if (header[36] != 0x61 || header[37] != 0x63 ||
header[38] != 0x73 || header[39] != 0x70) {
return null; /* not a valid profile */
}
profileSize = ((header[0] & 0xff) << 24) |
((header[1] & 0xff) << 16) |
((header[2] & 0xff) << 8) |
(header[3] & 0xff);
profileData = new byte[profileSize];
System.arraycopy(header, 0, profileData, 0, 128);
bytestoread = profileSize - 128;
bytesread = 128;
while (bytestoread != 0) {
if ((n = s.read(profileData, bytesread, bytestoread)) < 0) {
return null;
}
bytesread += n;
bytestoread -= n;
int profileSize = ((header[0] & 0xff) << 24) |
((header[1] & 0xff) << 16) |
((header[2] & 0xff) << 8) |
(header[3] & 0xff);
bis.reset();
try {
return bis.readNBytes(profileSize);
} catch (OutOfMemoryError e) {
throw new IOException("Color profile is too big");
}

return profileData;
}

/**

0 comments on commit af20c6b

Please sign in to comment.