foreach loops pt. 1

This commit is contained in:
gazer 2015-12-19 15:55:02 +03:00
parent 5c0380f002
commit 443236ada9
8 changed files with 70 additions and 71 deletions

View File

@ -204,7 +204,7 @@ uint decodeHexColor(string s, uint defValue = 0) {
if (s[0] != '#') if (s[0] != '#')
return defValue; return defValue;
uint value = 0; uint value = 0;
for (int i = 1; i < s.length; i++) { foreach(i; 1 .. s.length) {
uint digit = decodeHexDigit(s[i]); uint digit = decodeHexDigit(s[i]);
if (digit == uint.max) if (digit == uint.max)
return defValue; return defValue;

View File

@ -328,14 +328,14 @@ class DrawBuf : RefCountedObject {
if (isFullyTransparentColor(color1) && isFullyTransparentColor(color2)) if (isFullyTransparentColor(color1) && isFullyTransparentColor(color2))
return; return;
// draw horizontal lines // draw horizontal lines
for (int x = rc.left; x < rc.right; x++) { foreach(int x; rc.left .. rc.right) {
if ((x ^ rc.top) & 1) if ((x ^ rc.top) & 1)
fillRect(Rect(x, rc.top, x + 1, rc.top + 1), color1); fillRect(Rect(x, rc.top, x + 1, rc.top + 1), color1);
if ((x ^ (rc.bottom - 1)) & 1) if ((x ^ (rc.bottom - 1)) & 1)
fillRect(Rect(x, rc.bottom - 1, x + 1, rc.bottom), color2); fillRect(Rect(x, rc.bottom - 1, x + 1, rc.bottom), color2);
} }
// draw vertical lines // draw vertical lines
for (int y = rc.top + 1; y < rc.bottom - 1; y++) { foreach(int y; rc.top + 1 .. rc.bottom - 1) {
uint color = color1 == color2 ? color1 : blendARGB(color2, color1, 255 / (rc.bottom - rc.top)); uint color = color1 == color2 ? color1 : blendARGB(color2, color1, 255 / (rc.bottom - rc.top));
if ((y ^ rc.left) & 1) if ((y ^ rc.left) & 1)
fillRect(Rect(rc.left, y, rc.left + 1, y + 1), color); fillRect(Rect(rc.left, y, rc.left + 1, y + 1), color);
@ -440,12 +440,12 @@ class ColorDrawBufBase : DrawBuf {
int dy = srcrect.height; int dy = srcrect.height;
ColorDrawBufBase colorDrawBuf = cast(ColorDrawBufBase) src; ColorDrawBufBase colorDrawBuf = cast(ColorDrawBufBase) src;
if (colorDrawBuf !is null) { if (colorDrawBuf !is null) {
for (int yy = 0; yy < dy; yy++) { foreach(yy; 0 .. dy) {
uint * srcrow = colorDrawBuf.scanLine(srcrect.top + yy) + srcrect.left; uint * srcrow = colorDrawBuf.scanLine(srcrect.top + yy) + srcrect.left;
uint * dstrow = scanLine(dstrect.top + yy) + dstrect.left; uint * dstrow = scanLine(dstrect.top + yy) + dstrect.left;
if (!_alpha) { if (!_alpha) {
// simplified version - no alpha blending // simplified version - no alpha blending
for (int i = 0; i < dx; i++) { foreach(i; 0 .. dx) {
uint pixel = srcrow[i]; uint pixel = srcrow[i];
uint alpha = pixel >> 24; uint alpha = pixel >> 24;
if (!alpha) if (!alpha)
@ -457,7 +457,7 @@ class ColorDrawBufBase : DrawBuf {
} }
} else { } else {
// combine two alphas // combine two alphas
for (int i = 0; i < dx; i++) { foreach(i; 0 .. dx) {
uint pixel = srcrow[i]; uint pixel = srcrow[i];
uint alpha = blendAlpha(_alpha, pixel >> 24); uint alpha = blendAlpha(_alpha, pixel >> 24);
if (!alpha) if (!alpha)
@ -480,7 +480,7 @@ class ColorDrawBufBase : DrawBuf {
int dd = dst1 - dst0; int dd = dst1 - dst0;
int sd = src1 - src0; int sd = src1 - src0;
int[] res = new int[dd]; int[] res = new int[dd];
for (int i = 0; i < dd; i++) foreach(int i; 0 .. dd)
res[i] = src0 + i * sd / dd; res[i] = src0 + i * sd / dd;
return res; return res;
} }
@ -499,12 +499,12 @@ class ColorDrawBufBase : DrawBuf {
int dy = dstrect.height; int dy = dstrect.height;
ColorDrawBufBase colorDrawBuf = cast(ColorDrawBufBase) src; ColorDrawBufBase colorDrawBuf = cast(ColorDrawBufBase) src;
if (colorDrawBuf !is null) { if (colorDrawBuf !is null) {
for (int y = 0; y < dy; y++) { foreach(y; 0 .. dy) {
uint * srcrow = colorDrawBuf.scanLine(ymap[y]); uint * srcrow = colorDrawBuf.scanLine(ymap[y]);
uint * dstrow = scanLine(dstrect.top + y) + dstrect.left; uint * dstrow = scanLine(dstrect.top + y) + dstrect.left;
if (!_alpha) { if (!_alpha) {
// simplified alpha calculation // simplified alpha calculation
for (int x = 0; x < dx; x++) { foreach(x; 0 .. dx) {
uint srcpixel = srcrow[xmap[x]]; uint srcpixel = srcrow[xmap[x]];
uint dstpixel = dstrow[x]; uint dstpixel = dstrow[x];
uint alpha = srcpixel >> 24; uint alpha = srcpixel >> 24;
@ -517,7 +517,7 @@ class ColorDrawBufBase : DrawBuf {
} }
} else { } else {
// blending two alphas // blending two alphas
for (int x = 0; x < dx; x++) { foreach(x; 0 .. dx) {
uint srcpixel = srcrow[xmap[x]]; uint srcpixel = srcrow[xmap[x]];
uint dstpixel = dstrow[x]; uint dstpixel = dstrow[x];
uint srca = srcpixel >> 24; uint srca = srcpixel >> 24;
@ -541,7 +541,7 @@ class ColorDrawBufBase : DrawBuf {
bool foundUsed = false; bool foundUsed = false;
x0 = 0; x0 = 0;
x1 = 0; x1 = 0;
for (int x = 1; x < _dx - 1; x++) { foreach(int x; 1 .. _dx - 1) {
if (isBlackPixel(line[x])) { // opaque black pixel if (isBlackPixel(line[x])) { // opaque black pixel
if (!foundUsed) { if (!foundUsed) {
x0 = x; x0 = x;
@ -570,7 +570,7 @@ class ColorDrawBufBase : DrawBuf {
bool foundUsed = false; bool foundUsed = false;
y0 = 0; y0 = 0;
y1 = 0; y1 = 0;
for (int y = 1; y < _dy - 1; y++) { foreach(int y; 1 .. _dy - 1) {
uint * line = scanLine(y); uint * line = scanLine(y);
if (isBlackPixel(line[x])) { // opaque black pixel if (isBlackPixel(line[x])) { // opaque black pixel
if (!foundUsed) { if (!foundUsed) {
@ -615,7 +615,7 @@ class ColorDrawBufBase : DrawBuf {
bool clipping = true; //!_clipRect.empty(); bool clipping = true; //!_clipRect.empty();
color = applyAlpha(color); color = applyAlpha(color);
bool subpixel = glyph.subpixelMode != SubpixelRenderingMode.None; bool subpixel = glyph.subpixelMode != SubpixelRenderingMode.None;
for (int yy = 0; yy < srcdy; yy++) { foreach(int yy; 0 .. srcdy) {
int liney = y + yy; int liney = y + yy;
if (clipping && (liney < _clipRect.top || liney >= _clipRect.bottom)) if (clipping && (liney < _clipRect.top || liney >= _clipRect.bottom))
continue; continue;
@ -623,7 +623,7 @@ class ColorDrawBufBase : DrawBuf {
continue; continue;
uint * row = scanLine(liney); uint * row = scanLine(liney);
ubyte * srcrow = src.ptr + yy * srcdx; ubyte * srcrow = src.ptr + yy * srcdx;
for (int xx = 0; xx < srcdx; xx++) { foreach(int xx; 0 .. srcdx) {
int colx = x + (subpixel ? xx / 3 : xx); int colx = x + (subpixel ? xx / 3 : xx);
if (clipping && (colx < _clipRect.left || colx >= _clipRect.right)) if (clipping && (colx < _clipRect.left || colx >= _clipRect.right))
continue; continue;
@ -657,7 +657,7 @@ class ColorDrawBufBase : DrawBuf {
int srcdx = glyph.blackBoxX; int srcdx = glyph.blackBoxX;
int srcdy = glyph.blackBoxY; int srcdy = glyph.blackBoxY;
bool subpixel = glyph.subpixelMode != SubpixelRenderingMode.None; bool subpixel = glyph.subpixelMode != SubpixelRenderingMode.None;
for (int yy = 0; yy < srcdy; yy++) { foreach(int yy; 0 .. srcdy) {
int liney = y + yy; int liney = y + yy;
uint * row = scanLine(liney); uint * row = scanLine(liney);
ubyte * srcrow = src.ptr + yy * srcdx; ubyte * srcrow = src.ptr + yy * srcdx;
@ -684,13 +684,13 @@ class ColorDrawBufBase : DrawBuf {
override void fillRect(Rect rc, uint color) { override void fillRect(Rect rc, uint color) {
if (applyClipping(rc)) { if (applyClipping(rc)) {
for (int y = rc.top; y < rc.bottom; y++) { foreach(y; rc.top .. rc.bottom) {
uint * row = scanLine(y); uint * row = scanLine(y);
uint alpha = color >> 24; uint alpha = color >> 24;
if (!alpha) { if (!alpha) {
row[rc.left .. rc.right] = color; row[rc.left .. rc.right] = color;
} else if (alpha < 254) { } else if (alpha < 254) {
for (int x = rc.left; x < rc.right; x++) { foreach(x; rc.left .. rc.right) {
// apply blending // apply blending
row[x] = blendARGB(row[x], color, alpha); row[x] = blendARGB(row[x], color, alpha);
} }
@ -749,7 +749,7 @@ class GrayDrawBuf : DrawBuf {
int len = _dx * _dy; int len = _dx * _dy;
ubyte * p = _buf.ptr; ubyte * p = _buf.ptr;
ubyte cl = rgbToGray(color); ubyte cl = rgbToGray(color);
for (int i = 0; i < len; i++) foreach(i; 0 .. len)
p[i] = cl; p[i] = cl;
} }
@ -762,10 +762,10 @@ class GrayDrawBuf : DrawBuf {
int dy = srcrect.height; int dy = srcrect.height;
GrayDrawBuf grayDrawBuf = cast (GrayDrawBuf) src; GrayDrawBuf grayDrawBuf = cast (GrayDrawBuf) src;
if (grayDrawBuf !is null) { if (grayDrawBuf !is null) {
for (int yy = 0; yy < dy; yy++) { foreach(yy; 0 .. dy) {
ubyte * srcrow = grayDrawBuf.scanLine(srcrect.top + yy) + srcrect.left; ubyte * srcrow = grayDrawBuf.scanLine(srcrect.top + yy) + srcrect.left;
ubyte * dstrow = scanLine(dstrect.top + yy) + dstrect.left; ubyte * dstrow = scanLine(dstrect.top + yy) + dstrect.left;
for (int i = 0; i < dx; i++) { foreach(i; 0 .. dx) {
ubyte pixel = srcrow[i]; ubyte pixel = srcrow[i];
dstrow[i] = pixel; dstrow[i] = pixel;
} }
@ -780,7 +780,7 @@ class GrayDrawBuf : DrawBuf {
int dd = dst1 - dst0; int dd = dst1 - dst0;
int sd = src1 - src0; int sd = src1 - src0;
int[] res = new int[dd]; int[] res = new int[dd];
for (int i = 0; i < dd; i++) foreach(int i; 0 .. dd)
res[i] = src0 + i * sd / dd; res[i] = src0 + i * sd / dd;
return res; return res;
} }
@ -794,10 +794,10 @@ class GrayDrawBuf : DrawBuf {
int dy = dstrect.height; int dy = dstrect.height;
GrayDrawBuf grayDrawBuf = cast (GrayDrawBuf) src; GrayDrawBuf grayDrawBuf = cast (GrayDrawBuf) src;
if (grayDrawBuf !is null) { if (grayDrawBuf !is null) {
for (int y = 0; y < dy; y++) { foreach(y; 0 .. dy) {
ubyte * srcrow = grayDrawBuf.scanLine(ymap[y]); ubyte * srcrow = grayDrawBuf.scanLine(ymap[y]);
ubyte * dstrow = scanLine(dstrect.top + y) + dstrect.left; ubyte * dstrow = scanLine(dstrect.top + y) + dstrect.left;
for (int x = 0; x < dx; x++) { foreach(x; 0 .. dx) {
ubyte srcpixel = srcrow[xmap[x]]; ubyte srcpixel = srcrow[xmap[x]];
ubyte dstpixel = dstrow[x]; ubyte dstpixel = dstrow[x];
dstrow[x] = srcpixel; dstrow[x] = srcpixel;
@ -813,7 +813,7 @@ class GrayDrawBuf : DrawBuf {
bool foundUsed = false; bool foundUsed = false;
x0 = 0; x0 = 0;
x1 = 0; x1 = 0;
for (int x = 1; x < _dx - 1; x++) { foreach(int x; 1 .. _dx - 1) {
if (line[x] == 0x00000000) { // opaque black pixel if (line[x] == 0x00000000) { // opaque black pixel
if (!foundUsed) { if (!foundUsed) {
x0 = x; x0 = x;
@ -830,7 +830,7 @@ class GrayDrawBuf : DrawBuf {
bool foundUsed = false; bool foundUsed = false;
y0 = 0; y0 = 0;
y1 = 0; y1 = 0;
for (int y = 1; y < _dy - 1; y++) { foreach(int y; 1 .. _dy - 1) {
ubyte * line = scanLine(y); ubyte * line = scanLine(y);
if (line[x] == 0x00000000) { // opaque black pixel if (line[x] == 0x00000000) { // opaque black pixel
if (!foundUsed) { if (!foundUsed) {
@ -871,7 +871,7 @@ class GrayDrawBuf : DrawBuf {
int srcdx = glyph.blackBoxX; int srcdx = glyph.blackBoxX;
int srcdy = glyph.blackBoxY; int srcdy = glyph.blackBoxY;
bool clipping = true; //!_clipRect.empty(); bool clipping = true; //!_clipRect.empty();
for (int yy = 0; yy < srcdy; yy++) { foreach(int yy; 0 .. srcdy) {
int liney = y + yy; int liney = y + yy;
if (clipping && (liney < _clipRect.top || liney >= _clipRect.bottom)) if (clipping && (liney < _clipRect.top || liney >= _clipRect.bottom))
continue; continue;
@ -879,7 +879,7 @@ class GrayDrawBuf : DrawBuf {
continue; continue;
ubyte * row = scanLine(liney); ubyte * row = scanLine(liney);
ubyte * srcrow = src.ptr + yy * srcdx; ubyte * srcrow = src.ptr + yy * srcdx;
for (int xx = 0; xx < srcdx; xx++) { foreach(int xx; 0 .. srcdx) {
int colx = xx + x; int colx = xx + x;
if (clipping && (colx < _clipRect.left || colx >= _clipRect.right)) if (clipping && (colx < _clipRect.left || colx >= _clipRect.right))
continue; continue;
@ -902,9 +902,9 @@ class GrayDrawBuf : DrawBuf {
if (applyClipping(rc)) { if (applyClipping(rc)) {
uint alpha = color >> 24; uint alpha = color >> 24;
ubyte cl = rgbToGray(color); ubyte cl = rgbToGray(color);
for (int y = rc.top; y < rc.bottom; y++) { foreach(y; rc.top .. rc.bottom) {
ubyte * row = scanLine(y); ubyte * row = scanLine(y);
for (int x = rc.left; x < rc.right; x++) { foreach(x; rc.left .. rc.right) {
if (!alpha) if (!alpha)
row[x] = cl; row[x] = cl;
else if (alpha < 255) { else if (alpha < 255) {
@ -943,7 +943,7 @@ class ColorDrawBuf : ColorDrawBufBase {
this(ColorDrawBuf v) { this(ColorDrawBuf v) {
this(v.width, v.height); this(v.width, v.height);
//_buf.length = v._buf.length; //_buf.length = v._buf.length;
for (int i = 0; i < _buf.length; i++) foreach(i; 0 .. _buf.length)
_buf[i] = v._buf[i]; _buf[i] = v._buf[i];
} }
/// create resized copy of ColorDrawBuf /// create resized copy of ColorDrawBuf
@ -983,7 +983,7 @@ class ColorDrawBuf : ColorDrawBufBase {
} }
int len = _dx * _dy; int len = _dx * _dy;
uint * p = _buf.ptr; uint * p = _buf.ptr;
for (int i = 0; i < len; i++) foreach(i; 0 .. len)
p[i] = color; p[i] = color;
} }
override DrawBuf transformColors(ref ColorTransform transform) { override DrawBuf transformColors(ref ColorTransform transform) {
@ -996,11 +996,11 @@ class ColorDrawBuf : ColorDrawBufBase {
*p = *_ninePatch; *p = *_ninePatch;
res.ninePatch = p; res.ninePatch = p;
} }
for (int y = 0; y < _dy; y++) { foreach(int y; 0 .. _dy) {
uint * srcline = scanLine(y); uint * srcline = scanLine(y);
uint * dstline = res.scanLine(y); uint * dstline = res.scanLine(y);
bool allowTransformY = !skipFrame || (y !=0 && y != _dy - 1); bool allowTransformY = !skipFrame || (y !=0 && y != _dy - 1);
for (int x = 0; x < _dx; x++) { foreach(int x; 0 .. _dx) {
bool allowTransformX = !skipFrame || (x !=0 && x != _dx - 1); bool allowTransformX = !skipFrame || (x !=0 && x != _dx - 1);
if (!allowTransformX || !allowTransformY) if (!allowTransformX || !allowTransformY)
dstline[x] = srcline[x]; dstline[x] = srcline[x];

View File

@ -220,7 +220,7 @@ class Font : RefCountedObject {
tabOffset = tabOffset % tabWidth; tabOffset = tabOffset % tabWidth;
if (tabOffset < 0) if (tabOffset < 0)
tabOffset += tabWidth; tabOffset += tabWidth;
for (int i = 0; i < len; i++) { foreach(int i; 0 .. len) {
//auto measureStart = std.datetime.Clock.currAppTick; //auto measureStart = std.datetime.Clock.currAppTick;
dchar ch = pstr[i]; dchar ch = pstr[i];
if (ch == '\t') { if (ch == '\t') {
@ -308,7 +308,7 @@ class Font : RefCountedObject {
bool underline = (textFlags & TextFlag.Underline) != 0; bool underline = (textFlags & TextFlag.Underline) != 0;
int underlineHeight = 1; int underlineHeight = 1;
int underlineY = y + _baseline + underlineHeight * 2; int underlineY = y + _baseline + underlineHeight * 2;
for (int i = 0; i < charsMeasured; i++) { foreach(int i; 0 .. charsMeasured) {
dchar ch = text[i]; dchar ch = text[i];
if (ch == '&' && (textFlags & (TextFlag.UnderlineHotKeys | TextFlag.HotKeys | TextFlag.UnderlineHotKeysWhenAltPressed))) { if (ch == '&' && (textFlags & (TextFlag.UnderlineHotKeys | TextFlag.HotKeys | TextFlag.UnderlineHotKeysWhenAltPressed))) {
if (textFlags & (TextFlag.UnderlineHotKeys | TextFlag.UnderlineHotKeysWhenAltPressed)) if (textFlags & (TextFlag.UnderlineHotKeys | TextFlag.UnderlineHotKeysWhenAltPressed))
@ -377,7 +377,7 @@ class Font : RefCountedObject {
bool underline = (customizedTextFlags & TextFlag.Underline) != 0; bool underline = (customizedTextFlags & TextFlag.Underline) != 0;
int underlineHeight = 1; int underlineHeight = 1;
int underlineY = y + _baseline + underlineHeight * 2; int underlineY = y + _baseline + underlineHeight * 2;
for (int i = 0; i < charsMeasured; i++) { foreach(int i; 0 .. charsMeasured) {
dchar ch = text[i]; dchar ch = text[i];
uint color = i < charProps.length ? charProps[i].color : charProps[$ - 1].color; uint color = i < charProps.length ? charProps[i].color : charProps[$ - 1].color;
customizedTextFlags = (i < charProps.length ? charProps[i].textFlags : charProps[$ - 1].textFlags) | textFlags; customizedTextFlags = (i < charProps.length ? charProps[i].textFlags : charProps[$ - 1].textFlags) | textFlags;
@ -478,7 +478,7 @@ struct SimpleTextFormatter {
int lastWordEnd = 0; int lastWordEnd = 0;
int lastWordEndX = 0; int lastWordEndX = 0;
dchar prevChar = 0; dchar prevChar = 0;
for (int i = 0; i <= charsMeasured; i++) { foreach(int i; 0 .. charsMeasured + 1) {
dchar ch = i < charsMeasured ? text[i] : 0; dchar ch = i < charsMeasured ? text[i] : 0;
if (ch == '\n' || i == charsMeasured) { if (ch == '\n' || i == charsMeasured) {
// split by EOL char or at end of text // split by EOL char or at end of text
@ -547,9 +547,8 @@ struct SimpleTextFormatter {
/// draw formatted text /// draw formatted text
void draw(DrawBuf buf, int x, int y, FontRef fnt, uint color) { void draw(DrawBuf buf, int x, int y, FontRef fnt, uint color) {
int lineHeight = fnt.height; int lineHeight = fnt.height;
for (int i = 0; i < _lines.length; i++) { foreach(line; _lines) {
dstring line = _lines[i]; fnt.drawText(buf, x, y, line, color, _tabSize, _tabOffset, _textFlags);
fnt.drawText(buf, x, y, line, color, _tabSize, _tabOffset, _textFlags);
y += lineHeight; y += lineHeight;
} }
} }
@ -569,7 +568,7 @@ struct FontList {
} }
void clear() { void clear() {
for (uint i = 0; i < _len; i++) { foreach(i; 0 .. _len) {
_list[i].clear(); _list[i].clear();
_list[i] = null; _list[i] = null;
} }
@ -581,7 +580,7 @@ struct FontList {
} }
// find by a set of parameters - returns index of found item, -1 if not found // find by a set of parameters - returns index of found item, -1 if not found
int find(int size, int weight, bool italic, FontFamily family, string face) { int find(int size, int weight, bool italic, FontFamily family, string face) {
for (int i = 0; i < _len; i++) { foreach(int i; 0 .. _len) {
Font item = _list[i].get; Font item = _list[i].get;
if (item.family != family) if (item.family != family)
continue; continue;
@ -597,7 +596,7 @@ struct FontList {
} }
// find by size only - returns index of found item, -1 if not found // find by size only - returns index of found item, -1 if not found
int find(int size) { int find(int size) {
for (int i = 0; i < _len; i++) { foreach(int i; 0 .. _len) {
Font item = _list[i].get; Font item = _list[i].get;
if (item.size != size) if (item.size != size)
continue; continue;
@ -616,27 +615,27 @@ struct FontList {
} }
// remove unused items - with reference == 1 // remove unused items - with reference == 1
void cleanup() { void cleanup() {
for (int i = 0; i < _len; i++) foreach(i; 0 .. _len)
if (_list[i].refCount <= 1) if (_list[i].refCount <= 1)
_list[i].clear(); _list[i].clear();
int dst = 0; uint dst = 0;
for (int i = 0; i < _len; i++) { foreach(i; 0 .. _len) {
if (!_list[i].isNull) if (!_list[i].isNull)
if (i != dst) if (i != dst)
_list[dst++] = _list[i]; _list[dst++] = _list[i];
} }
_len = dst; _len = dst;
for (int i = 0; i < _len; i++) foreach(i; 0 .. _len)
_list[i].cleanup(); _list[i].cleanup();
} }
void checkpoint() { void checkpoint() {
for (int i = 0; i < _len; i++) foreach(i; 0 .. _len)
_list[i].checkpoint(); _list[i].checkpoint();
} }
/// clears glyph cache /// clears glyph cache
void clearGlyphCache() { void clearGlyphCache() {
for (int i = 0; i < _len; i++) foreach(i; 0 .. _len)
_list[i].clearGlyphCache(); _list[i].clearGlyphCache();
} }
} }
@ -865,7 +864,7 @@ struct glyph_gamma_table(int maxv = 65)
@property double gamma() { return _gamma; } @property double gamma() { return _gamma; }
@property void gamma(double g) { @property void gamma(double g) {
_gamma = g; _gamma = g;
for(int i = 0; i < maxv; i++) foreach(int i; 0 .. maxv)
{ {
double v = (maxv - 1.0 - i) / maxv; double v = (maxv - 1.0 - i) / maxv;
v = pow(v, g); v = pow(v, g);

View File

@ -301,10 +301,10 @@ class FreeTypeFontFile {
ubyte mask = 0x80; ubyte mask = 0x80;
ubyte * ptr = bitmap.buffer; ubyte * ptr = bitmap.buffer;
ubyte * dst = glyph.glyph.ptr; ubyte * dst = glyph.glyph.ptr;
for ( int y=0; y<h; y++ ) { foreach(y; 0 .. h) {
ubyte * row = ptr; ubyte * row = ptr;
mask = 0x80; mask = 0x80;
for ( int x=0; x<w; x++ ) { foreach(x; 0 .. w) {
*dst++ = (*row & mask) ? 0xFF : 00; *dst++ = (*row & mask) ? 0xFF : 00;
mask >>= 1; mask >>= 1;
if ( !mask && x != w-1) { if ( !mask && x != w-1) {
@ -317,8 +317,8 @@ class FreeTypeFontFile {
} else { } else {
// antialiased // antialiased
for (uint y = 0; y < h; y++) { foreach(y; 0 .. h) {
for (uint x = 0; x < w; x++) { foreach(x; 0 .. w) {
glyph.glyph[y * w + x] = _gamma256.correct(bitmap.buffer[y * bitmap.pitch + x]); glyph.glyph[y * w + x] = _gamma256.correct(bitmap.buffer[y * bitmap.pitch + x]);
} }
} }
@ -516,7 +516,7 @@ class FreeTypeFontManager : FontManager {
int score = 0; int score = 0;
int bestFaceMatch = 0; int bestFaceMatch = 0;
if (faces && face.length) { if (faces && face.length) {
for (int i = 0; i < faces.length; i++) { foreach(i; 0 .. faces.length) {
string f = faces[i].strip; string f = faces[i].strip;
if (f.icmp(item.def.face) == 0) { if (f.icmp(item.def.face) == 0) {
score += 3000 - i; score += 3000 - i;
@ -695,7 +695,7 @@ bool registerFontConfigFonts(FreeTypeFontManager fontMan) {
// load fonts from file // load fonts from file
//CRLog::debug("FONTCONFIG: %d font files found", fontset->nfont); //CRLog::debug("FONTCONFIG: %d font files found", fontset->nfont);
for(int i = 0; i < fontset.nfont; i++) { foreach(i; 0 .. fontset.nfont) {
const (FcChar8) *s = "".toStringz; const (FcChar8) *s = "".toStringz;
const (FcChar8) *family = "".toStringz; const (FcChar8) *family = "".toStringz;
const (FcChar8) *style = "".toStringz; const (FcChar8) *style = "".toStringz;

View File

@ -471,7 +471,7 @@ private class GLImageCache {
private void removePage(GLImageCachePage page) { private void removePage(GLImageCachePage page) {
if (_activePage == page) if (_activePage == page)
_activePage = null; _activePage = null;
for (int i = 0; i < _pages.length; i++) foreach(i; 0 .. _pages.length)
if (_pages[i] == page) { if (_pages[i] == page) {
_pages.remove(i); _pages.remove(i);
break; break;
@ -526,7 +526,7 @@ private class GLImageCache {
} }
/// clears cache /// clears cache
void clear() { void clear() {
for (int i = 0; i < _pages.length; i++) { foreach(i; 0 .. _pages.length) {
destroy(_pages[i]); destroy(_pages[i]);
_pages[i] = null; _pages[i] = null;
} }
@ -565,7 +565,7 @@ private class GLImageCache {
if (item._deleted) if (item._deleted)
list ~= item._objectId; list ~= item._objectId;
} }
for (int i = 0 ; i < list.length; i++) { foreach(i; 0 .. list.length) {
onCachedObjectDeleted(list[i]); onCachedObjectDeleted(list[i]);
} }
} }
@ -767,7 +767,7 @@ private class GLGlyphCache {
void removePage(GLGlyphCachePage page) { void removePage(GLGlyphCachePage page) {
if (_activePage == page) if (_activePage == page)
_activePage = null; _activePage = null;
for (int i = 0; i < _pages.length; i++) foreach(i; 0 .. _pages.length)
if (_pages[i] == page) { if (_pages[i] == page) {
_pages.remove(i); _pages.remove(i);
break; break;
@ -811,7 +811,7 @@ private class GLGlyphCache {
_map[glyph.id] = res; _map[glyph.id] = res;
} }
void clear() { void clear() {
for (int i = 0; i < _pages.length; i++) { foreach(i; 0 .. _pages.length) {
destroy(_pages[i]); destroy(_pages[i]);
_pages[i] = null; _pages[i] = null;
} }
@ -849,7 +849,7 @@ private class GLGlyphCache {
if (item._deleted) if (item._deleted)
list ~= item._objectId; list ~= item._objectId;
} }
for (int i = 0 ; i < list.length; i++) { foreach(i; 0 .. list.length) {
onCachedObjectDeleted(list[i]); onCachedObjectDeleted(list[i]);
} }
} }

View File

@ -88,9 +88,9 @@ ColorDrawBuf loadImage(immutable ubyte[] data, string filename) {
ColorDrawBuf buf = new ColorDrawBuf(w, h); ColorDrawBuf buf = new ColorDrawBuf(w, h);
Color_RGBA[] pixels = image.rgba.allPixels; Color_RGBA[] pixels = image.rgba.allPixels;
int index = 0; int index = 0;
for (int y = 0; y < h; y++) { foreach(y; 0 .. h) {
uint * dstLine = buf.scanLine(y); uint * dstLine = buf.scanLine(y);
for (int x = 0; x < w; x++) { foreach(x; 0 .. w) {
Color_RGBA * pixel = &pixels[index + x]; Color_RGBA * pixel = &pixels[index + x];
dstLine[x] = makeRGBA(pixel.r_ubyte, pixel.g_ubyte, pixel.b_ubyte, pixel.a_ubyte); dstLine[x] = makeRGBA(pixel.r_ubyte, pixel.g_ubyte, pixel.b_ubyte, pixel.a_ubyte);
} }
@ -182,9 +182,9 @@ version (USE_DLIBIMAGE) {
int w = image.width; int w = image.width;
int h = image.height; int h = image.height;
ColorDrawBuf buf = new ColorDrawBuf(w, h); ColorDrawBuf buf = new ColorDrawBuf(w, h);
for (int y = 0; y < h; y++) { foreach(y; 0 .. h) {
uint * dstLine = buf.scanLine(y); uint * dstLine = buf.scanLine(y);
for (int x = 0; x < w; x++) { foreach(x; 0 .. w) {
auto pixel = image[x, y].convert(8); auto pixel = image[x, y].convert(8);
dstLine[x] = makeRGBA(pixel.r, pixel.g, pixel.b, 255 - pixel.a); dstLine[x] = makeRGBA(pixel.r, pixel.g, pixel.b, 255 - pixel.a);
} }
@ -198,9 +198,9 @@ version (USE_DIMAGE) {
int w = image.width; int w = image.width;
int h = image.height; int h = image.height;
ColorDrawBuf buf = new ColorDrawBuf(w, h); ColorDrawBuf buf = new ColorDrawBuf(w, h);
for (int y = 0; y < h; y++) { foreach(y; 0 .. h) {
uint * dstLine = buf.scanLine(y); uint * dstLine = buf.scanLine(y);
for (int x = 0; x < w; x++) { foreach(x; 0 .. w) {
uint pixel = image[x, y]; uint pixel = image[x, y];
dstLine[x] = pixel ^ 0xFF000000; dstLine[x] = pixel ^ 0xFF000000;
} }

View File

@ -701,7 +701,7 @@ class StateDrawable : Drawable {
uint[4] nn; uint[4] nn;
if (!parseList4!float(value, n)) if (!parseList4!float(value, n))
return COLOR_TRANSFORM_MULTIPLY_NONE; return COLOR_TRANSFORM_MULTIPLY_NONE;
for(int i = 0; i < 4; i++) { foreach(i; 0 .. 4) {
int res = cast(int)(n[i] * 0x40); int res = cast(int)(n[i] * 0x40);
if (res < 0) if (res < 0)
res = 0; res = 0;

View File

@ -135,7 +135,7 @@ ColorDrawBuf parseXPM(const(ubyte)[] data)
uint* dstLine = colorBuf.scanLine(y); uint* dstLine = colorBuf.scanLine(y);
if (str.length) { if (str.length) {
enforce(str.length >= w*cpp, "Invalid pixel line"); enforce(str.length >= w*cpp, "Invalid pixel line");
for (int x=0; x < w; x++) { foreach(int x; 0 .. w) {
auto pixelStr = str[x*cpp..(x+1)*cpp]; auto pixelStr = str[x*cpp..(x+1)*cpp];
auto colorPtr = xpmHash(pixelStr) in colorMap; auto colorPtr = xpmHash(pixelStr) in colorMap;
enforce(colorPtr, "Unknown pixel : '" ~ str ~ "'"); enforce(colorPtr, "Unknown pixel : '" ~ str ~ "'");