update vendor

This commit is contained in:
ston1th 2025-10-15 22:37:57 +02:00
commit 8675bc4b7a
328 changed files with 27166 additions and 6537 deletions

View file

@ -1,6 +1,8 @@
package barcode
import "image"
import (
"image"
)
const (
TypeAztec = "Aztec"
@ -40,3 +42,7 @@ type BarcodeIntCS interface {
Barcode
CheckSum() int
}
type BarcodeColor interface {
ColorScheme() ColorScheme
}

39
vendor/github.com/boombuler/barcode/color_scheme.go generated vendored Normal file
View file

@ -0,0 +1,39 @@
package barcode
import "image/color"
// ColorScheme defines a structure for color schemes used in barcode rendering.
// It includes the color model, background color, and foreground color.
type ColorScheme struct {
Model color.Model // Color model to be used (e.g., grayscale, RGB, RGBA)
Background color.Color // Color of the background
Foreground color.Color // Color of the foreground (e.g., bars in a barcode)
}
// ColorScheme8 represents a color scheme with 8-bit grayscale colors.
var ColorScheme8 = ColorScheme{
Model: color.GrayModel,
Background: color.Gray{Y: 255},
Foreground: color.Gray{Y: 0},
}
// ColorScheme16 represents a color scheme with 16-bit grayscale colors.
var ColorScheme16 = ColorScheme{
Model: color.Gray16Model,
Background: color.White,
Foreground: color.Black,
}
// ColorScheme24 represents a color scheme with 24-bit RGB colors.
var ColorScheme24 = ColorScheme{
Model: color.RGBAModel,
Background: color.RGBA{255, 255, 255, 255},
Foreground: color.RGBA{0, 0, 0, 255},
}
// ColorScheme32 represents a color scheme with 32-bit RGBA colors, which is similar to ColorScheme24 but typically includes alpha for transparency.
var ColorScheme32 = ColorScheme{
Model: color.RGBAModel,
Background: color.RGBA{255, 255, 255, 255},
Foreground: color.RGBA{0, 0, 0, 255},
}

View file

@ -54,8 +54,8 @@ func (e Encoding) String() string {
return ""
}
// Encode returns a QR barcode with the given content, error correction level and uses the given encoding
func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.Barcode, error) {
// Encode returns a QR barcode with the given content and color scheme, error correction level and uses the given encoding
func EncodeWithColor(content string, level ErrorCorrectionLevel, mode Encoding, color barcode.ColorScheme) (barcode.Barcode, error) {
bits, vi, err := mode.getEncoder()(content, level)
if err != nil {
return nil, err
@ -63,19 +63,23 @@ func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.
blocks := splitToBlocks(bits.IterateBytes(), vi)
data := blocks.interleave(vi)
result := render(data, vi)
result := render(data, vi, color)
result.content = content
return result, nil
}
func render(data []byte, vi *versionInfo) *qrcode {
func Encode(content string, level ErrorCorrectionLevel, mode Encoding) (barcode.Barcode, error) {
return EncodeWithColor(content, level, mode, barcode.ColorScheme16)
}
func render(data []byte, vi *versionInfo, color barcode.ColorScheme) *qrcode {
dim := vi.modulWidth()
results := make([]*qrcode, 8)
for i := 0; i < 8; i++ {
results[i] = newBarcode(dim)
results[i] = newBarCodeWithColor(dim, color)
}
occupied := newBarcode(dim)
occupied := newBarCodeWithColor(dim, color)
setAll := func(x int, y int, val bool) {
occupied.Set(x, y, true)

View file

@ -13,6 +13,7 @@ type qrcode struct {
dimension int
data *utils.BitList
content string
color barcode.ColorScheme
}
func (qr *qrcode) Content() string {
@ -24,7 +25,11 @@ func (qr *qrcode) Metadata() barcode.Metadata {
}
func (qr *qrcode) ColorModel() color.Model {
return color.Gray16Model
return qr.color.Model
}
func (c *qrcode) ColorScheme() barcode.ColorScheme {
return c.color
}
func (qr *qrcode) Bounds() image.Rectangle {
@ -33,9 +38,9 @@ func (qr *qrcode) Bounds() image.Rectangle {
func (qr *qrcode) At(x, y int) color.Color {
if qr.Get(x, y) {
return color.Black
return qr.color.Foreground
}
return color.White
return qr.color.Background
}
func (qr *qrcode) Get(x, y int) bool {
@ -158,9 +163,14 @@ func (qr *qrcode) calcPenaltyRule4() uint {
return uint(math.Min(floor, ceil) * 10)
}
func newBarcode(dim int) *qrcode {
func newBarCodeWithColor(dim int, color barcode.ColorScheme) *qrcode {
res := new(qrcode)
res.dimension = dim
res.data = utils.NewBitList(dim * dim)
res.color = color
return res
}
func newBarcode(dim int) *qrcode {
return newBarCodeWithColor(dim, barcode.ColorScheme16)
}

View file

@ -49,11 +49,22 @@ func (bc *intCSscaledBC) CheckSum() int {
// Scale returns a resized barcode with the given width and height.
func Scale(bc Barcode, width, height int) (Barcode, error) {
var fill color.Color
if v, ok := bc.(BarcodeColor); ok {
fill = v.ColorScheme().Background
} else {
fill = color.White
}
return ScaleWithFill(bc, width, height, fill)
}
// Scale returns a resized barcode with the given width, height and fill color.
func ScaleWithFill(bc Barcode, width, height int, fill color.Color) (Barcode, error) {
switch bc.Metadata().Dimensions {
case 1:
return scale1DCode(bc, width, height)
return scale1DCode(bc, width, height, fill)
case 2:
return scale2DCode(bc, width, height)
return scale2DCode(bc, width, height, fill)
}
return nil, errors.New("unsupported barcode format")
@ -72,7 +83,7 @@ func newScaledBC(wrapped Barcode, wrapperFunc wrapFunc, rect image.Rectangle) Ba
return result
}
func scale2DCode(bc Barcode, width, height int) (Barcode, error) {
func scale2DCode(bc Barcode, width, height int, fill color.Color) (Barcode, error) {
orgBounds := bc.Bounds()
orgWidth := orgBounds.Max.X - orgBounds.Min.X
orgHeight := orgBounds.Max.Y - orgBounds.Min.Y
@ -87,12 +98,12 @@ func scale2DCode(bc Barcode, width, height int) (Barcode, error) {
wrap := func(x, y int) color.Color {
if x < offsetX || y < offsetY {
return color.White
return fill
}
x = (x - offsetX) / factor
y = (y - offsetY) / factor
if x >= orgWidth || y >= orgHeight {
return color.White
return fill
}
return bc.At(x, y)
}
@ -104,7 +115,7 @@ func scale2DCode(bc Barcode, width, height int) (Barcode, error) {
), nil
}
func scale1DCode(bc Barcode, width, height int) (Barcode, error) {
func scale1DCode(bc Barcode, width, height int, fill color.Color) (Barcode, error) {
orgBounds := bc.Bounds()
orgWidth := orgBounds.Max.X - orgBounds.Min.X
factor := int(float64(width) / float64(orgWidth))
@ -116,12 +127,12 @@ func scale1DCode(bc Barcode, width, height int) (Barcode, error) {
wrap := func(x, y int) color.Color {
if x < offsetX {
return color.White
return fill
}
x = (x - offsetX) / factor
if x >= orgWidth {
return color.White
return fill
}
return bc.At(x, 0)
}

View file

@ -12,6 +12,7 @@ type base1DCode struct {
*BitList
kind string
content string
color barcode.ColorScheme
}
type base1DCodeIntCS struct {
@ -28,7 +29,11 @@ func (c *base1DCode) Metadata() barcode.Metadata {
}
func (c *base1DCode) ColorModel() color.Model {
return color.Gray16Model
return c.color.Model
}
func (c *base1DCode) ColorScheme() barcode.ColorScheme {
return c.color
}
func (c *base1DCode) Bounds() image.Rectangle {
@ -37,9 +42,9 @@ func (c *base1DCode) Bounds() image.Rectangle {
func (c *base1DCode) At(x, y int) color.Color {
if c.GetBit(x) {
return color.Black
return c.color.Foreground
}
return color.White
return c.color.Background
}
func (c *base1DCodeIntCS) CheckSum() int {
@ -48,10 +53,20 @@ func (c *base1DCodeIntCS) CheckSum() int {
// New1DCodeIntCheckSum creates a new 1D barcode where the bars are represented by the bits in the bars BitList
func New1DCodeIntCheckSum(codeKind, content string, bars *BitList, checksum int) barcode.BarcodeIntCS {
return &base1DCodeIntCS{base1DCode{bars, codeKind, content}, checksum}
return &base1DCodeIntCS{base1DCode{bars, codeKind, content, barcode.ColorScheme16}, checksum}
}
// New1DCodeIntCheckSum creates a new 1D barcode where the bars are represented by the bits in the bars BitList
func New1DCodeIntCheckSumWithColor(codeKind, content string, bars *BitList, checksum int, color barcode.ColorScheme) barcode.BarcodeIntCS {
return &base1DCodeIntCS{base1DCode{bars, codeKind, content, color}, checksum}
}
// New1DCode creates a new 1D barcode where the bars are represented by the bits in the bars BitList
func New1DCode(codeKind, content string, bars *BitList) barcode.Barcode {
return &base1DCode{bars, codeKind, content}
return &base1DCode{bars, codeKind, content, barcode.ColorScheme16}
}
// New1DCode creates a new 1D barcode where the bars are represented by the bits in the bars BitList
func New1DCodeWithColor(codeKind, content string, bars *BitList, color barcode.ColorScheme) barcode.Barcode {
return &base1DCode{bars, codeKind, content, color}
}