# HG changeset patch # User John Tsiombikas # Date 1436311896 -10800 # Node ID 3e6430028d54b185902fbed449b60ee5ce3f10de # Parent c2a2069a49ec75ef4b5e530807b6802eb39b340e slot highlghting diff -r c2a2069a49ec -r 3e6430028d54 src/board.cc --- a/src/board.cc Tue Jul 07 21:56:37 2015 +0300 +++ b/src/board.cc Wed Jul 08 02:31:36 2015 +0300 @@ -268,7 +268,7 @@ glBegin(GL_TRIANGLES); //glColor3fv(pal[idx % (sizeof pal / sizeof *pal)]); - glColor4f(1, 1, 1, 0.4); + glColor4f(1, 1, 1, 0.5); glTexCoord2f(0, 0); glVertex3f(slotbb[idx].tri0.v[0].x, slotbb[idx].tri0.v[0].y, slotbb[idx].tri0.v[0].z); glTexCoord2f(1, 0); @@ -572,6 +572,9 @@ } img_highlight.texture(); + float kern[] = {1, 5, 11, 18, 22, 18, 11, 5, 1}; + convolve_horiz_image(&img_highlight, kern, sizeof kern / sizeof *kern); + convolve_vert_image(&img_highlight, kern, sizeof kern / sizeof *kern); // ---- generic wood texture ---- img_wood.create(256, 256); diff -r c2a2069a49ec -r 3e6430028d54 src/image.cc --- a/src/image.cc Tue Jul 07 21:56:37 2015 +0300 +++ b/src/image.cc Wed Jul 08 02:31:36 2015 +0300 @@ -1,4 +1,5 @@ #include +#include #include "opengl.h" #include "image.h" #include "imago2.h" @@ -233,6 +234,119 @@ return true; } +void convolve_horiz_image(Image *dest, float *kern, int ksz, float scale) +{ + if((ksz & 1) == 0) { + fprintf(stderr, "%s: kernel size (%d) must be odd, skipping last value\n", __FUNCTION__, ksz); + --ksz; + } + if(scale == 0.0) { + // calculate scale factor + float sum = 0.0; + for(int i=0; iwidth * 4 * sizeof *buf); + unsigned char *sptr = dest->pixels; + + for(int i=0; iheight; i++) { + float *bptr = buf; + for(int j=0; jwidth * 4; j++) { + *bptr++ = (float)(sptr[j] / 255.0); + } + + for(int j=0; jwidth; j++) { + float col[] = {0, 0, 0, 0}; + + for(int k=0; k= dest->width) idx = dest->width - 1; + + col[0] += buf[idx * 4] * kern[k]; + col[1] += buf[idx * 4 + 1] * kern[k]; + col[2] += buf[idx * 4 + 2] * kern[k]; + col[3] += buf[idx * 4 + 3] * kern[k]; + } + + int ri = (int)(col[0] * scale * 255.0); + int gi = (int)(col[1] * scale * 255.0); + int bi = (int)(col[2] * scale * 255.0); + int ai = (int)(col[3] * scale * 255.0); + + sptr[0] = ri < 0 ? 0 : (ri > 255 ? 255 : ri); + sptr[1] = gi < 0 ? 0 : (gi > 255 ? 255 : gi); + sptr[2] = bi < 0 ? 0 : (bi > 255 ? 255 : bi); + sptr[3] = ai < 0 ? 0 : (ai > 255 ? 255 : ai); + sptr += 4; + } + } + + dest->invalidate_texture(); +} + +void convolve_vert_image(Image *dest, float *kern, int ksz, float scale) +{ + if((ksz & 1) == 0) { + fprintf(stderr, "%s: kernel size (%d) must be odd, skipping last value\n", __FUNCTION__, ksz); + --ksz; + } + if(scale == 0.0) { + // calculate scale factor + float sum = 0.0; + for(int i=0; iheight * 4 * sizeof *buf); + unsigned char *sptr = dest->pixels; + + for(int i=0; iwidth; i++) { + float *bptr = buf; + sptr = dest->pixels + i * 4; + + for(int j=0; jheight; j++) { + for(int k=0; k<4; k++) { + *bptr++ = (float)(sptr[k] / 255.0); + } + sptr += dest->width * 4; + } + + sptr = dest->pixels + i * 4; + + for(int j=0; jheight; j++) { + float col[] = {0, 0, 0, 0}; + + for(int k=0; k= dest->height) idx = dest->height - 1; + + col[0] += buf[idx * 4] * kern[k]; + col[1] += buf[idx * 4 + 1] * kern[k]; + col[2] += buf[idx * 4 + 2] * kern[k]; + col[3] += buf[idx * 4 + 3] * kern[k]; + } + + int ri = (int)(col[0] * scale * 255.0); + int gi = (int)(col[1] * scale * 255.0); + int bi = (int)(col[2] * scale * 255.0); + int ai = (int)(col[3] * scale * 255.0); + + sptr[0] = ri < 0 ? 0 : (ri > 255 ? 255 : ri); + sptr[1] = gi < 0 ? 0 : (gi > 255 ? 255 : gi); + sptr[2] = bi < 0 ? 0 : (bi > 255 ? 255 : bi); + sptr[3] = ai < 0 ? 0 : (ai > 255 ? 255 : ai); + sptr += dest->width * 4; + } + } +} + static unsigned int next_pow2(unsigned int x) { x--; diff -r c2a2069a49ec -r 3e6430028d54 src/image.h --- a/src/image.h Tue Jul 07 21:56:37 2015 +0300 +++ b/src/image.h Wed Jul 08 02:31:36 2015 +0300 @@ -42,4 +42,7 @@ bool combine_image(Image *dest, const Image *aimg, const Image *bimg, ImgCombine op = IMG_OP_LERP, float t = 0.5); +void convolve_horiz_image(Image *dest, float *kern, int ksz, float scale = 0.0); +void convolve_vert_image(Image *dest, float *kern, int ksz, float scale = 0.0); + #endif // IMAGE_H_