-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from observerly/feature/astrotiff/writePixels
feat: add writePixels() utility to astrotiff module in @observerly/iris
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*****************************************************************************************************************/ | ||
|
||
// @author Michael Roberts <michael@observerly.com> | ||
// @package @observerly/iris/astrotiff | ||
// @license Copyright © 2021-2024 observerly | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
package astrotiff | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
/*****************************************************************************************************************/ | ||
|
||
// writePixels writes the internal byte array of an image to w. It is less general | ||
// but much faster then encode. writePixels is used when pix directly | ||
// corresponds to one of the TIFF image types. | ||
func writePixels(w io.Writer, pix []byte, nrows, length, stride int) error { | ||
if length == stride { | ||
_, err := w.Write(pix[:nrows*length]) | ||
return err | ||
} | ||
|
||
for ; nrows > 0; nrows-- { | ||
if _, err := w.Write(pix[:length]); err != nil { | ||
return err | ||
} | ||
pix = pix[stride:] | ||
} | ||
|
||
return nil | ||
} | ||
|
||
/*****************************************************************************************************************/ |