652 SampleModel sm = raster.getSampleModel(); |
652 SampleModel sm = raster.getSampleModel(); |
653 cs = cm.getColorSpace(); |
653 cs = cm.getColorSpace(); |
654 int csType = cs.getType(); |
654 int csType = cs.getType(); |
655 if (csType != ColorSpace.TYPE_RGB) { |
655 if (csType != ColorSpace.TYPE_RGB) { |
656 if (csType == ColorSpace.TYPE_GRAY |
656 if (csType == ColorSpace.TYPE_GRAY |
657 && cm instanceof ComponentColorModel) { |
657 && ComponentColorModel.class.equals(cm.getClass())) { |
658 // Check if this might be a child raster (fix for bug 4240596) |
658 // Check if this might be a child raster (fix for bug 4240596) |
659 if (sm instanceof ComponentSampleModel && |
659 if (sm instanceof ComponentSampleModel && |
660 ((ComponentSampleModel)sm).getPixelStride() != numBands) { |
660 ((ComponentSampleModel)sm).getPixelStride() != numBands) { |
661 imageType = TYPE_CUSTOM; |
661 imageType = TYPE_CUSTOM; |
662 } else if (raster instanceof ByteComponentRaster && |
662 } else if (raster instanceof ByteComponentRaster && |
|
663 PixelInterleavedSampleModel.class.equals(sm.getClass()) && |
663 raster.getNumBands() == 1 && |
664 raster.getNumBands() == 1 && |
664 cm.getComponentSize(0) == 8 && |
665 cm.getComponentSize(0) == 8 && |
665 ((ByteComponentRaster)raster).getPixelStride() == 1) { |
666 ((ByteComponentRaster)raster).getPixelStride() == 1) { |
666 imageType = TYPE_BYTE_GRAY; |
667 imageType = TYPE_BYTE_GRAY; |
667 } else if (raster instanceof ShortComponentRaster && |
668 } else if (raster instanceof ShortComponentRaster && |
|
669 PixelInterleavedSampleModel.class.equals(sm.getClass()) && |
668 raster.getNumBands() == 1 && |
670 raster.getNumBands() == 1 && |
669 cm.getComponentSize(0) == 16 && |
671 cm.getComponentSize(0) == 16 && |
670 ((ShortComponentRaster)raster).getPixelStride() == 1) { |
672 ((ShortComponentRaster)raster).getPixelStride() == 1) { |
671 imageType = TYPE_USHORT_GRAY; |
673 imageType = TYPE_USHORT_GRAY; |
672 } |
674 } |
682 (IntegerComponentRaster) raster; |
684 (IntegerComponentRaster) raster; |
683 // Check if the raster params and the color model |
685 // Check if the raster params and the color model |
684 // are correct |
686 // are correct |
685 int pixSize = cm.getPixelSize(); |
687 int pixSize = cm.getPixelSize(); |
686 if (iraster.getPixelStride() == 1 && |
688 if (iraster.getPixelStride() == 1 && |
687 cm instanceof DirectColorModel && |
689 DirectColorModel.class.equals(cm.getClass()) && |
|
690 SinglePixelPackedSampleModel.class.equals(sm.getClass()) && |
688 (pixSize == 32 || pixSize == 24)) |
691 (pixSize == 32 || pixSize == 24)) |
689 { |
692 { |
690 // Now check on the DirectColorModel params |
693 // Now check on the DirectColorModel params |
691 DirectColorModel dcm = (DirectColorModel) cm; |
694 DirectColorModel dcm = (DirectColorModel) cm; |
692 int rmask = dcm.getRedMask(); |
695 int rmask = dcm.getRedMask(); |
713 imageType = TYPE_INT_BGR; |
716 imageType = TYPE_INT_BGR; |
714 } |
717 } |
715 } // if (rmask == DCM_BGR_RED_MASK && |
718 } // if (rmask == DCM_BGR_RED_MASK && |
716 } // if (iraster.getPixelStride() == 1 |
719 } // if (iraster.getPixelStride() == 1 |
717 } // ((raster instanceof IntegerComponentRaster) && |
720 } // ((raster instanceof IntegerComponentRaster) && |
718 else if ((cm instanceof IndexColorModel) && (numBands == 1) && |
721 else if ((IndexColorModel.class.equals(cm.getClass())) && |
|
722 (numBands == 1) && |
719 (!cm.hasAlpha() || !isAlphaPre)) |
723 (!cm.hasAlpha() || !isAlphaPre)) |
720 { |
724 { |
721 IndexColorModel icm = (IndexColorModel) cm; |
725 IndexColorModel icm = (IndexColorModel) cm; |
722 int pixSize = icm.getPixelSize(); |
726 int pixSize = icm.getPixelSize(); |
723 |
727 |
724 if (raster instanceof BytePackedRaster) { |
728 if (raster instanceof BytePackedRaster && |
|
729 MultiPixelPackedSampleModel.class.equals(sm.getClass())) |
|
730 { |
725 imageType = TYPE_BYTE_BINARY; |
731 imageType = TYPE_BYTE_BINARY; |
726 } // if (raster instanceof BytePackedRaster) |
732 } // if (raster instanceof BytePackedRaster) |
727 else if (raster instanceof ByteComponentRaster) { |
733 else if (raster instanceof ByteComponentRaster && |
|
734 PixelInterleavedSampleModel.class.equals(sm.getClass())) |
|
735 { |
728 ByteComponentRaster braster = (ByteComponentRaster) raster; |
736 ByteComponentRaster braster = (ByteComponentRaster) raster; |
729 if (braster.getPixelStride() == 1 && pixSize <= 8) { |
737 if (braster.getPixelStride() == 1 && pixSize <= 8) { |
730 imageType = TYPE_BYTE_INDEXED; |
738 imageType = TYPE_BYTE_INDEXED; |
731 } |
739 } |
732 } |
740 } |
733 } // else if (cm instanceof IndexColorModel) && (numBands == 1)) |
741 } // else if (cm instanceof IndexColorModel) && (numBands == 1)) |
734 else if ((raster instanceof ShortComponentRaster) |
742 else if ((raster instanceof ShortComponentRaster) |
735 && (cm instanceof DirectColorModel) |
743 && (DirectColorModel.class.equals(cm.getClass())) |
|
744 && (SinglePixelPackedSampleModel.class.equals(sm.getClass())) |
736 && (numBands == 3) |
745 && (numBands == 3) |
737 && !cm.hasAlpha()) |
746 && !cm.hasAlpha()) |
738 { |
747 { |
739 DirectColorModel dcm = (DirectColorModel) cm; |
748 DirectColorModel dcm = (DirectColorModel) cm; |
740 if (dcm.getRedMask() == DCM_565_RED_MASK) { |
749 if (dcm.getRedMask() == DCM_565_RED_MASK) { |
777 } |
786 } |
778 if (is8bit && |
787 if (is8bit && |
779 braster.getPixelStride() == numBands && |
788 braster.getPixelStride() == numBands && |
780 offs[0] == numBands-1 && |
789 offs[0] == numBands-1 && |
781 offs[1] == numBands-2 && |
790 offs[1] == numBands-2 && |
782 offs[2] == numBands-3) |
791 offs[2] == numBands-3 && |
|
792 ComponentColorModel.class.equals(ccm.getClass()) && |
|
793 PixelInterleavedSampleModel.class.equals(csm.getClass())) |
783 { |
794 { |
784 if (numBands == 3) { |
795 if (numBands == 3 && !ccm.hasAlpha()) { |
785 imageType = TYPE_3BYTE_BGR; |
796 imageType = TYPE_3BYTE_BGR; |
786 } |
797 } |
787 else if (offs[3] == 0) { |
798 else if (offs[3] == 0 && ccm.hasAlpha()) { |
788 imageType = (isAlphaPre |
799 imageType = (isAlphaPre |
789 ? TYPE_4BYTE_ABGR_PRE |
800 ? TYPE_4BYTE_ABGR_PRE |
790 : TYPE_4BYTE_ABGR); |
801 : TYPE_4BYTE_ABGR); |
791 } |
802 } |
792 } |
803 } |