void glopTexImage2D(GLContext *c, GLParam *p) { int target = p[1].i; int level = p[2].i; int components = p[3].i; int width = p[4].i; int height = p[5].i; int border = p[6].i; int format = p[7].i; int type = p[8].i; void *pixels = p[9].p; GLImage *im; byte *pixels1; bool do_free_after_rgb2rgba = false; Graphics::PixelFormat sourceFormat; switch (format) { case TGL_RGBA: sourceFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); break; case TGL_RGB: sourceFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0); break; case TGL_BGRA: sourceFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); break; case TGL_BGR: sourceFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0); break; default: error("glTexImage2D: Pixel format not handled."); } Graphics::PixelFormat pf; switch (format) { case TGL_RGBA: case TGL_RGB: pf = Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); break; case TGL_BGRA: case TGL_BGR: pf = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); break; default: break; } int bytes = pf.bytesPerPixel; // Simply unpack RGB into RGBA with 255 for Alpha. // FIXME: This will need additional checks when we get around to adding 24/32-bit backend. if (target == TGL_TEXTURE_2D && level == 0 && components == 3 && border == 0) { if (format == TGL_RGB || format == TGL_BGR) { Graphics::PixelBuffer temp(pf, width * height, DisposeAfterUse::NO); Graphics::PixelBuffer pixPtr(sourceFormat, (byte *)pixels); for (int i = 0; i < width * height; ++i) { uint8 r, g, b; pixPtr.getRGBAt(i, r, g, b); temp.setPixelAt(i, 255, r, g, b); } format = TGL_RGBA; pixels = temp.getRawBuffer(); do_free_after_rgb2rgba = true; } } else if (!(target == TGL_TEXTURE_2D && level == 0 && components == 3 && border == 0 && format == TGL_RGBA && type == TGL_UNSIGNED_BYTE)) { error("glTexImage2D: combination of parameters not handled"); } pixels1 = new byte[256 * 256 * bytes]; if (width != 256 || height != 256) { // no interpolation is done here to respect the original image aliasing ! //gl_resizeImageNoInterpolate(pixels1, 256, 256, (unsigned char *)pixels, width, height); // used interpolation anyway, it look much better :) --- aquadran gl_resizeImage(pixels1, 256, 256, (byte *)pixels, width, height); width = 256; height = 256; } else { memcpy(pixels1, pixels, 256 * 256 * bytes); } im = &c->current_texture->images[level]; im->xsize = width; im->ysize = height; if (im->pixmap) im->pixmap.free(); im->pixmap = Graphics::PixelBuffer(pf, pixels1); if (do_free_after_rgb2rgba) gl_free(pixels); }
void glopTexImage2D(GLContext *c, GLParam *p) { int target = p[1].i; int level = p[2].i; int components = p[3].i; int width = p[4].i; int height = p[5].i; int border = p[6].i; int format = p[7].i; int type = p[8].i; byte *pixels = (byte *)p[9].p; GLImage *im; byte *pixels1; bool do_free_after_rgb2rgba = false; Graphics::PixelFormat sourceFormat; switch (format) { case TGL_RGBA: sourceFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); break; case TGL_RGB: sourceFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0); break; case TGL_BGRA: sourceFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); break; case TGL_BGR: sourceFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0); break; default: error("tglTexImage2D: Pixel format not handled."); } Graphics::PixelFormat pf; switch (format) { case TGL_RGBA: case TGL_RGB: #if defined(SCUMM_BIG_ENDIAN) pf = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0); #elif defined(SCUMM_LITTLE_ENDIAN) pf = Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24); #endif break; case TGL_BGRA: case TGL_BGR: #if defined(SCUMM_BIG_ENDIAN) pf = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 0, 8, 16); #elif defined(SCUMM_LITTLE_ENDIAN) pf = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); #endif break; default: break; } int bytes = pf.bytesPerPixel; // Simply unpack RGB into RGBA with 255 for Alpha. // FIXME: This will need additional checks when we get around to adding 24/32-bit backend. if (target == TGL_TEXTURE_2D && level == 0 && components == 3 && border == 0 && pixels != NULL) { if (format == TGL_RGB || format == TGL_BGR) { Graphics::PixelBuffer temp(pf, width * height, DisposeAfterUse::NO); Graphics::PixelBuffer pixPtr(sourceFormat, pixels); for (int i = 0; i < width * height; ++i) { uint8 r, g, b; pixPtr.getRGBAt(i, r, g, b); temp.setPixelAt(i, 255, r, g, b); } pixels = temp.getRawBuffer(); do_free_after_rgb2rgba = true; } } else if ((format != TGL_RGBA && format != TGL_RGB && format != TGL_BGR && format != TGL_BGRA) || (type != TGL_UNSIGNED_BYTE && type != TGL_UNSIGNED_INT_8_8_8_8_REV)) { error("tglTexImage2D: combination of parameters not handled"); } pixels1 = new byte[c->_textureSize * c->_textureSize * bytes]; if (pixels != NULL) { if (width != c->_textureSize || height != c->_textureSize) { // we use interpolation for better looking result gl_resizeImage(pixels1, c->_textureSize, c->_textureSize, pixels, width, height); width = c->_textureSize; height = c->_textureSize; } else { memcpy(pixels1, pixels, c->_textureSize * c->_textureSize * bytes); } #if defined(SCUMM_BIG_ENDIAN) if (type == TGL_UNSIGNED_INT_8_8_8_8_REV) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { uint32 offset = (y * width + x) * 4; byte *data = pixels1 + offset; WRITE_BE_UINT32(data, READ_LE_UINT32(data)); } } } #endif } c->current_texture->versionNumber++; im = &c->current_texture->images[level]; im->xsize = width; im->ysize = height; if (im->pixmap) im->pixmap.free(); im->pixmap = Graphics::PixelBuffer(pf, pixels1); if (do_free_after_rgb2rgba) { // pixels as been assigned to tmp.getRawBuffer() which was created with // DisposeAfterUse::NO, therefore delete[] it delete[] pixels; } }
PIX getPixel(unsigned int x, unsigned int y) const { return *pixPtr(x,y); }