Package javax.media.jai

Examples of javax.media.jai.PixelAccessor


/*     */         }
/*     */     }
/*     */
/*     */     private void constructTree(Raster source) {
/* 219 */       if (!OctTreeOpImage.this.isInitialized) {
/* 220 */         OctTreeOpImage.this.srcPA = new PixelAccessor(OctTreeOpImage.this.getSourceImage(0));
/* 221 */         OctTreeOpImage.this.srcSampleType = (OctTreeOpImage.this.srcPA.sampleType == -1 ? 0 : OctTreeOpImage.this.srcPA.sampleType);
/*     */
/* 223 */         OctTreeOpImage.this.isInitialized = true;
/*     */       }
/*     */
View Full Code Here


/*     */
/* 222 */     short thresholdS = (short)(int)Math.ceil(this.threshold);
/*     */
/* 228 */     Rectangle srcRect = mapDestRect(destRect, 0);
/*     */
/* 230 */     PixelAccessor pa = new PixelAccessor(dest.getSampleModel(), null);
/* 231 */     PackedImageData pid = pa.getPackedPixels(dest, destRect, true, false);
/* 232 */     int offset = pid.offset;
/* 233 */     PixelAccessor srcPa = new PixelAccessor(source.getSampleModel(), null);
/*     */
/* 235 */     UnpackedImageData srcImD = srcPa.getPixels(source, srcRect, 2, false);
/* 236 */     int srcOffset = srcImD.bandOffsets[0];
/* 237 */     short[] srcData = ((short[][])(short[][])srcImD.data)[0];
/* 238 */     int pixelStride = srcImD.pixelStride;
/*     */
/* 240 */     int ind0 = pid.bitOffset;
View Full Code Here

/*     */
/* 269 */     int thresholdI = (int)Math.ceil(this.threshold);
/*     */
/* 275 */     Rectangle srcRect = mapDestRect(destRect, 0);
/*     */
/* 277 */     PixelAccessor pa = new PixelAccessor(dest.getSampleModel(), null);
/* 278 */     PackedImageData pid = pa.getPackedPixels(dest, destRect, true, false);
/* 279 */     int offset = pid.offset;
/* 280 */     PixelAccessor srcPa = new PixelAccessor(source.getSampleModel(), null);
/*     */
/* 282 */     UnpackedImageData srcImD = srcPa.getPixels(source, srcRect, 1, false);
/* 283 */     int srcOffset = srcImD.bandOffsets[0];
/* 284 */     short[] srcData = ((short[][])(short[][])srcImD.data)[0];
/* 285 */     int pixelStride = srcImD.pixelStride;
/*     */
/* 287 */     int ind0 = pid.bitOffset;
View Full Code Here

/*     */
/* 318 */     int thresholdI = (int)Math.ceil(this.threshold);
/*     */
/* 324 */     Rectangle srcRect = mapDestRect(destRect, 0);
/*     */
/* 326 */     PixelAccessor pa = new PixelAccessor(dest.getSampleModel(), null);
/* 327 */     PackedImageData pid = pa.getPackedPixels(dest, destRect, true, false);
/* 328 */     int offset = pid.offset;
/* 329 */     PixelAccessor srcPa = new PixelAccessor(source.getSampleModel(), null);
/*     */
/* 331 */     UnpackedImageData srcImD = srcPa.getPixels(source, srcRect, 3, false);
/* 332 */     int srcOffset = srcImD.bandOffsets[0];
/* 333 */     int[] srcData = ((int[][])(int[][])srcImD.data)[0];
/* 334 */     int pixelStride = srcImD.pixelStride;
/*     */
/* 336 */     int ind0 = pid.bitOffset;
View Full Code Here

/*     */
/*     */   private void floatLoop(Raster source, WritableRaster dest, Rectangle destRect)
/*     */   {
/* 356 */     Rectangle srcRect = mapDestRect(destRect, 0);
/*     */
/* 358 */     PixelAccessor pa = new PixelAccessor(dest.getSampleModel(), null);
/* 359 */     PackedImageData pid = pa.getPackedPixels(dest, destRect, true, false);
/* 360 */     int offset = pid.offset;
/* 361 */     PixelAccessor srcPa = new PixelAccessor(source.getSampleModel(), null);
/*     */
/* 363 */     UnpackedImageData srcImD = srcPa.getPixels(source, srcRect, 4, false);
/* 364 */     int srcOffset = srcImD.bandOffsets[0];
/* 365 */     float[] srcData = ((float[][])(float[][])srcImD.data)[0];
/* 366 */     int pixelStride = srcImD.pixelStride;
/*     */
/* 368 */     int ind0 = pid.bitOffset;
View Full Code Here

/*     */
/*     */   private void doubleLoop(Raster source, WritableRaster dest, Rectangle destRect)
/*     */   {
/* 387 */     Rectangle srcRect = mapDestRect(destRect, 0);
/*     */
/* 389 */     PixelAccessor pa = new PixelAccessor(dest.getSampleModel(), null);
/* 390 */     PackedImageData pid = pa.getPackedPixels(dest, destRect, true, false);
/* 391 */     int offset = pid.offset;
/* 392 */     PixelAccessor srcPa = new PixelAccessor(source.getSampleModel(), null);
/*     */
/* 394 */     UnpackedImageData srcImD = srcPa.getPixels(source, srcRect, 5, false);
/* 395 */     int srcOffset = srcImD.bandOffsets[0];
/* 396 */     double[] srcData = ((double[][])(double[][])srcImD.data)[0];
/* 397 */     int pixelStride = srcImD.pixelStride;
/*     */
/* 399 */     int ind0 = pid.bitOffset;
View Full Code Here

/*     */   }
/*     */
/*     */   private void setTo1(Raster dest, Rectangle destRect)
/*     */   {
/* 416 */     initBitsOn();
/* 417 */     PixelAccessor pa = new PixelAccessor(dest.getSampleModel(), null);
/* 418 */     PackedImageData pid = pa.getPackedPixels(dest, destRect, true, false);
/* 419 */     int offset = pid.offset;
/*     */
/* 421 */     for (int h = 0; h < destRect.height; h++) {
/* 422 */       int ind0 = pid.bitOffset;
/* 423 */       int indE = ind0 + destRect.width - 1;
/* 424 */       if (indE < 8)
/*     */       {
/* 426 */         pid.data[offset] = ((byte)(pid.data[offset] | bitsOn[indE]));
/*     */       }
/*     */       else {
/* 429 */         pid.data[offset] = ((byte)(pid.data[offset] | bitsOn[7]));
/*     */
/* 431 */         for (int b = offset + 1; b <= offset + (indE - 7) / 8; b++) {
/* 432 */           pid.data[b] = -1;
/*     */         }
/*     */
/* 436 */         int remBits = indE % 8;
/* 437 */         if (remBits % 8 != 7) {
/* 438 */           indE = offset + indE / 8;
/* 439 */           pid.data[indE] = ((byte)(pid.data[indE] | bitsOn[remBits]));
/*     */         }
/*     */       }
/* 442 */       offset += pid.lineStride;
/*     */     }
/* 444 */     pa.setPackedPixels(pid);
/*     */   }
View Full Code Here

        // Bands associated with each sources
        int[] snbands = new int[nSrcs];
        // PixelAccessor array for each source
        PixelAccessor[] pas = new PixelAccessor[nSrcs];
        for (int i = 0; i < nSrcs; i++) {
            pas[i] = new PixelAccessor(sources[i].getSampleModel(), colorModels[i]);

            if (colorModels[i] instanceof IndexColorModel) {
                snbands[i] = colorModels[i].getNumComponents();
            } else {
                snbands[i] = sources[i].getNumBands();
            }
        }

        // Destination bands
        int dnbands = dest.getNumBands();
        // Destination data type
        int destType = dest.getTransferType();
        // PixelAccessor associated with the destination raster
        PixelAccessor d = new PixelAccessor(dest.getSampleModel(), null);

        UnpackedImageData dimd = d.getPixels(dest, destRect, destType, true);

        // Destination tile initial position
        final int minX = destRect.x;
        final int minY = destRect.y;

        // Destination data values
        byte[][] dstdata = (byte[][]) dimd.data;

        // ONLY VALID DATA
        if (caseA) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;
                // Cycle on each source bands
                for (int sb = 0; sb < snbands[sindex]; sb++, db++) {
                    if (db >= dnbands) {
                        // exceeding destNumBands; should not have happened
                        break;
                    }

                    byte[] dstdatabandb = dstdata[db];
                    byte[][] srcdata = (byte[][]) simd.data;
                    byte[] srcdatabandsb = srcdata[sb];
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];

                    // Cycle on the y-axis
                    for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                        // Cycle on the x-axis
                        for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                            dstdatabandb[dstpos] = srcdatabandsb[srcpos];
                        }
                    }
                }
            }
            // ONLY ROI
        } else if (caseB) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                int srcstart = 0;
                int dststart = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                    // Cycle on the x-axis
                    for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                        // ROI Check
                        if (roi.contains(i + minX, y + minY)) {
                            // Cycle on each source bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                int dbidx = db + sb;
                                byte[] dstdatabandb = dstdata[dbidx];
                                byte[][] srcdata = (byte[][]) simd.data;
                                byte[] srcdatabandsb = srcdata[sb];

                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = srcdatabandsb[srcpos
                                        + simd.bandOffsets[sb]];
                            }
                        } else {
                            for (int sb = 0; sb < snbands[sindex]; sb++) {

                                int dbidx = db + sb;
                                byte[] dstdatabandb = dstdata[dbidx];

                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataByte;
                            }
                        }
                    }
                }
                db += snbands[sindex];
            }
            // ONLY NODATA
        } else if (caseC) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                // Source data
                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                // Source and Destination parameters
                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                // Cycle on each source bands
                for (int sb = 0; sb < snbands[sindex]; sb++, db++) {
                    if (db >= dnbands) {
                        // exceeding destNumBands; should not have happened
                        break;
                    }

                    // Source and destination data array
                    byte[] dstdatabandb = dstdata[db];
                    byte[][] srcdata = (byte[][]) simd.data;
                    byte[] srcdatabandsb = srcdata[sb];
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];
                    // Cycle on the y-axis
                    for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                        // Cycle on the x-axis
                        for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {
                            // No Data control
                            if (noData[sindex].contains(srcdatabandsb[srcpos])) {
                                dstdatabandb[dstpos] = destNoDataByte;
                            } else {
                                dstdatabandb[dstpos] = srcdatabandsb[srcpos];
                            }
                        }
                    }
                }
            }
            // NODATA AND ROI
        } else {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                int srcstart = 0;
                int dststart = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                    // Cycle on the x-axis
                    for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                        // ROI Check
                        if (roi.contains(i + minX, y + minY)) {
                            // Cycle on each source bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                int dbidx = db + sb;
                                byte[] dstdatabandb = dstdata[dbidx];
                                byte[][] srcdata = (byte[][]) simd.data;
                                byte[] srcdatabandsb = srcdata[sb];

                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }

                                // No Data control
                                if (noData[sindex].contains(srcdatabandsb[srcpos])) {
                                    dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataByte;
                                } else {
                                    dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = srcdatabandsb[srcpos
                                            + simd.bandOffsets[sb]];
                                }
                            }
                        } else {
                            for (int sb = 0; sb < snbands[sindex]; sb++) {

                                int dbidx = db + sb;
                                byte[] dstdatabandb = dstdata[dbidx];

                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataByte;
                            }
                        }
                    }
                }
                db += snbands[sindex];
            }
        }
        d.setPixels(dimd);
    }
View Full Code Here

        PixelAccessor[] pas = new PixelAccessor[nSrcs];

        boolean isUshort = getSampleModel().getDataType() == DataBuffer.TYPE_USHORT;

        for (int i = 0; i < nSrcs; i++) {
            pas[i] = new PixelAccessor(sources[i].getSampleModel(), colorModels[i]);

            if (colorModels[i] instanceof IndexColorModel) {
                snbands[i] = colorModels[i].getNumComponents();
            } else {
                snbands[i] = sources[i].getNumBands();
            }
        }

        // Destination bands
        int dnbands = dest.getNumBands();
        // Destination data type
        int destType = dest.getTransferType();
        // PixelAccessor associated with the destination raster
        PixelAccessor d = new PixelAccessor(dest.getSampleModel(), null);

        UnpackedImageData dimd = d.getPixels(dest, destRect, destType, true);

        // Destination data values
        short[][] dstdata = (short[][]) dimd.data;

        // ONLY VALID DATA
        if (caseA) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;
                // Cycle on each source bands
                for (int sb = 0; sb < snbands[sindex]; sb++, db++) {
                    if (db >= dnbands) {
                        // exceeding destNumBands; should not have happened
                        break;
                    }

                    short[] dstdatabandb = dstdata[db];
                    short[][] srcdata = (short[][]) simd.data;
                    short[] srcdatabandsb = srcdata[sb];
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];

                    // Cycle on the y-axis
                    for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                        // Cycle on the x-axis
                        for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                            dstdatabandb[dstpos] = srcdatabandsb[srcpos];
                        }
                    }
                }
            }
            // ONLY ROI
        } else if (caseB) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                int srcstart = 0;
                int dststart = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                    // Cycle on the x-axis
                    for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                        // ROI Check
                        if (roi.contains(i + minX, y + minY)) {
                            // Cycle on each source bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                int dbidx = db + sb;
                                short[] dstdatabandb = dstdata[dbidx];
                                short[][] srcdata = (short[][]) simd.data;
                                short[] srcdatabandsb = srcdata[sb];

                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = srcdatabandsb[srcpos
                                        + simd.bandOffsets[sb]];
                            }
                        } else {
                            for (int sb = 0; sb < snbands[sindex]; sb++) {

                                int dbidx = db + sb;
                                short[] dstdatabandb = dstdata[dbidx];

                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataShort;
                            }
                        }
                    }
                }
                db += snbands[sindex];
            }
            // ONLY NODATA
        } else if (caseC) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                // Source data
                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                // Source and Destination parameters
                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                // Cycle on each source bands
                for (int sb = 0; sb < snbands[sindex]; sb++, db++) {
                    if (db >= dnbands) {
                        // exceeding destNumBands; should not have happened
                        break;
                    }

                    // Source and destination data array
                    short[] dstdatabandb = dstdata[db];
                    short[][] srcdata = (short[][]) simd.data;
                    short[] srcdatabandsb = srcdata[sb];
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];
                    // Cycle on the y-axis
                    for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                        // Cycle on the x-axis
                        for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {
                            // No Data control
                            if (noData[sindex].contains(srcdatabandsb[srcpos])) {
                                dstdatabandb[dstpos] = destNoDataShort;
                            } else {
                                dstdatabandb[dstpos] = srcdatabandsb[srcpos];
                            }
                        }
                    }
                }
            }
            // NODATA AND ROI
        } else {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                int srcstart = 0;
                int dststart = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                    // Cycle on the x-axis
                    for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                        // ROI Check
                        if (roi.contains(i + minX, y + minY)) {
                            // Cycle on each source bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                int dbidx = db + sb;
                                short[] dstdatabandb = dstdata[dbidx];
                                short[][] srcdata = (short[][]) simd.data;
                                short[] srcdatabandsb = srcdata[sb];

                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }

                                // No Data control
                                if (noData[sindex].contains(srcdatabandsb[srcpos])) {
                                    dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataShort;
                                } else {
                                    dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = srcdatabandsb[srcpos
                                            + simd.bandOffsets[sb]];
                                }
                            }
                        } else {
                            for (int sb = 0; sb < snbands[sindex]; sb++) {

                                int dbidx = db + sb;
                                short[] dstdatabandb = dstdata[dbidx];

                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataShort;
                            }
                        }
                    }
                }
                db += snbands[sindex];
            }
        }
        d.setPixels(dimd);
    }
View Full Code Here

        int[] snbands = new int[nSrcs];
        // PixelAccessor array for each source
        PixelAccessor[] pas = new PixelAccessor[nSrcs];

        for (int i = 0; i < nSrcs; i++) {
            pas[i] = new PixelAccessor(sources[i].getSampleModel(), colorModels[i]);

            if (colorModels[i] instanceof IndexColorModel) {
                snbands[i] = colorModels[i].getNumComponents();
            } else {
                snbands[i] = sources[i].getNumBands();
            }
        }

        // Destination bands
        int dnbands = dest.getNumBands();
        // Destination data type
        int destType = dest.getTransferType();
        // PixelAccessor associated with the destination raster
        PixelAccessor d = new PixelAccessor(dest.getSampleModel(), null);

        UnpackedImageData dimd = d.getPixels(dest, destRect, destType, true);
        // Destination data values
        int[][] dstdata = (int[][]) dimd.data;

        // ONLY VALID DATA
        if (caseA) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;
                // Cycle on each source bands
                for (int sb = 0; sb < snbands[sindex]; sb++, db++) {
                    if (db >= dnbands) {
                        // exceeding destNumBands; should not have happened
                        break;
                    }

                    int[] dstdatabandb = dstdata[db];
                    int[][] srcdata = (int[][]) simd.data;
                    int[] srcdatabandsb = srcdata[sb];
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];

                    // Cycle on the y-axis
                    for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                        // Cycle on the x-axis
                        for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                            dstdatabandb[dstpos] = srcdatabandsb[srcpos];
                        }
                    }
                }
            }
            // ONLY ROI
        } else if (caseB) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                int srcstart = 0;
                int dststart = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                    // Cycle on the x-axis
                    for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                        // ROI Check
                        if (roi.contains(i + minX, y + minY)) {
                            // Cycle on each source bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                int dbidx = db + sb;
                                int[] dstdatabandb = dstdata[dbidx];
                                int[][] srcdata = (int[][]) simd.data;
                                int[] srcdatabandsb = srcdata[sb];

                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }
                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = srcdatabandsb[srcpos
                                        + simd.bandOffsets[sb]];
                            }
                        } else {
                            for (int sb = 0; sb < snbands[sindex]; sb++) {

                                int dbidx = db + sb;
                                int[] dstdatabandb = dstdata[dbidx];

                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataInt;
                            }
                        }
                    }
                }
                db += snbands[sindex];
            }
            // ONLY NODATA
        } else if (caseC) {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                // Source data
                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                // Source and Destination parameters
                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                // Cycle on each source bands
                for (int sb = 0; sb < snbands[sindex]; sb++, db++) {
                    if (db >= dnbands) {
                        // exceeding destNumBands; should not have happened
                        break;
                    }

                    // Source and destination data array
                    int[] dstdatabandb = dstdata[db];
                    int[][] srcdata = (int[][]) simd.data;
                    int[] srcdatabandsb = srcdata[sb];
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];
                    // Cycle on the y-axis
                    for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                        // Cycle on the x-axis
                        for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {
                            // No Data control
                            if (noData[sindex].contains(srcdatabandsb[srcpos])) {
                                dstdatabandb[dstpos] = destNoDataInt;
                            } else {
                                dstdatabandb[dstpos] = srcdatabandsb[srcpos];
                            }
                        }
                    }
                }
            }
            // NODATA AND ROI
        } else {
            // Cycle on all the sources
            for (int sindex = 0, db = 0; sindex < nSrcs; sindex++) {

                UnpackedImageData simd = colorModels[sindex] instanceof IndexColorModel ? pas[sindex]
                        .getComponents(sources[sindex], destRect, sources[sindex].getSampleModel()
                                .getTransferType()) : pas[sindex].getPixels(sources[sindex],
                        destRect, sources[sindex].getSampleModel().getTransferType(), false);

                int srcPixelStride = simd.pixelStride;
                int srcLineStride = simd.lineStride;
                int dstPixelStride = dimd.pixelStride;
                int dstLineStride = dimd.lineStride;
                int dRectWidth = destRect.width;

                int srcstart = 0;
                int dststart = 0;

                // Cycle on the y-axis
                for (int y = 0; y < destRect.height; y++, srcstart += srcLineStride, dststart += dstLineStride) {
                    // Cycle on the x-axis
                    for (int i = 0, srcpos = srcstart, dstpos = dststart; i < dRectWidth; i++, srcpos += srcPixelStride, dstpos += dstPixelStride) {

                        // ROI Check
                        if (roi.contains(i + minX, y + minY)) {
                            // Cycle on each source bands
                            for (int sb = 0; sb < snbands[sindex]; sb++) {
                                int dbidx = db + sb;
                                int[] dstdatabandb = dstdata[dbidx];
                                int[][] srcdata = (int[][]) simd.data;
                                int[] srcdatabandsb = srcdata[sb];

                                if (db >= dnbands) {
                                    // exceeding destNumBands; should not have happened
                                    break;
                                }

                                // No Data control
                                if (noData[sindex].contains(srcdatabandsb[srcpos])) {
                                    dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataInt;
                                } else {
                                    dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = srcdatabandsb[srcpos
                                            + simd.bandOffsets[sb]];
                                }
                            }
                        } else {
                            for (int sb = 0; sb < snbands[sindex]; sb++) {

                                int dbidx = db + sb;
                                int[] dstdatabandb = dstdata[dbidx];

                                dstdatabandb[dstpos + dimd.bandOffsets[dbidx]] = destNoDataInt;
                            }
                        }
                    }
                }
                db += snbands[sindex];
            }
        }
        d.setPixels(dimd);
    }
View Full Code Here

TOP

Related Classes of javax.media.jai.PixelAccessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.