Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix imwrite for single channel images #139

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions source/dcv/imageio/image.d
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,32 @@ bool imwrite(in string path, size_t width, size_t height, ImageFormat format, Bi
if (depth == BitDepth.BD_8)
{
GamutImage gimage = GamutImage(cast(int)width, cast(int)height, gamutPixelTypeFromFormat[format]);

size_t kk;
for (int y = 0; y < gimage.height(); ++y)
{
ubyte* scan = cast(ubyte*) gimage.scanline(y);
for (int x = 0; x < gimage.width(); ++x)

if(data.length == width * height){ // single channel
size_t kk;
for (int y = 0; y < gimage.height(); ++y){
ubyte* scan = cast(ubyte*) gimage.scanline(y);
for (int x = 0; x < gimage.width(); ++x){
scan[x] = data[kk++];
}
}
}else if(data.length == width * height * 3){ // 3 channels
size_t kk;
for (int y = 0; y < gimage.height(); ++y)
{
scan[3*x + 0] = data[kk++];
scan[3*x + 1] = data[kk++];
scan[3*x + 2] = data[kk++];

ubyte* scan = cast(ubyte*) gimage.scanline(y);
for (int x = 0; x < gimage.width(); ++x)
{
scan[3*x + 0] = data[kk++];
scan[3*x + 1] = data[kk++];
scan[3*x + 2] = data[kk++];

}
}
}else {
throw new Exception("Only 1 and 3 channel images can be written.");
}

if (!gimage.saveToFile(path))
throw new Exception("Writing " ~ path ~ " failed");
// write_image(path, cast(long)width, cast(long)height, data, imageFormatChannelCount[format]);
Expand Down Expand Up @@ -544,4 +556,4 @@ unittest
// should enter here...
}
}
*/
*/