MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / writeData

Method writeData

ij/src/main/java/ij/plugin/FITS_Writer.java:605–645  ·  view source on GitHub ↗

Appends the data of the current image to the end of the file specified by path.

(String path, ImageProcessor ip)

Source from the content-addressed store, hash-verified

603 * Appends the data of the current image to the end of the file specified by path.
604 */
605 void writeData(String path, ImageProcessor ip) {
606 int w = ip.getWidth();
607 int h = ip.getHeight();
608 if (ip instanceof ByteProcessor) {
609 byte[] pixels = (byte[])ip.getPixels();
610 try {
611 DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path,true)));
612 for (int i = h - 1; i >= 0; i-- )
613 for (int j = i*w; j < w*(i+1); j++)
614 dos.writeByte(pixels[j]);
615 dos.close();
616 } catch (IOException e) {
617 IJ.showStatus("Error writing file!");
618 return;
619 }
620 } else if (ip instanceof ShortProcessor) {
621 short[] pixels = (short[])ip.getPixels();
622 try {
623 DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path,true)));
624 for (int i = h - 1; i >= 0; i-- )
625 for (int j = i*w; j < w*(i+1); j++)
626 dos.writeShort(pixels[j]^0x8000);
627 dos.close();
628 } catch (IOException e) {
629 IJ.showStatus("Error writing file!");
630 return;
631 }
632 } else if (ip instanceof FloatProcessor) {
633 float[] pixels = (float[])ip.getPixels();
634 try {
635 DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(path,true)));
636 for (int i = h - 1; i >= 0; i-- )
637 for (int j = i*w; j < w*(i+1); j++)
638 dos.writeFloat(pixels[j]);
639 dos.close();
640 } catch (IOException e) {
641 IJ.showStatus("Error writing file!");
642 return;
643 }
644 }
645 }
646
647 /**
648 * Extracts the original FITS header from the Properties object of the

Callers 1

runMethod · 0.95

Calls 8

showStatusMethod · 0.95
closeMethod · 0.65
getWidthMethod · 0.45
getHeightMethod · 0.45
getPixelsMethod · 0.45
writeByteMethod · 0.45
writeShortMethod · 0.45
writeFloatMethod · 0.45

Tested by

no test coverage detected