@@ -600,26 +600,24 @@ protected Map<String, Object> _parsejpg(String fileName, byte[] data) {
600600 JpegReader jpegReader = new JpegReader ();
601601 img = jpegReader .readImage (data );
602602
603- Map <String , Object > image = new HashMap <>();
604- image .put ("w" , Integer .valueOf (img .getWidth ()));
605- image .put ("h" , Integer .valueOf (img .getHeight ()));
606603 String colspace ;
607- if (img .getColorModel ().getColorSpace ().getType () == ColorSpace .TYPE_CMYK ) {
608- colspace = "DeviceCMYK" ;
609- } else if (img .getColorModel ().getColorSpace ().getType () == ColorSpace .TYPE_RGB ) {
604+ // Output from jpegReader should always be RGB but still throw just in case it somehow isn't
605+ if (img .getColorModel ().getColorSpace ().getType () == ColorSpace .TYPE_RGB ) {
610606 colspace = "DeviceRGB" ;
611- } else if (img .getColorModel ().getColorSpace ().getType () == ColorSpace .TYPE_GRAY ) {
612- colspace = "DeviceGray" ;
613607 } else {
614608 throw new IllegalArgumentException ("Ungültiges Farbmodell " + img .getColorModel ().getColorSpace ().getType ());
615609 }
610+ //
611+ ByteArrayOutputStream boas = new ByteArrayOutputStream ();
612+ ImageIO .write (img , "jpg" , boas );
613+ // Load image map with img metadata / raw image data
614+ Map <String , Object > image = new HashMap <>();
615+ image .put ("w" , Integer .valueOf (img .getWidth ()));
616+ image .put ("h" , Integer .valueOf (img .getHeight ()));
616617 image .put ("cs" , colspace );
617618 image .put ("bpc" , 8 );
618619 image .put ("f" , "DCTDecode" );
619620 image .put ("i" , Integer .valueOf (this .images .size () + 1 ));
620-
621- ByteArrayOutputStream boas = new ByteArrayOutputStream ();
622- ImageIO .write (img , "jpg" , boas );
623621 image .put ("data" , boas .toByteArray ());
624622 return image ;
625623 } catch (IOException | ImageReadException e ) {
0 commit comments