Skip to content

Commit

Permalink
Merge pull request #227 from observerly/feature/astrotiff/writePixels
Browse files Browse the repository at this point in the history
feat: add writePixels() utility to astrotiff module in @observerly/iris
  • Loading branch information
michealroberts authored Oct 17, 2024
2 parents 57e4ae6 + 405d334 commit bf86634
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pkg/astrotiff/writer.go
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
}

/*****************************************************************************************************************/

0 comments on commit bf86634

Please sign in to comment.