From 7c1b96a165f970a09ed239bb4fb3f1b0d8f2a407 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Tue, 21 Oct 2008 07:00:00 -0700 Subject: Initial Contribution --- opengl/libagl/mipmap.cpp | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 opengl/libagl/mipmap.cpp (limited to 'opengl/libagl/mipmap.cpp') diff --git a/opengl/libagl/mipmap.cpp b/opengl/libagl/mipmap.cpp new file mode 100644 index 000000000..ccd77b7dc --- /dev/null +++ b/opengl/libagl/mipmap.cpp @@ -0,0 +1,192 @@ +/* libs/opengles/mipmap.cpp +** +** Copyright 2006, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +#include +#include + +#include "context.h" +#include "state.h" +#include "texture.h" +#include "TextureObjectManager.h" + +namespace android { + +// ---------------------------------------------------------------------------- + +status_t buildAPyramid(ogles_context_t* c, EGLTextureObject* tex) +{ + int level = 0; + const GGLSurface* base = &tex->surface; + const GGLFormat& pixelFormat(c->rasterizer.formats[base->format]); + + int w = base->width; + int h = base->height; + if ((w&h) == 1) + return NO_ERROR; + + w = (w>>1) ? : 1; + h = (h>>1) ? : 1; + + while(true) { + ++level; + const int bpr = w * pixelFormat.size; + if (tex->reallocate(level, w, h, w, + base->format, base->compressedFormat, bpr) != NO_ERROR) { + return NO_MEMORY; + } + + int stride = w; + int bs = base->stride; + GGLSurface& cur = tex->editMip(level); + + if (base->format == GGL_PIXEL_FORMAT_RGB_565) + { + uint16_t const * src = (uint16_t const *)base->data; + uint16_t* dst = (uint16_t*)cur.data; + const uint32_t mask = 0x07E0F81F; + for (int y=0 ; y> 2) & mask; + uint32_t rgb = (grb & 0xFFFF) | (grb >> 16); + dst[x + y*stride] = rgb; + offset += 2; + } + } + } + else if (base->format == GGL_PIXEL_FORMAT_RGBA_5551) + { + uint16_t const * src = (uint16_t const *)base->data; + uint16_t* dst = (uint16_t*)cur.data; + for (int y=0 ; y>11)+(p10>>11)+(p01>>11)+(p11>>11)+2)>>2; + uint32_t g = (((p00>>6)+(p10>>6)+(p01>>6)+(p11>>6)+2)>>2)&0x3F; + uint32_t b = ((p00&0x3E)+(p10&0x3E)+(p01&0x3E)+(p11&0x3E)+4)>>3; + uint32_t a = ((p00&1)+(p10&1)+(p01&1)+(p11&1)+2)>>2; + dst[x + y*stride] = (r<<11)|(g<<6)|(b<<1)|a; + offset += 2; + } + } + } + else if (base->format == GGL_PIXEL_FORMAT_RGBA_8888) + { + uint32_t const * src = (uint32_t const *)base->data; + uint32_t* dst = (uint32_t*)cur.data; + for (int y=0 ; y> 8) & 0x00FF00FF; + uint32_t ga01 = (p01 >> 8) & 0x00FF00FF; + uint32_t ga10 = (p10 >> 8) & 0x00FF00FF; + uint32_t ga11 = (p11 >> 8) & 0x00FF00FF; + uint32_t rb = (rb00 + rb01 + rb10 + rb11)>>2; + uint32_t ga = (ga00 + ga01 + ga10 + ga11)>>2; + uint32_t rgba = (rb & 0x00FF00FF) | ((ga & 0x00FF00FF)<<8); + dst[x + y*stride] = rgba; + offset += 2; + } + } + } + else if ((base->format == GGL_PIXEL_FORMAT_RGB_888) || + (base->format == GGL_PIXEL_FORMAT_LA_88) || + (base->format == GGL_PIXEL_FORMAT_A_8) || + (base->format == GGL_PIXEL_FORMAT_L_8)) + { + int skip; + switch (base->format) { + case GGL_PIXEL_FORMAT_RGB_888: skip = 3; break; + case GGL_PIXEL_FORMAT_LA_88: skip = 2; break; + default: skip = 1; break; + } + uint8_t const * src = (uint8_t const *)base->data; + uint8_t* dst = (uint8_t*)cur.data; + bs *= skip; + stride *= skip; + for (int y=0 ; y> 2; + } + offset += 2*skip; + } + } + } + else if (base->format == GGL_PIXEL_FORMAT_RGBA_4444) + { + uint16_t const * src = (uint16_t const *)base->data; + uint16_t* dst = (uint16_t*)cur.data; + for (int y=0 ; y> 2; + uint32_t rgba = (rbga & 0x0F0F) | ((rbga>>12) & 0xF0F0); + dst[x + y*stride] = rgba; + offset += 2; + } + } + } else { + LOGE("Unsupported format (%d)", base->format); + return BAD_TYPE; + } + + // exit condition: we just processed the 1x1 LODs + if ((w&h) == 1) + break; + + base = &cur; + w = (w>>1) ? : 1; + h = (h>>1) ? : 1; + } + return NO_ERROR; +} + +}; // namespace android -- cgit v1.2.3