Mercurial > hg > dmlib
comparison tools/libgfx.c @ 1898:50dbfc10f49f
Fix planar IFF ILBM writing.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 26 Jun 2018 04:31:24 +0300 |
parents | f80b2dc77c30 |
children | 54baa688425b |
comparison
equal
deleted
inserted
replaced
1897:699ee626912b | 1898:50dbfc10f49f |
---|---|
2044 else | 2044 else |
2045 return dmf_write_str(fp, buf, bufLen); | 2045 return dmf_write_str(fp, buf, bufLen); |
2046 } | 2046 } |
2047 | 2047 |
2048 | 2048 |
2049 static inline Uint8 dmEncodeBit(const Uint8 *buf, const int xc) | |
2050 { | |
2051 return (buf[xc] >> (7 - (xc & 7))) & 1; | |
2052 } | |
2053 | |
2054 | |
2055 void dmEncodeBitPlane(Uint8 *dp, const Uint8 *src, const int width, const int nplane) | |
2056 { | |
2057 for (int xc = 0; xc < width; xc++) | |
2058 dp[xc / 8] |= dmEncodeBit(src, xc) << nplane; | |
2059 } | |
2060 | |
2061 | |
2062 int dmEncodeILBMBody(DMResource *fp, DMIFF *iff, const DMImage *img) | 2049 int dmEncodeILBMBody(DMResource *fp, DMIFF *iff, const DMImage *img) |
2063 { | 2050 { |
2064 Uint8 *buf; | 2051 Uint8 *buf; |
2065 size_t bufLen; | 2052 size_t bufLen; |
2066 int res = DMERR_OK; | 2053 int res = DMERR_OK; |
2076 // Encode the chunk | 2063 // Encode the chunk |
2077 for (int yc = 0; yc < img->height; yc++) | 2064 for (int yc = 0; yc < img->height; yc++) |
2078 { | 2065 { |
2079 const Uint8 *sp = img->data + (yc * img->pitch); | 2066 const Uint8 *sp = img->data + (yc * img->pitch); |
2080 | 2067 |
2081 dmMemset(buf, 0, bufLen); | |
2082 | |
2083 for (int plane = 0; plane < nplanes; plane++) | 2068 for (int plane = 0; plane < nplanes; plane++) |
2084 { | 2069 { |
2085 // Encode bitplane | 2070 // Encode bitplane |
2086 dmEncodeBitPlane(buf, sp, img->width, plane); | 2071 dmMemset(buf, 0, bufLen); |
2072 | |
2073 for (int xc = 0; xc < img->width; xc++) | |
2074 buf[xc / 8] |= ((sp[xc] >> plane) & 1) << (7 - (xc & 7)); | |
2087 | 2075 |
2088 // Compress / write data | 2076 // Compress / write data |
2089 if (!dmIFFWriteOneRow(fp, iff, buf, bufLen)) | 2077 if (!dmIFFWriteOneRow(fp, iff, buf, bufLen)) |
2090 { | 2078 { |
2091 res = dmError(DMERR_FWRITE, | 2079 res = dmError(DMERR_FWRITE, |
2092 "IFF: Error in writing image plane #%d @ %d.\n", | 2080 "IFF: Error in writing image plane #%d @ %d.\n", |
2093 plane, yc); | 2081 plane, yc); |
2082 goto error; | |
2083 } | |
2084 } | |
2085 | |
2086 // Write mask data | |
2087 if (iff->bmhd.masking == IFF_MASK_HAS_MASK) | |
2088 { | |
2089 // Encode bitplane | |
2090 dmMemset(buf, 0, bufLen); | |
2091 | |
2092 for (int xc = 0; xc < img->width; xc++) | |
2093 buf[xc / 8] |= (sp[xc] == img->ctransp) << (7 - (xc & 7)); | |
2094 | |
2095 if (!dmIFFWriteOneRow(fp, iff, buf, bufLen)) | |
2096 { | |
2097 res = dmError(DMERR_FWRITE, | |
2098 "IFF: Error in writing mask plane.\n"); | |
2094 goto error; | 2099 goto error; |
2095 } | 2100 } |
2096 } | 2101 } |
2097 } | 2102 } |
2098 | 2103 |