Skip to content

New struct for image mode data #6547

@Yay295

Description

@Yay295

Currently all of the data about the format/mode of an image is stored in the image itself.

struct ImagingMemoryInstance {
/* Format */
char mode[IMAGING_MODE_LENGTH]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK",
"YCbCr", "BGR;xy") */
int type; /* Data type (IMAGING_TYPE_*) */
int depth; /* Depth (ignored in this version) */
int bands; /* Number of bands (1, 2, 3, or 4) */
int xsize; /* Image dimension. */
int ysize;
/* Colour palette (for "P" images only) */
ImagingPalette palette;
/* Data pointers */
UINT8 **image8; /* Set for 8-bit images (pixelsize=1). */
INT32 **image32; /* Set for 32-bit images (pixelsize=4). */
/* Internals */
char **image; /* Actual raster data. */
char *block; /* Set if data is allocated in a single block. */
ImagingMemoryBlock *blocks; /* Memory blocks for pixel storage */
int pixelsize; /* Size of a pixel, in bytes (1, 2 or 4) */
int linesize; /* Size of a line, in bytes (xsize * pixelsize) */
/* Virtual methods */
void (*destroy)(Imaging im);
};

I think it would be cleaner if this information was stored in a separate struct.

struct ImageMode {
    char mode[IMAGING_MODE_LENGTH]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
    int type;                       /* Data type (IMAGING_TYPE_*) */
    int depth;                      /* Depth (ignored in this version) */
    int bands;                      /* Number of bands (1, 2, 3, or 4) */
    int pixelsize;                  /* Size of a pixel, in bytes (1, 2 or 4) */
};

Furthermore, I think some more changes could be made that would simplify coding for some calculations, and allow for more image formats to be processed (#1888).

struct BandDataType {
    char dataType; /* 'u' = unsigned integer, 's' = signed integer, 'f' = floating point */
    UINT8 numBytes;
} BAND_DATA_TYPES[] = {
    {'u', 1}, /* UINT8 */
    {'u', 2}, /* UINT16 */
    {'s', 4}, /* INT32 */
    {'f', 4}, /* FLOAT32 */
};
/* Normal bands are treated normally */
/* Alpha bands may be treated specially by some calculations */
/* Extra bands are ignored (this could be used for padding, or maybe storing non-image data) */
enum BandType { NORMAL, ALPHA, EXTRA };
struct Band {
    char *name; /* "R", "G", "B", "Y", "Cb", "Cr", etc. */
    BandDataType dataType;
    BandType type;
};
struct ImageFormat {
    char *name;      /* Format name ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
    Band *bands;     /* Array of bands in this format */
    UINT32 numBands; /* Number of bands in this format */
    UINT32 numBytes; /* Total size in bytes of one pixel in this format */
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions