1 /*
2 * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
442 byte[] compressedProfile =
443 new byte[compressedProfileLength];
444 stream.readFully(compressedProfile);
445 metadata.iCCP_compressedProfile = compressedProfile;
446
447 metadata.iCCP_present = true;
448 }
449
450 private void parse_iTXt_chunk(int chunkLength) throws IOException {
451 long chunkStart = stream.getStreamPosition();
452
453 String keyword = readNullTerminatedString("ISO-8859-1", 80);
454 metadata.iTXt_keyword.add(keyword);
455
456 int compressionFlag = stream.readUnsignedByte();
457 metadata.iTXt_compressionFlag.add(Boolean.valueOf(compressionFlag == 1));
458
459 int compressionMethod = stream.readUnsignedByte();
460 metadata.iTXt_compressionMethod.add(Integer.valueOf(compressionMethod));
461
462 String languageTag = readNullTerminatedString("UTF8", 80);
463 metadata.iTXt_languageTag.add(languageTag);
464
465 long pos = stream.getStreamPosition();
466 int maxLen = (int)(chunkStart + chunkLength - pos);
467 String translatedKeyword =
468 readNullTerminatedString("UTF8", maxLen);
469 metadata.iTXt_translatedKeyword.add(translatedKeyword);
470
471 String text;
472 pos = stream.getStreamPosition();
473 int textLength = (int)(chunkStart + chunkLength - pos);
474 if (textLength < 0) {
475 throw new IIOException("iTXt chunk length is not proper");
476 }
477 byte[] b = new byte[textLength];
478 stream.readFully(b);
479
480 if (compressionFlag == 1) { // Decompress the text
481 text = new String(inflate(b), "UTF8");
482 } else {
483 text = new String(b, "UTF8");
484 }
485 metadata.iTXt_text.add(text);
486
487 // Check if the text chunk contains image creation time
488 if (keyword.equals(PNGMetadata.tEXt_creationTimeKey)) {
|
1 /*
2 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
442 byte[] compressedProfile =
443 new byte[compressedProfileLength];
444 stream.readFully(compressedProfile);
445 metadata.iCCP_compressedProfile = compressedProfile;
446
447 metadata.iCCP_present = true;
448 }
449
450 private void parse_iTXt_chunk(int chunkLength) throws IOException {
451 long chunkStart = stream.getStreamPosition();
452
453 String keyword = readNullTerminatedString("ISO-8859-1", 80);
454 metadata.iTXt_keyword.add(keyword);
455
456 int compressionFlag = stream.readUnsignedByte();
457 metadata.iTXt_compressionFlag.add(Boolean.valueOf(compressionFlag == 1));
458
459 int compressionMethod = stream.readUnsignedByte();
460 metadata.iTXt_compressionMethod.add(Integer.valueOf(compressionMethod));
461
462 long pos = stream.getStreamPosition();
463 int remainingLen = (int)(chunkStart + chunkLength - pos);
464 String languageTag = readNullTerminatedString("UTF8", remainingLen);
465 metadata.iTXt_languageTag.add(languageTag);
466
467 pos = stream.getStreamPosition();
468 remainingLen = (int)(chunkStart + chunkLength - pos);
469 if (remainingLen < 0) {
470 throw new IIOException("iTXt chunk length is not proper");
471 }
472 String translatedKeyword =
473 readNullTerminatedString("UTF8", remainingLen);
474 metadata.iTXt_translatedKeyword.add(translatedKeyword);
475
476 String text;
477 pos = stream.getStreamPosition();
478 int textLength = (int)(chunkStart + chunkLength - pos);
479 if (textLength < 0) {
480 throw new IIOException("iTXt chunk length is not proper");
481 }
482 byte[] b = new byte[textLength];
483 stream.readFully(b);
484
485 if (compressionFlag == 1) { // Decompress the text
486 text = new String(inflate(b), "UTF8");
487 } else {
488 text = new String(b, "UTF8");
489 }
490 metadata.iTXt_text.add(text);
491
492 // Check if the text chunk contains image creation time
493 if (keyword.equals(PNGMetadata.tEXt_creationTimeKey)) {
|