Skip to content

Commit

Permalink
Massive refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ZILtoid1991 committed Aug 25, 2020
1 parent daae48b commit e1c3724
Show file tree
Hide file tree
Showing 12 changed files with 2,499 additions and 1,166 deletions.
86 changes: 82 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# dimage
Image file handling library for D by László Szerémi ([email protected], https://twitter.com/ziltoid1991, https://www.patreon.com/ShapeshiftingLizard, https://ko-fi.com/D1D45NEN).
Image file handling library for D by László Szerémi ([email protected], https://twitter.com/ziltoid1991,
https://www.patreon.com/ShapeshiftingLizard, https://ko-fi.com/D1D45NEN).

# Supported formats and capabilities

Expand All @@ -13,22 +14,99 @@ Image file handling library for D by László Szerémi ([email protected]
* RLE compression and decompression works mostly fine, but needs further testing.
* Capable of reading and writing embedded data (developer area). (untested)
* Capable of accessing extension area and generating scanline table. (untested)
* Extra features not present in standard: less than 8 bit indexed images, scanline boundary ignorance compressing RLE at the sacrifice of easy scanline accessing.
* Extra features not present in standard: less than 8 bit indexed images, scanline boundary ignorance compressing RLE at the
sacrifice of easy scanline accessing.

## Portable Network Graphics (png)

* Compression and decompression through phobos' etc.c.zlib.
* Output mostly works. Certain ancillary chunks generate bad checksums on writing, which might not be liked by certain readers.
* No interlace support yet.
* Basic processing is fully supported, unsupported chunks are stored as extra embedded data.
* Currently truecolor images are only supported with up to 8 bit per channel.

## Windows Bitmap (bmp)

* All versions are supported with some caveats (e.g. 1.x has no built in palette support, so normal reads are problematic).
* Currently truecolor images are only supported with up to 8 bit per channel.

# Usage

## Loading images

The following example shows how to load a TGA image file:

```d
File source = File("example.tga");
Image texture = TGA.load(source);
```

The file can be replaced with any other structure that uses the same functions, such as `VFile`, which enables it to load files
from memory e.g. after loading from a package. Be noted that while there may be size reduction in compressing already compressed
image formats, this will have diminishing results in space saved (and might end up with bigger files), and will slow down access
speeds.

## Accessing data

Most images should have `imageData` return the imagedata as the interface `IImageData`, which have some basic function that
could be sufficient in certain cases, especially when data must be handled by some other library.

```d
ARGB8888 backgroundColor = texture.read(0,0);
assert(texture.getPixelFormat == PixelFormat.ARGB8888, "Unsupported pixel format!");
myFancyTextureLoader(texture.raw.ptr, texture.width, texture.height);
```

`IImageData` can be casted to different other types, which enable more operations. However one must be careful with the types,
which can be checked by using the property `pixelFormat`.

```d
if (indexedImageData.pixelformat == PixelFormat.Indexed)
{
IndexedImageData!ubyte iif = cast(IndexedImageData!ubyte)indexedImageData;
for (int y ; y < iif.height; ; y++)
{
for (int x ; x < iif.width ; x++)
{
iif[x, y] = 0;
}
}
}
```

## Palettes

If an image format supports palettes, then it can be accessed with the `palette` property.

The `IPalette` interface provides the `length` property and the `read(size_t pos)` function, which can be used to create a
for loop:

```d
IPalette pal = indexedImage.palette;
for(size_t i ; i < pal.length ; i++)
{
//Do things that require reading the palette.
}
```

A more complex method is casting the `IPalette` interface into a more exact type, which gives access to the original pixel format,
an `opIndex` function, and basic range functionality:

```d
Palette!RGBA5551 pal = cast(Palette!RGBA5551)indexedImage.palette;
foreach(colorIndex ; pal)
{
//Do things with the palette
}
```

# Planned features

* Better memory safety.
* Use of floating points for conversion.

## Planned formats

* BMP
* TIFF (requires LZW)
* TIFF (requires LZW and JPEG codec)
* GIF (requires LZW)
* JPEG (requires codec)
3 changes: 2 additions & 1 deletion source/dimage/pcx.d → leftout/pcx.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright under Boost Software License.
*/

module dimage.pcx;
module leftout.pcx;

import dimage.base;
import dimage.util;
Expand All @@ -15,6 +15,7 @@ import std.bitmanip;

/**
* Implements ZSoft PCX file handling.
* Dummied out due to complexity.
*/
public class PCX : Image {
/**
Expand Down
Loading

0 comments on commit e1c3724

Please sign in to comment.