summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsAllocation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/rsAllocation.cpp')
-rw-r--r--libs/rs/rsAllocation.cpp74
1 files changed, 61 insertions, 13 deletions
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index c143307..ca277ef 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -204,12 +204,12 @@ static void mip565(const Adapter2D &out, const Adapter2D &in)
uint32_t w = out.getDimX();
uint32_t h = out.getDimY();
- for (uint32_t y=0; y < w; y++) {
+ for (uint32_t y=0; y < h; y++) {
uint16_t *oPtr = static_cast<uint16_t *>(out.getElement(0, y));
const uint16_t *i1 = static_cast<uint16_t *>(in.getElement(0, y*2));
const uint16_t *i2 = static_cast<uint16_t *>(in.getElement(0, y*2+1));
- for (uint32_t x=0; x < h; x++) {
+ for (uint32_t x=0; x < w; x++) {
*oPtr = rsBoxFilter565(i1[0], i1[1], i2[0], i2[1]);
oPtr ++;
i1 += 2;
@@ -223,21 +223,33 @@ static void mip8888(const Adapter2D &out, const Adapter2D &in)
uint32_t w = out.getDimX();
uint32_t h = out.getDimY();
- for (uint32_t y=0; y < w; y++) {
+ for (uint32_t y=0; y < h; y++) {
uint32_t *oPtr = static_cast<uint32_t *>(out.getElement(0, y));
const uint32_t *i1 = static_cast<uint32_t *>(in.getElement(0, y*2));
const uint32_t *i2 = static_cast<uint32_t *>(in.getElement(0, y*2+1));
- for (uint32_t x=0; x < h; x++) {
+ for (uint32_t x=0; x < w; x++) {
*oPtr = rsBoxFilter8888(i1[0], i1[1], i2[0], i2[1]);
oPtr ++;
i1 += 2;
i2 += 2;
}
}
-
}
+static void mip(const Adapter2D &out, const Adapter2D &in)
+{
+ switch(out.getBaseType()->getElement()->getSizeBits()) {
+ case 32:
+ mip8888(out, in);
+ break;
+ case 16:
+ mip565(out, in);
+ break;
+
+ }
+
+}
typedef void (*ElementConverter_t)(void *dst, const void *src, uint32_t count);
@@ -301,14 +313,18 @@ static ElementConverter_t pickConverter(RsElementPredefined dstFmt, RsElementPre
return elementConverter_cpy_32;
}
- LOGE("pickConverter, unsuported combo");
+ LOGE("pickConverter, unsuported combo, src %i, dst %i", srcFmt, dstFmt);
return 0;
}
RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h, RsElementPredefined dstFmt, RsElementPredefined srcFmt, bool genMips, const void *data)
{
- rsi_TypeBegin(rsc, rsi_ElementGetPredefined(rsc, RS_ELEMENT_RGB_565));
+ rsAssert(!(w & (w-1)));
+ rsAssert(!(h & (h-1)));
+
+ //LOGE("rsi_AllocationCreateFromBitmap %i %i %i %i %i", w, h, dstFmt, srcFmt, genMips);
+ rsi_TypeBegin(rsc, rsi_ElementGetPredefined(rsc, dstFmt));
rsi_TypeAdd(rsc, RS_DIMENSION_X, w);
rsi_TypeAdd(rsc, RS_DIMENSION_Y, h);
if (genMips) {
@@ -333,13 +349,49 @@ RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, uint32_t w, uint32_t h
for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
adapt.setLOD(lod);
adapt2.setLOD(lod + 1);
- mip565(adapt2, adapt);
+ mip(adapt2, adapt);
}
}
return texAlloc;
}
+static uint32_t fmtToBits(RsElementPredefined fmt)
+{
+ return 16;
+}
+
+RsAllocation rsi_AllocationCreateFromBitmapBoxed(Context *rsc, uint32_t w, uint32_t h, RsElementPredefined dstFmt, RsElementPredefined srcFmt, bool genMips, const void *data)
+{
+ uint32_t w2 = rsHigherPow2(w);
+ uint32_t h2 = rsHigherPow2(h);
+
+ if ((w2 == w) && (h2 == h)) {
+ return rsi_AllocationCreateFromBitmap(rsc, w, h, dstFmt, srcFmt, genMips, data);
+ }
+
+ uint32_t bpp = fmtToBits(srcFmt) >> 3;
+ size_t size = w2 * h2 * bpp;
+ uint8_t *tmp = static_cast<uint8_t *>(malloc(size));
+ memset(tmp, 0, size);
+
+ const uint8_t * src = static_cast<const uint8_t *>(data);
+ for (uint32_t y = 0; y < h; y++) {
+ uint8_t * ydst = &tmp[(y + ((h2 - h) >> 1)) * w2 * bpp];
+ memcpy(&ydst[(w2 - w) >> 1], src, w * bpp);
+ src += w * bpp;
+ }
+
+ RsAllocation ret = rsi_AllocationCreateFromBitmap(rsc, w2, h2, dstFmt, srcFmt, genMips, tmp);
+ free(tmp);
+ return ret;
+
+
+
+
+}
+
+
RsAllocation rsi_AllocationCreateFromFile(Context *rsc, const char *file, bool genMips)
{
bool use32bpp = false;
@@ -442,11 +494,7 @@ RsAllocation rsi_AllocationCreateFromFile(Context *rsc, const char *file, bool g
for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
adapt.setLOD(lod);
adapt2.setLOD(lod + 1);
- if (use32bpp) {
- mip8888(adapt2, adapt);
- } else {
- mip565(adapt2, adapt);
- }
+ mip(adapt2, adapt);
}
}