mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Implemented MP attribute breakdown with tests.
This commit is contained in:
		
							parent
							
								
									dcd171c1b8
								
							
						
					
					
						commit
						a5683ab574
					
				| 
						 | 
				
			
			@ -474,10 +474,37 @@ def _getmp(self):
 | 
			
		|||
            unpackedentry = unpack('{0}LLLHH'.format(endianness), rawmpentry)
 | 
			
		||||
            labels = ('Attribute', 'Size', 'DataOffset', 'EntryNo1', 'EntryNo2')
 | 
			
		||||
            mpentry = dict(zip(labels, unpackedentry))
 | 
			
		||||
            mpentryattr = {
 | 
			
		||||
                'DependentParentImageFlag': bool(mpentry['Attribute'] & (1<<31)),
 | 
			
		||||
                'DependentChildImageFlag': bool(mpentry['Attribute'] & (1<<30)),
 | 
			
		||||
                'RepresentativeImageFlag': bool(mpentry['Attribute'] & (1<<29)),
 | 
			
		||||
                'Reserved': (mpentry['Attribute'] & (3<<27)) >> 27,
 | 
			
		||||
                'ImageDataFormat': (mpentry['Attribute'] & (7<<24)) >> 24,
 | 
			
		||||
                'MPType': mpentry['Attribute'] & 0x00FFFFFF
 | 
			
		||||
            }
 | 
			
		||||
            if mpentryattr['ImageDataFormat'] == 0:
 | 
			
		||||
                mpentryattr['ImageDataFormat'] = 'JPEG'
 | 
			
		||||
            else:
 | 
			
		||||
                raise SyntaxError("unsupported picture format in MPO")
 | 
			
		||||
            mptypemap = {
 | 
			
		||||
                0x000000: 'Undefined',
 | 
			
		||||
                0x010001: 'Large Thumbnail (VGA Equivalent)',
 | 
			
		||||
                0x010002: 'Large Thumbnail (Full HD Equivalent)',
 | 
			
		||||
                0x020001: 'Multi-Frame Image (Panorama)',
 | 
			
		||||
                0x020002: 'Multi-Frame Image: (Disparity)',
 | 
			
		||||
                0x020003: 'Multi-Frame Image: (Multi-Angle)',
 | 
			
		||||
                0x030000: 'Baseline MP Primary Image'
 | 
			
		||||
            }
 | 
			
		||||
            mpentryattr['MPType'] = mptypemap.get(mpentryattr['MPType'],
 | 
			
		||||
                'Unknown')
 | 
			
		||||
            mpentry['Attribute'] = mpentryattr
 | 
			
		||||
            mpentries.append(mpentry)
 | 
			
		||||
        mp[0xB002] = mpentries
 | 
			
		||||
    except KeyError:
 | 
			
		||||
        raise SyntaxError("malformed MP Index (bad MP Entry)")
 | 
			
		||||
    # Next we should try and parse the individual image unique ID list;
 | 
			
		||||
    # we don't because I've never seen this actually used in a real MPO
 | 
			
		||||
    # file and so can't test it.
 | 
			
		||||
    return mp
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -226,6 +226,20 @@ TAGS = {
 | 
			
		|||
    45058: "MPEntry",
 | 
			
		||||
    45059: "ImageUIDList",
 | 
			
		||||
    45060: "TotalFrames",
 | 
			
		||||
    45313: "MPIndividualNum",
 | 
			
		||||
    45569: "PanOrientation",
 | 
			
		||||
    45570: "PanOverlap_H",
 | 
			
		||||
    45571: "PanOverlap_V",
 | 
			
		||||
    45572: "BaseViewpointNum",
 | 
			
		||||
    45573: "ConvergenceAngle",
 | 
			
		||||
    45574: "BaselineLength",
 | 
			
		||||
    45575: "VerticalDivergence",
 | 
			
		||||
    45576: "AxisDistance_X",
 | 
			
		||||
    45577: "AxisDistance_Y",
 | 
			
		||||
    45578: "AxisDistance_Z",
 | 
			
		||||
    45579: "YawAngle",
 | 
			
		||||
    45580: "PitchAngle",
 | 
			
		||||
    45581: "RollAngle",
 | 
			
		||||
    
 | 
			
		||||
    # Adobe DNG
 | 
			
		||||
    50706: "DNGVersion",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -51,10 +51,29 @@ class TestFileMpo(PillowTestCase):
 | 
			
		|||
    def test_mp(self):
 | 
			
		||||
        for test_file in test_files:
 | 
			
		||||
            im = Image.open(test_file)
 | 
			
		||||
            info = im._getmp()
 | 
			
		||||
            self.assertEqual(info[45056], '0100')
 | 
			
		||||
            self.assertEqual(info[45057], 2)
 | 
			
		||||
            mpinfo = im._getmp()
 | 
			
		||||
            self.assertEqual(mpinfo[45056], '0100')
 | 
			
		||||
            self.assertEqual(mpinfo[45057], 2)
 | 
			
		||||
    
 | 
			
		||||
    def test_mp_attribute(self):
 | 
			
		||||
        for test_file in test_files:
 | 
			
		||||
            im = Image.open(test_file)
 | 
			
		||||
            mpinfo = im._getmp()
 | 
			
		||||
            frameNumber = 0
 | 
			
		||||
            for mpentry in mpinfo[45058]:
 | 
			
		||||
                mpattr = mpentry['Attribute']
 | 
			
		||||
                if frameNumber:
 | 
			
		||||
                    self.assertFalse(mpattr['RepresentativeImageFlag'])
 | 
			
		||||
                else:
 | 
			
		||||
                    self.assertTrue(mpattr['RepresentativeImageFlag'])
 | 
			
		||||
                self.assertFalse(mpattr['DependentParentImageFlag'])
 | 
			
		||||
                self.assertFalse(mpattr['DependentChildImageFlag'])
 | 
			
		||||
                self.assertEqual(mpattr['ImageDataFormat'], 'JPEG')
 | 
			
		||||
                self.assertEqual(mpattr['MPType'],
 | 
			
		||||
                    'Multi-Frame Image: (Disparity)')
 | 
			
		||||
                self.assertEqual(mpattr['Reserved'], 0)
 | 
			
		||||
                frameNumber += 1
 | 
			
		||||
 | 
			
		||||
    def test_seek(self):
 | 
			
		||||
        for test_file in test_files:
 | 
			
		||||
            im = Image.open(test_file)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user