Search in sources :

Example 1 with WlzIVertex2

use of uk.ac.mrc.hgu.Wlz.WlzIVertex2 in project bioformats by openmicroscopy.

the class WlzServiceImpl method saveBytes.

@Override
public void saveBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException {
    if (state == WLZ_SERVICE_WRITE) {
        WlzIVertex3 og = new WlzIVertex3(x + bBox.xMin, y + bBox.yMin, no + bBox.zMin);
        WlzIVertex2 sz = new WlzIVertex2(w, h);
        try {
            wlzObj = WlzObject.WlzBuildObj3B(wlzObj, og, sz, objGType, buf.length, buf);
        } catch (WlzException e) {
            throw new FormatException("Failed save bytes to Woolz object", e);
        }
    }
}
Also used : WlzException(uk.ac.mrc.hgu.Wlz.WlzException) WlzIVertex3(uk.ac.mrc.hgu.Wlz.WlzIVertex3) FormatException(loci.formats.FormatException) WlzIVertex2(uk.ac.mrc.hgu.Wlz.WlzIVertex2)

Example 2 with WlzIVertex2

use of uk.ac.mrc.hgu.Wlz.WlzIVertex2 in project bioformats by openmicroscopy.

the class WlzServiceImpl method readBytes2DDomObj.

private byte[] readBytes2DDomObj(byte[] buf, int x, int y, int w, int h) throws WlzException {
    WlzIVertex2 og = new WlzIVertex2(x + bBox.xMin, y + bBox.yMin);
    WlzIVertex2 sz = new WlzIVertex2(w, h);
    WlzIVertex2[] dstSz = new WlzIVertex2[1];
    dstSz[0] = null;
    switch(objGType) {
        case WlzGreyType.WLZ_GREY_UBYTE:
            {
                byte[][][] dstDat = new byte[1][][];
                WlzObject.WlzToUArray2D(dstSz, dstDat, wlzObj, og, sz, 0);
                for (int idY = 0; idY < h; ++idY) {
                    int idYW = idY * w;
                    for (int idX = 0; idX < w; ++idX) {
                        buf[idYW + idX] = dstDat[0][idY][idX];
                    }
                }
            }
            break;
        case WlzGreyType.WLZ_GREY_SHORT:
            {
                short m = 0xff;
                short[][][] dstDat = new short[1][][];
                WlzObject.WlzToSArray2D(dstSz, dstDat, wlzObj, og, sz, 0);
                for (int idY = 0; idY < h; ++idY) {
                    int idYW = idY * w;
                    for (int idX = 0; idX < w; ++idX) {
                        short p = dstDat[0][idY][idX];
                        buf[2 * (idYW + idX)] = (byte) ((p >>> 8) & m);
                        buf[2 * (idYW + idX) + 1] = (byte) (p & m);
                    }
                }
            }
            break;
        case WlzGreyType.WLZ_GREY_INT:
            {
                int m = 0xff;
                int[][][] dstDat = new int[1][][];
                WlzObject.WlzToIArray2D(dstSz, dstDat, wlzObj, og, sz, 0);
                for (int idY = 0; idY < h; ++idY) {
                    int idYW = idY * w;
                    for (int idX = 0; idX < w; ++idX) {
                        int p = dstDat[0][idY][idX];
                        buf[idYW + (4 * idX)] = (byte) ((p >> 24) & m);
                        buf[idYW + (4 * idX) + 1] = (byte) ((p >> 16) & m);
                        buf[idYW + (4 * idX) + 2] = (byte) ((p >> 8) & m);
                        buf[idYW + (4 * idX) + 3] = (byte) (p & m);
                    }
                }
            }
            break;
        case WlzGreyType.WLZ_GREY_RGBA:
            {
                int m = 0xff;
                int cOff = h * w;
                int[][][] dstDat = new int[1][][];
                WlzObject.WlzToRArray2D(dstSz, dstDat, wlzObj, og, sz, 0);
                for (int idY = 0; idY < h; ++idY) {
                    int idYW = idY * w;
                    for (int idX = 0; idX < w; ++idX) {
                        int idYWX = idYW + idX;
                        int p = dstDat[0][idY][idX];
                        buf[idYWX] = (byte) ((p >> 0) & m);
                        buf[idYWX + cOff] = (byte) ((p >> 8) & m);
                        buf[idYWX + (2 * cOff)] = (byte) ((p >> 16) & m);
                        buf[idYWX + (3 * cOff)] = (byte) ((p >> 24) & m);
                    }
                }
            }
            break;
        case WlzGreyType.WLZ_GREY_ERROR:
            /* Indicates no values. */
            {
                int w8 = (w + 7) / 8;
                byte[][][] dstDat = new byte[1][][];
                WlzObject.WlzToBArray2D(dstSz, dstDat, wlzObj, og, sz, 0);
                for (int idY = 0; idY < h; ++idY) {
                    int idYW = idY * w;
                    int idYW8 = idY * w8;
                    for (int idX = 0; idX < w; ++idX) {
                        byte p = dstDat[0][idY][idX / 8];
                        byte b = (byte) (p & (0x01 << (idX % 8)));
                        if (b == 0) {
                            buf[idYW + idX] = (byte) 0x00;
                        } else {
                            buf[idYW + idX] = (byte) 0xff;
                        }
                    }
                }
            }
            break;
        default:
            throw new WlzException("Unsupported pixel type");
    }
    return (buf);
}
Also used : WlzException(uk.ac.mrc.hgu.Wlz.WlzException) WlzIVertex2(uk.ac.mrc.hgu.Wlz.WlzIVertex2)

Aggregations

WlzException (uk.ac.mrc.hgu.Wlz.WlzException)2 WlzIVertex2 (uk.ac.mrc.hgu.Wlz.WlzIVertex2)2 FormatException (loci.formats.FormatException)1 WlzIVertex3 (uk.ac.mrc.hgu.Wlz.WlzIVertex3)1