-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TIFF & BMP file formats, add parameter grouping for CLI tool
- Loading branch information
Showing
9 changed files
with
232 additions
and
13 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
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
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
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,57 @@ | ||
// Copyright 2023 Ronsor Labs. All rights reserved. | ||
|
||
package henshin | ||
|
||
import ( | ||
"image" | ||
"io" | ||
|
||
"golang.org/x/image/bmp" | ||
) | ||
|
||
func init() { | ||
RegisterCodec(&BMPCodec{}) | ||
} | ||
|
||
// BMPCodec is the BMP codec. | ||
type BMPCodec struct{} | ||
|
||
// New returns a new instance of BMPCodec. | ||
func (c *BMPCodec) New() Codec { return &BMPCodec{} } | ||
|
||
// Name returns the name of the BMP codec: "bmp" | ||
func (c *BMPCodec) Name() string { return "bmp" } | ||
|
||
// Aliases returns alternate names for the BMP codec | ||
func (c *BMPCodec) Aliases() []string { | ||
return []string{"dib"} | ||
} | ||
|
||
// Magic returns magic strings that identify BMP data. | ||
func (c *BMPCodec) Magic() []string { | ||
return []string{"BM????\x00\x00\x00\x00"} | ||
} | ||
|
||
// Decode decodes a BMP image according to the options specified. | ||
func (c *BMPCodec) Decode(r io.Reader, d *DecodeOptions) (image.Image, error) { | ||
return bmp.Decode(r) | ||
} | ||
|
||
// DecodeConfig returns the color model and dimensions of a BMP image | ||
// without decoding the image. | ||
func (c *BMPCodec) DecodeConfig(r io.Reader, d *DecodeOptions) (image.Config, error) { | ||
return bmp.DecodeConfig(r) | ||
} | ||
|
||
// Encode encodes a BMP image according to the options specified. | ||
func (c *BMPCodec) Encode(w io.Writer, i image.Image, o *EncodeOptions) error { | ||
if o == nil { o = DefaultEncodeOptions() } | ||
|
||
return bmp.Encode(w, i) | ||
} | ||
|
||
var ( | ||
_ Decoder = &BMPCodec{} | ||
_ Encoder = &BMPCodec{} | ||
_ CodecWithAliases = &BMPCodec{} | ||
) |
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
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,14 @@ | ||
// Copyright 2023 Ronsor Labs. All rights reserved. | ||
|
||
package henshin | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAreaFit(t *testing.T) { | ||
w, h := areaFit(1920, 1080, 1024*1024) | ||
if w != 1365 && h != 768 { | ||
t.Errorf("Expected (1365, 768) but got (%d, %d)", w, h) | ||
} | ||
} |
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,60 @@ | ||
// Copyright 2023 Ronsor Labs. All rights reserved. | ||
|
||
package henshin | ||
|
||
import ( | ||
"image" | ||
"io" | ||
|
||
"golang.org/x/image/tiff" | ||
) | ||
|
||
func init() { | ||
RegisterCodec(&TIFFCodec{}) | ||
} | ||
|
||
// TIFFCodec is the TIFF codec. | ||
type TIFFCodec struct{} | ||
|
||
// New returns a new instance of TIFFCodec. | ||
func (c *TIFFCodec) New() Codec { return &TIFFCodec{} } | ||
|
||
// Name returns the name of the TIFF codec: "tiff" | ||
func (c *TIFFCodec) Name() string { return "tiff" } | ||
|
||
// Aliases returns alternate names for the TIFF codec | ||
func (c *TIFFCodec) Aliases() []string { | ||
return []string{"tif"} | ||
} | ||
|
||
// Magic returns magic strings that identify TIFF data. | ||
func (c *TIFFCodec) Magic() []string { | ||
return []string{"II\x2A\x00", "MM\x00\x2A"} | ||
} | ||
|
||
// Decode decodes a TIFF image according to the options specified. | ||
func (c *TIFFCodec) Decode(r io.Reader, d *DecodeOptions) (image.Image, error) { | ||
return tiff.Decode(r) | ||
} | ||
|
||
// DecodeConfig returns the color model and dimensions of a TIFF image | ||
// without decoding the image. | ||
func (c *TIFFCodec) DecodeConfig(r io.Reader, d *DecodeOptions) (image.Config, error) { | ||
return tiff.DecodeConfig(r) | ||
} | ||
|
||
// Encode encodes a TIFF image according to the options specified. | ||
func (c *TIFFCodec) Encode(w io.Writer, i image.Image, o *EncodeOptions) error { | ||
if o == nil { o = DefaultEncodeOptions() } | ||
|
||
var tiffOpt tiff.Options | ||
// TODO: allow setting these options | ||
|
||
return tiff.Encode(w, i, &tiffOpt) | ||
} | ||
|
||
var ( | ||
_ Decoder = &TIFFCodec{} | ||
_ Encoder = &TIFFCodec{} | ||
_ CodecWithAliases = &TIFFCodec{} | ||
) |
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
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