JPEGFactoryTest.java (pdfbox-2.0.23-src) | : | JPEGFactoryTest.java (pdfbox-2.0.24-src) | ||
---|---|---|---|---|
skipping to change at line 20 | skipping to change at line 20 | |||
* Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | |||
* limitations under the License. | * limitations under the License. | |||
*/ | */ | |||
package org.apache.pdfbox.pdmodel.graphics.image; | package org.apache.pdfbox.pdmodel.graphics.image; | |||
import java.awt.Graphics; | import java.awt.Graphics; | |||
import java.awt.image.BufferedImage; | import java.awt.image.BufferedImage; | |||
import java.io.ByteArrayInputStream; | ||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | |||
import java.io.File; | import java.io.File; | |||
import java.io.FileInputStream; | ||||
import java.io.IOException; | import java.io.IOException; | |||
import java.io.InputStream; | import java.io.InputStream; | |||
import java.util.Arrays; | import java.util.Arrays; | |||
import javax.imageio.ImageIO; | import javax.imageio.ImageIO; | |||
import junit.framework.TestCase; | import junit.framework.TestCase; | |||
import org.apache.pdfbox.cos.COSName; | import org.apache.pdfbox.cos.COSName; | |||
import org.apache.pdfbox.io.IOUtils; | import org.apache.pdfbox.io.IOUtils; | |||
import org.apache.pdfbox.pdmodel.PDDocument; | import org.apache.pdfbox.pdmodel.PDDocument; | |||
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK; | import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceCMYK; | |||
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray; | import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray; | |||
skipping to change at line 261 | skipping to change at line 263 | |||
} | } | |||
} | } | |||
PDImageXObject ximage = JPEGFactory.createFromImage(document, rgbImage); | PDImageXObject ximage = JPEGFactory.createFromImage(document, rgbImage); | |||
validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName() ); | validate(ximage, 8, width, height, "jpg", PDDeviceRGB.INSTANCE.getName() ); | |||
assertNull(ximage.getSoftMask()); | assertNull(ximage.getSoftMask()); | |||
doWritePDF(document, ximage, testResultsDir, "jpeg-ushort555rgb.pdf"); | doWritePDF(document, ximage, testResultsDir, "jpeg-ushort555rgb.pdf"); | |||
} | } | |||
/** | ||||
* PDFBOX-5137 and PDFBOX-5196: check that numFrameComponents and not numSca | ||||
nComponents is used | ||||
* to determine the color space. | ||||
* | ||||
* @throws IOException | ||||
*/ | ||||
public void testPDFBox5137() throws IOException | ||||
{ | ||||
InputStream is = new FileInputStream("target/imgs/PDFBOX-5196-lotus.jpg" | ||||
); | ||||
byte[] ba = IOUtils.toByteArray(is); | ||||
is.close(); | ||||
PDDocument document = new PDDocument(); | ||||
PDImageXObject ximage = JPEGFactory.createFromByteArray(document, ba); | ||||
validate(ximage, 8, 500, 500, "jpg", PDDeviceRGB.INSTANCE.getName()); | ||||
doWritePDF(document, ximage, testResultsDir, "PDFBOX-5196-lotus.pdf"); | ||||
checkJpegStream(testResultsDir, "PDFBOX-5196-lotus.pdf", new ByteArrayIn | ||||
putStream(ba)); | ||||
} | ||||
// check whether it is possible to extract the jpeg stream exactly | // check whether it is possible to extract the jpeg stream exactly | |||
// as it was passed to createFromStream | // as it was passed to createFromStream | |||
private void checkJpegStream(File testResultsDir, String filename, InputStre am resourceStream) | private void checkJpegStream(File testResultsDir, String filename, InputStre am resourceStream) | |||
throws IOException | throws IOException | |||
{ | { | |||
PDDocument doc = PDDocument.load(new File(testResultsDir, filename)); | PDDocument doc = PDDocument.load(new File(testResultsDir, filename)); | |||
PDImageXObject img = | PDImageXObject img = | |||
(PDImageXObject) doc.getPage(0).getResources().getXObject(COSNam e.getPDFName("Im1")); | (PDImageXObject) doc.getPage(0).getResources().getXObject(COSNam e.getPDFName("Im1")); | |||
InputStream dctStream = img.createInputStream(Arrays.asList(COSName.DCT_ DECODE.getName())); | InputStream dctStream = img.createInputStream(Arrays.asList(COSName.DCT_ DECODE.getName())); | |||
ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); | ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); | |||
End of changes. 3 change blocks. | ||||
0 lines changed or deleted | 27 lines changed or added |