aboutsummaryrefslogtreecommitdiff
path: root/generic/Image.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/Image.c')
-rw-r--r--generic/Image.c126
1 files changed, 122 insertions, 4 deletions
diff --git a/generic/Image.c b/generic/Image.c
index 33d7c8c..1474291 100644
--- a/generic/Image.c
+++ b/generic/Image.c
@@ -95,9 +95,11 @@ GetImageBits(ZnWindow win,
Tk_SizeOfImage(image, &width, &height);
im_bits = (ImageBits *) ZnMalloc(sizeof(ImageBits));
#ifdef LIBART
-#ifdef SHM
im_bits->pixbuf = NULL;
#endif
+#ifdef GLX
+ im_bits->texture = 0;
+ im_bits->i_bits = NULL;
#endif
im_bits->pixmaps = NULL;
im_bits->b_bits = NULL;
@@ -201,11 +203,15 @@ InvalidateImage(char *image_name)
ZnFree(im_bits->b_bits);
}
#ifdef LIBART
-#ifdef SHM
if (im_bits->pixbuf) {
art_pixbuf_free(im_bits->pixbuf);
}
#endif
+#ifdef GLX
+ if (im_bits->texture) {
+ ZnFree(im_bits->i_bits);
+ glDeleteTextures(1, &im_bits->texture);
+ }
#endif
ZnFree(im_bits);
Tcl_DeleteHashEntry(entry);
@@ -1297,10 +1303,9 @@ tile_svp_alpha(const ArtSVP *svp,
}
}
-#ifdef SHM
/*
* Working only for 16 bits displays with 5r6g5b mask.
- */
+ */
ArtPixBuf *
GetImagePixbuf(ZnWindow win,
char *image_name,
@@ -1358,4 +1363,117 @@ GetImagePixbuf(ZnWindow win,
return im_bits->pixbuf;
}
#endif
+
+#ifdef GLX
+/*
+ * Working only for 16 bits displays with 5r6g5b mask.
+ * Need more work at least to support 24 and 32 bit displays.
+ */
+void
+From5r6g5b(unsigned char *data,
+ int width,
+ int height,
+ int bytes_per_line,
+ int t_width,
+ int t_height,
+ BitmapBits *b_bits,
+ unsigned char *i_bits)
+{
+ int x, y;
+ int rowstride = t_width * 4;
+ unsigned char *obptr;
+ unsigned char *bptr, *bp2;
+ unsigned char alpha;
+ unsigned short temp;
+
+ bptr = i_bits;
+
+ for (y = 0; y < height; y++) {
+ bp2 = bptr;
+ obptr = data;
+ for (x = 0; x < width; x++) {
+ /*
+ * Configure the alpha value.
+ */
+ alpha = GetBitmapPixel(b_bits, x, y) ? 255 : 0;
+ alpha = 255;
+ /*
+ * Dispatch the 3 color components.
+ */
+ temp = ((unsigned short *)obptr)[0];
+ *bp2 = (temp >> 8) & 0xf8; /* r */
+ bp2++;
+ *bp2 = (temp >> 3) & 0xfc; /* v */
+ bp2++;
+ *bp2 = (temp << 3); /* b */
+ bp2++;
+ *bp2 = alpha;
+ bp2++;
+ obptr += 2;
+ }
+ for (x = width; x < t_width; x++) {
+ *bp2 = 0;
+ bp2++;
+ *bp2 = 0;
+ bp2++;
+ *bp2 = 0;
+ bp2++;
+ *bp2 = 0;
+ bp2++;
+ }
+ bptr += rowstride;
+ data += bytes_per_line;
+ }
+ for (y = height; y < t_height; y++) {
+ memset(bptr, 0, rowstride);
+ bptr += rowstride;
+ }
+}
+
+static int
+To2Power(int a)
+{
+ int result = 1;
+
+ while (result < a) {
+ result *= 2;
+ }
+ return result;
+}
+
+ImageBits *
+GetImageTexture(ZnWindow win,
+ char *image_name,
+ ZnImage image)
+{
+ ImageBits *im_bits;
+ int t_width, t_height;
+
+ im_bits = GetImageBits(win, image_name, image);
+ if (!im_bits->i_bits) {
+ t_width = To2Power(im_bits->width);
+ t_height = To2Power(im_bits->height);
+ im_bits->s = im_bits->width / (ZnReal) t_width;
+ im_bits->t = im_bits->height / (ZnReal) t_height;
+ im_bits->i_bits = ZnMalloc(t_width * 4 * t_height);
+ From5r6g5b(im_bits->pixels->data, im_bits->width, im_bits->height,
+ im_bits->pixels->bytes_per_line, t_width, t_height,
+ im_bits->b_bits, im_bits->i_bits);
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glGenTextures(1, &im_bits->texture);
+ /*printf("creation texture %d pour image %s\n", im_bits->texture, image_name);*/
+ glBindTexture(GL_TEXTURE_2D, im_bits->texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ t_width, t_height,
+ 0, GL_RGBA, GL_UNSIGNED_BYTE,
+ im_bits->i_bits);
+ }
+
+ return im_bits;
+}
#endif