Skip to content

Commit

Permalink
Merge pull request h2non#172 from isatsam/master
Browse files Browse the repository at this point in the history
Add support for DDS
  • Loading branch information
h2non authored Aug 28, 2024
2 parents d13ef9b + 97b250e commit cd3441f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Image
- **heic** - ``image/heic``
- **avif** - ``image/avif``
- **qoi** - ``image/qoi``
- **dds** - ``image/dds``

Video
^^^^^
Expand Down
1 change: 1 addition & 0 deletions filetype/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
image.Dcm(),
image.Avif(),
image.Qoi(),
image.Dds(),
)

# Supported video types
Expand Down
17 changes: 17 additions & 0 deletions filetype/types/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,20 @@ def match(self, buf):
buf[1] == 0x6F and
buf[2] == 0x69 and
buf[3] == 0x66)


class Dds(Type):
"""
Implements the DDS image type matcher.
"""
MIME = 'image/dds'
EXTENSION = 'dds'

def __init__(self):
super(Dds, self).__init__(
mime=Dds.MIME,
extension=Dds.EXTENSION
)

def match(self, buf):
return buf.startswith(b'\x44\x44\x53\x20')
Binary file added tests/fixtures/sample.dds
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def test_guess_avif(self):
self.assertEqual(kind.mime, 'image/avif')
self.assertEqual(kind.extension, 'avif')

def test_guess_dds(self):
kind = filetype.guess(FIXTURES + '/sample.dds')
self.assertTrue(kind is not None)
self.assertEqual(kind.mime, 'image/dds')
self.assertEqual(kind.extension, 'dds')

def test_guess_m4a(self):
kind = filetype.guess(FIXTURES + '/sample.m4a')
self.assertTrue(kind is not None)
Expand Down

0 comments on commit cd3441f

Please sign in to comment.