mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
Merge pull request #4 from radarhere/improved_dds
Loop over enums to create constants
This commit is contained in:
commit
f59c9ae348
|
@ -11,6 +11,7 @@ Full text of the CC0 license:
|
|||
"""
|
||||
import io
|
||||
import struct
|
||||
import sys
|
||||
from enum import IntEnum, IntFlag
|
||||
|
||||
from . import Image, ImageFile, ImagePalette
|
||||
|
@ -263,62 +264,43 @@ class D3DFMT(IntEnum):
|
|||
|
||||
|
||||
# Backward compat layer
|
||||
DDSD_CAPS = DDSD.CAPS
|
||||
DDSD_HEIGHT = DDSD.HEIGHT
|
||||
DDSD_WIDTH = DDSD.WIDTH
|
||||
DDSD_PITCH = DDSD.PITCH
|
||||
DDSD_PIXELFORMAT = DDSD.PIXELFORMAT
|
||||
DDSD_MIPMAPCOUNT = DDSD.MIPMAPCOUNT
|
||||
DDSD_LINEARSIZE = DDSD.LINEARSIZE
|
||||
DDSD_DEPTH = DDSD.DEPTH
|
||||
module = sys.modules[__name__]
|
||||
for item in DDSD:
|
||||
setattr(module, "DDSD_" + item.name, item.value)
|
||||
for item in DDSCAPS:
|
||||
setattr(module, "DDSCAPS_" + item.name, item.value)
|
||||
for item in DDSCAPS2:
|
||||
setattr(module, "DDSCAPS2_" + item.name, item.value)
|
||||
for item in DDPF:
|
||||
setattr(module, "DDPF_" + item.name, item.value)
|
||||
|
||||
DDSCAPS_COMPLEX = DDSCAPS.COMPLEX
|
||||
DDSCAPS_TEXTURE = DDSCAPS.TEXTURE
|
||||
DDSCAPS_MIPMAP = DDSCAPS.MIPMAP
|
||||
DDS_FOURCC = DDPF.FOURCC
|
||||
DDS_RGB = DDPF.RGB
|
||||
DDS_RGBA = DDPF.RGB | DDPF.ALPHAPIXELS
|
||||
DDS_LUMINANCE = DDPF.LUMINANCE
|
||||
DDS_LUMINANCEA = DDPF.LUMINANCE | DDPF.ALPHAPIXELS
|
||||
DDS_ALPHA = DDPF.ALPHA
|
||||
DDS_PAL8 = DDPF.PALETTEINDEXED8
|
||||
|
||||
DDSCAPS2_CUBEMAP = DDSCAPS2.CUBEMAP
|
||||
DDSCAPS2_CUBEMAP_POSITIVEX = DDSCAPS2.CUBEMAP_POSITIVEX
|
||||
DDSCAPS2_CUBEMAP_NEGATIVEX = DDSCAPS2.CUBEMAP_NEGATIVEX
|
||||
DDSCAPS2_CUBEMAP_POSITIVEY = DDSCAPS2.CUBEMAP_POSITIVEY
|
||||
DDSCAPS2_CUBEMAP_NEGATIVEY = DDSCAPS2.CUBEMAP_NEGATIVEY
|
||||
DDSCAPS2_CUBEMAP_POSITIVEZ = DDSCAPS2.CUBEMAP_POSITIVEZ
|
||||
DDSCAPS2_CUBEMAP_NEGATIVEZ = DDSCAPS2.CUBEMAP_NEGATIVEZ
|
||||
DDSCAPS2_VOLUME = DDSCAPS2.VOLUME
|
||||
DDS_HEADER_FLAGS_TEXTURE = DDSD.CAPS | DDSD.HEIGHT | DDSD.WIDTH | DDSD.PIXELFORMAT
|
||||
DDS_HEADER_FLAGS_MIPMAP = DDSD.MIPMAPCOUNT
|
||||
DDS_HEADER_FLAGS_VOLUME = DDSD.DEPTH
|
||||
DDS_HEADER_FLAGS_PITCH = DDSD.PITCH
|
||||
DDS_HEADER_FLAGS_LINEARSIZE = DDSD.LINEARSIZE
|
||||
|
||||
DDPF_ALPHAPIXELS = DDPF.ALPHAPIXELS
|
||||
DDPF_ALPHA = DDPF.ALPHA
|
||||
DDPF_FOURCC = DDPF.FOURCC
|
||||
DDPF_PALETTEINDEXED8 = DDPF.PALETTEINDEXED8
|
||||
DDPF_RGB = DDPF.RGB
|
||||
DDPF_LUMINANCE = DDPF.LUMINANCE
|
||||
DDS_HEIGHT = DDSD.HEIGHT
|
||||
DDS_WIDTH = DDSD.WIDTH
|
||||
|
||||
DDS_FOURCC = DDPF_FOURCC
|
||||
DDS_RGB = DDPF_RGB
|
||||
DDS_RGBA = DDPF_RGB | DDPF_ALPHAPIXELS
|
||||
DDS_LUMINANCE = DDPF_LUMINANCE
|
||||
DDS_LUMINANCEA = DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
||||
DDS_ALPHA = DDPF_ALPHA
|
||||
DDS_PAL8 = DDPF_PALETTEINDEXED8
|
||||
DDS_SURFACE_FLAGS_TEXTURE = DDSCAPS.TEXTURE
|
||||
DDS_SURFACE_FLAGS_MIPMAP = DDSCAPS.COMPLEX | DDSCAPS.MIPMAP
|
||||
DDS_SURFACE_FLAGS_CUBEMAP = DDSCAPS.COMPLEX
|
||||
|
||||
DDS_HEADER_FLAGS_TEXTURE = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
||||
DDS_HEADER_FLAGS_MIPMAP = DDSD_MIPMAPCOUNT
|
||||
DDS_HEADER_FLAGS_VOLUME = DDSD_DEPTH
|
||||
DDS_HEADER_FLAGS_PITCH = DDSD_PITCH
|
||||
DDS_HEADER_FLAGS_LINEARSIZE = DDSD_LINEARSIZE
|
||||
|
||||
DDS_HEIGHT = DDSD_HEIGHT
|
||||
DDS_WIDTH = DDSD_WIDTH
|
||||
|
||||
DDS_SURFACE_FLAGS_TEXTURE = DDSCAPS_TEXTURE
|
||||
DDS_SURFACE_FLAGS_MIPMAP = DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
|
||||
DDS_SURFACE_FLAGS_CUBEMAP = DDSCAPS_COMPLEX
|
||||
|
||||
DDS_CUBEMAP_POSITIVEX = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
|
||||
DDS_CUBEMAP_NEGATIVEX = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
|
||||
DDS_CUBEMAP_POSITIVEY = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
|
||||
DDS_CUBEMAP_NEGATIVEY = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
|
||||
DDS_CUBEMAP_POSITIVEZ = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
|
||||
DDS_CUBEMAP_NEGATIVEZ = DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
|
||||
DDS_CUBEMAP_POSITIVEX = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEX
|
||||
DDS_CUBEMAP_NEGATIVEX = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_NEGATIVEX
|
||||
DDS_CUBEMAP_POSITIVEY = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEY
|
||||
DDS_CUBEMAP_NEGATIVEY = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_NEGATIVEY
|
||||
DDS_CUBEMAP_POSITIVEZ = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_POSITIVEZ
|
||||
DDS_CUBEMAP_NEGATIVEZ = DDSCAPS2.CUBEMAP | DDSCAPS2.CUBEMAP_NEGATIVEZ
|
||||
|
||||
DXT1_FOURCC = D3DFMT.DXT1
|
||||
DXT3_FOURCC = D3DFMT.DXT3
|
||||
|
@ -405,7 +387,7 @@ class DdsImageFile(ImageFile.ImageFile):
|
|||
else:
|
||||
msg = f"Unsupported bitcount {bitcount} for {pfflags_}"
|
||||
raise OSError(msg)
|
||||
elif pfflags & DDPF_PALETTEINDEXED8:
|
||||
elif pfflags & DDPF.PALETTEINDEXED8:
|
||||
self._mode = "P"
|
||||
self.palette = ImagePalette.raw("RGBA", self.fp.read(1024))
|
||||
self.tile = [("raw", (0, 0) + self.size, 0, "L")]
|
||||
|
|
|
@ -212,7 +212,7 @@ class _Tile(NamedTuple):
|
|||
encoder_name: str
|
||||
extents: tuple[int, int, int, int]
|
||||
offset: int
|
||||
tile_args: tuple
|
||||
args: tuple
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
|
|
|
@ -523,10 +523,10 @@ def _save(im, fp, tile, bufsize=0):
|
|||
|
||||
|
||||
def _encode_tile(im, fp, tile: list[Image._Tile], bufsize, fh, exc=None):
|
||||
for encoder_name, extents, offset, tile_args in tile:
|
||||
for encoder_name, extents, offset, args in tile:
|
||||
if offset > 0:
|
||||
fp.seek(offset)
|
||||
encoder = Image._getencoder(im.mode, encoder_name, tile_args, im.encoderconfig)
|
||||
encoder = Image._getencoder(im.mode, encoder_name, args, im.encoderconfig)
|
||||
try:
|
||||
encoder.setimage(im.im, extents)
|
||||
if encoder.pushes_fd:
|
||||
|
|
Loading…
Reference in New Issue
Block a user