dithermode = Diffuse;
}
- int w = src->width;
- int h = src->height;
- int d = src->depth;
uchar gray[256]; // gray map for 8 bit images
- bool use_gray = (d == 8);
+ bool use_gray = (src->depth == 8);
if (use_gray) { // make gray map
if (fromalpha) {
// Alpha 0x00 -> 0 pixels (white)
}
uchar *dst_data = dst->data;
- int dst_bpl = dst->bytes_per_line;
const uchar *src_data = src->data;
- int src_bpl = src->bytes_per_line;
switch (dithermode) {
case Diffuse: {
- QScopedArrayPointer<int> lineBuffer(new int[w * 2]);
+ QScopedArrayPointer<int> lineBuffer(new int[src->width * 2]);
int *line1 = lineBuffer.data();
- int *line2 = lineBuffer.data() + w;
- int bmwidth = (w+7)/8;
+ int *line2 = lineBuffer.data() + src->width;
+ int bmwidth = (src->width+7)/8;
int *b1, *b2;
- int wbytes = w * (d/8);
+ int wbytes = src->width * (src->depth/8);
const uchar *p = src->data;
const uchar *end = p + wbytes;
b2 = line2;
}
}
}
- for (int y=0; y<h; y++) { // for each scan line...
+ for (int y=0; y<src->height; y++) { // for each scan line...
int *tmp = line1; line1 = line2; line2 = tmp;
- bool not_last_line = y < h - 1;
+ bool not_last_line = y < src->height - 1;
if (not_last_line) { // calc. grayvals for next line
p = src->data + (y+1)*src->bytes_per_line;
end = p + wbytes;
b1 = line1;
b2 = line2;
int bit = 7;
- for (int x=1; x<=w; x++) {
+ for (int x=1; x<=src->width; x++) {
if (*b1 < 128) { // black pixel
err = *b1++;
*p |= 1 << bit;
} else {
bit--;
}
- if (x < w)
+ if (x < src->width)
*b1 += (err*7)>>4; // spread error to right pixel
if (not_last_line) {
b2[0] += (err*5)>>4; // pixel below
if (x > 1)
b2[-1] += (err*3)>>4; // pixel below left
- if (x < w)
+ if (x < src->width)
b2[1] += err>>4; // pixel below right
}
b2++;
case Ordered: {
memset(dst->data, 0, dst->nbytes);
- if (d == 32) {
- for (int i=0; i<h; i++) {
+ if (src->depth == 32) {
+ for (int i=0; i<src->height; i++) {
const uint *p = (const uint *)src_data;
- const uint *end = p + w;
+ const uint *end = p + src->width;
uchar *m = dst_data;
int bit = 7;
int j = 0;
}
}
}
- dst_data += dst_bpl;
- src_data += src_bpl;
+ dst_data += dst->bytes_per_line;
+ src_data += src->bytes_per_line;
}
} else
- /* (d == 8) */ {
- for (int i=0; i<h; i++) {
+ /* (src->depth == 8) */ {
+ for (int i=0; i<src->height; i++) {
const uchar *p = src_data;
- const uchar *end = p + w;
+ const uchar *end = p + src->width;
uchar *m = dst_data;
int bit = 7;
int j = 0;
bit--;
}
}
- dst_data += dst_bpl;
- src_data += src_bpl;
+ dst_data += dst->bytes_per_line;
+ src_data += src->bytes_per_line;
}
}
} break;
default: { // Threshold:
memset(dst->data, 0, dst->nbytes);
- if (d == 32) {
- for (int i=0; i<h; i++) {
+ if (src->depth == 32) {
+ for (int i=0; i<src->height; i++) {
const uint *p = (const uint *)src_data;
- const uint *end = p + w;
+ const uint *end = p + src->width;
uchar *m = dst_data;
int bit = 7;
if (fromalpha) {
}
}
}
- dst_data += dst_bpl;
- src_data += src_bpl;
+ dst_data += dst->bytes_per_line;
+ src_data += src->bytes_per_line;
}
} else
- if (d == 8) {
- for (int i=0; i<h; i++) {
+ if (src->depth == 8) {
+ for (int i=0; i<src->height; i++) {
const uchar *p = src_data;
- const uchar *end = p + w;
+ const uchar *end = p + src->width;
uchar *m = dst_data;
int bit = 7;
while (p < end) {
bit--;
}
}
- dst_data += dst_bpl;
- src_data += src_bpl;
+ dst_data += dst->bytes_per_line;
+ src_data += src->bytes_per_line;
}
}
}