mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
1 parent
33ae0b1a98
commit
365f3ba8f9
2 files changed
+17
-4
No files matched your search
@@ -249,7 +249,7 @@ func jpegColorProfile(ctx context.Context, data []byte, model color.Model) ([]by
|
|||||||
return profile, nil
|
return profile, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// jpegDisplayImage 统一JPEG显示变换,保留源分量并使用文档内嵌ICC
|
// jpegDisplayImage 统一JPEG显示变换,保留源分量并精确复用相邻同色的ICC结果
|
||||||
// 入参: ctx 取消上下文, source 源像素, profile 颜色配置,可为nil
|
// 入参: ctx 取消上下文, source 源像素, profile 颜色配置,可为nil
|
||||||
// 返回: image.Image 显示像素, error 变换或取消错误
|
// 返回: image.Image 显示像素, error 变换或取消错误
|
||||||
func jpegDisplayImage(ctx context.Context, source image.Image, profile *pdfgo.ColorSpace) (image.Image, error) {
|
func jpegDisplayImage(ctx context.Context, source image.Image, profile *pdfgo.ColorSpace) (image.Image, error) {
|
||||||
@@ -265,6 +265,12 @@ func jpegDisplayImage(ctx context.Context, source image.Image, profile *pdfgo.Co
|
|||||||
return nil, fmt.Errorf("JPEG color image dimensions exceed capacity")
|
return nil, fmt.Errorf("JPEG color image dimensions exceed capacity")
|
||||||
}
|
}
|
||||||
pixels := image.NewNRGBA64(bounds)
|
pixels := image.NewNRGBA64(bounds)
|
||||||
|
var intent pdfgo.Name
|
||||||
|
if profile != nil {
|
||||||
|
intent = profile.DefaultIntent()
|
||||||
|
}
|
||||||
|
var previous color.CMYK
|
||||||
|
var previousPixel color.NRGBA64
|
||||||
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
||||||
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
||||||
if (x-bounds.Min.X)&255 == 0 {
|
if (x-bounds.Min.X)&255 == 0 {
|
||||||
@@ -283,12 +289,18 @@ func jpegDisplayImage(ctx context.Context, source image.Image, profile *pdfgo.Co
|
|||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if previousPixel.A != 0 && ink == previous {
|
||||||
|
pixels.SetNRGBA64(x, y, previousPixel)
|
||||||
|
continue
|
||||||
|
}
|
||||||
values := [4]float64{float64(ink.C) / 255, float64(ink.M) / 255, float64(ink.Y) / 255, float64(ink.K) / 255}
|
values := [4]float64{float64(ink.C) / 255, float64(ink.M) / 255, float64(ink.Y) / 255, float64(ink.K) / 255}
|
||||||
rgb, err := profile.SRGB(values[:], profile.DefaultIntent())
|
rgb, err := profile.SRGB(values[:], intent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
pixels.SetNRGBA64(x, y, color.NRGBA64{R: colorWord(rgb[0]), G: colorWord(rgb[1]), B: colorWord(rgb[2]), A: 65535})
|
previous = ink
|
||||||
|
previousPixel = color.NRGBA64{R: colorWord(rgb[0]), G: colorWord(rgb[1]), B: colorWord(rgb[2]), A: 65535}
|
||||||
|
pixels.SetNRGBA64(x, y, previousPixel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &colorImage{NRGBA64: pixels, source: source}, nil
|
return &colorImage{NRGBA64: pixels, source: source}, nil
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ func applyImageColorProfile(ctx context.Context, source image.Image, profile *pd
|
|||||||
model := source.ColorModel()
|
model := source.ColorModel()
|
||||||
premultiplied := model == color.RGBAModel || model == color.RGBA64Model
|
premultiplied := model == color.RGBAModel || model == color.RGBA64Model
|
||||||
table := newTIFFProfileTable(source)
|
table := newTIFFProfileTable(source)
|
||||||
|
components, intent := profile.Components(), profile.DefaultIntent()
|
||||||
result := image.NewNRGBA64(bounds)
|
result := image.NewNRGBA64(bounds)
|
||||||
var previous [4]float64
|
var previous [4]float64
|
||||||
var previousPixel color.NRGBA64
|
var previousPixel color.NRGBA64
|
||||||
@@ -174,7 +175,7 @@ func applyImageColorProfile(ctx context.Context, source image.Image, profile *pd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rgb, err := profile.SRGB(values[:profile.Components()], profile.DefaultIntent())
|
rgb, err := profile.SRGB(values[:components], intent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user