mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
Fixing lab colorspace component input ranges. Fix Indexed cs Image to rgb conversion.
This commit is contained in:
parent
d3d0312170
commit
e2bfa9094a
@ -202,6 +202,8 @@ func (this *ContentStreamProcessor) Process(resources *PdfPageResources) error {
|
|||||||
this.graphicsState.ColorNonStroking = NewPdfColorDeviceGray(0)
|
this.graphicsState.ColorNonStroking = NewPdfColorDeviceGray(0)
|
||||||
|
|
||||||
for _, op := range this.operations {
|
for _, op := range this.operations {
|
||||||
|
var err error
|
||||||
|
|
||||||
// Internal handling.
|
// Internal handling.
|
||||||
switch op.Operand {
|
switch op.Operand {
|
||||||
case "q":
|
case "q":
|
||||||
@ -211,65 +213,34 @@ func (this *ContentStreamProcessor) Process(resources *PdfPageResources) error {
|
|||||||
|
|
||||||
// Color operations (Table 74 p. 179)
|
// Color operations (Table 74 p. 179)
|
||||||
case "CS":
|
case "CS":
|
||||||
err := this.handleCommand_CS(op, resources)
|
err = this.handleCommand_CS(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "cs":
|
case "cs":
|
||||||
err := this.handleCommand_cs(op, resources)
|
err = this.handleCommand_cs(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "SC":
|
case "SC":
|
||||||
err := this.handleCommand_SC(op, resources)
|
err = this.handleCommand_SC(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "SCN":
|
case "SCN":
|
||||||
err := this.handleCommand_SCN(op, resources)
|
err = this.handleCommand_SCN(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "sc":
|
case "sc":
|
||||||
err := this.handleCommand_sc(op, resources)
|
err = this.handleCommand_sc(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "scn":
|
case "scn":
|
||||||
err := this.handleCommand_scn(op, resources)
|
err = this.handleCommand_scn(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "G":
|
case "G":
|
||||||
err := this.handleCommand_G(op, resources)
|
err = this.handleCommand_G(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "g":
|
case "g":
|
||||||
err := this.handleCommand_g(op, resources)
|
err = this.handleCommand_g(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "RG":
|
case "RG":
|
||||||
err := this.handleCommand_RG(op, resources)
|
err = this.handleCommand_RG(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "rg":
|
case "rg":
|
||||||
err := this.handleCommand_rg(op, resources)
|
err = this.handleCommand_rg(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "K":
|
case "K":
|
||||||
err := this.handleCommand_K(op, resources)
|
err = this.handleCommand_K(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case "k":
|
case "k":
|
||||||
err := this.handleCommand_k(op, resources)
|
err = this.handleCommand_k(op, resources)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Debug("Processor handling error (%s): %v", op.Operand, err)
|
||||||
|
common.Log.Debug("Operand: %#v", op.Operand)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if have external handler also, and process if so.
|
// Check if have external handler also, and process if so.
|
||||||
@ -440,6 +411,7 @@ func (this *ContentStreamProcessor) handleCommand_scn(op *ContentStreamOperation
|
|||||||
|
|
||||||
color, err := cs.ColorFromPdfObjects(op.Params)
|
color, err := cs.ColorFromPdfObjects(op.Params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
common.Log.Debug("ERROR: Fail to get color from params: %+v (CS is %+v)", op.Params, cs)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1413,19 +1413,34 @@ func (this *PdfColorspaceLab) ColorFromFloats(vals []float64) (PdfColor, error)
|
|||||||
|
|
||||||
// L
|
// L
|
||||||
l := vals[0]
|
l := vals[0]
|
||||||
if l < 0.0 || l > 1.0 {
|
if l < 0.0 || l > 100.0 {
|
||||||
|
common.Log.Debug("L out of range (got %v should be 0-100)", l)
|
||||||
return nil, errors.New("Range check")
|
return nil, errors.New("Range check")
|
||||||
}
|
}
|
||||||
|
|
||||||
// A
|
// A
|
||||||
a := vals[1]
|
a := vals[1]
|
||||||
if a < 0.0 || a > 1.0 {
|
aMin := float64(-100)
|
||||||
|
aMax := float64(100)
|
||||||
|
if len(this.Range) > 1 {
|
||||||
|
aMin = this.Range[0]
|
||||||
|
aMax = this.Range[1]
|
||||||
|
}
|
||||||
|
if a < aMin || a > aMax {
|
||||||
|
common.Log.Debug("A out of range (got %v; range %v to %v)", a, aMin, aMax)
|
||||||
return nil, errors.New("Range check")
|
return nil, errors.New("Range check")
|
||||||
}
|
}
|
||||||
|
|
||||||
// B.
|
// B.
|
||||||
b := vals[2]
|
b := vals[2]
|
||||||
if b < 0.0 || b > 1.0 {
|
bMin := float64(-100)
|
||||||
|
bMax := float64(100)
|
||||||
|
if len(this.Range) > 3 {
|
||||||
|
bMin = this.Range[2]
|
||||||
|
bMax = this.Range[3]
|
||||||
|
}
|
||||||
|
if b < bMin || b > bMax {
|
||||||
|
common.Log.Debug("b out of range (got %v; range %v to %v)", b, bMin, bMax)
|
||||||
return nil, errors.New("Range check")
|
return nil, errors.New("Range check")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1462,6 +1477,8 @@ func (this *PdfColorspaceLab) ColorToRGB(color PdfColor) (PdfColor, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get normalized L*, a*, b* values. [0-1]
|
// Get normalized L*, a*, b* values. [0-1]
|
||||||
|
// XXX/FIXME: According to the pdf standard these values are going to be in range 0-100, -100 - 100, -100 - 100
|
||||||
|
// by default.
|
||||||
LNorm := lab.L()
|
LNorm := lab.L()
|
||||||
ANorm := lab.A()
|
ANorm := lab.A()
|
||||||
BNorm := lab.B()
|
BNorm := lab.B()
|
||||||
@ -2207,7 +2224,15 @@ func (this *PdfColorspaceSpecialIndexed) ColorToRGB(color PdfColor) (PdfColor, e
|
|||||||
|
|
||||||
// Convert an indexed image to RGB.
|
// Convert an indexed image to RGB.
|
||||||
func (this *PdfColorspaceSpecialIndexed) ImageToRGB(img Image) (Image, error) {
|
func (this *PdfColorspaceSpecialIndexed) ImageToRGB(img Image) (Image, error) {
|
||||||
baseImage := img
|
//baseImage := img
|
||||||
|
// Make a new representation of the image to be converted with the base colorspace.
|
||||||
|
baseImage := Image{}
|
||||||
|
baseImage.Height = img.Height
|
||||||
|
baseImage.Width = img.Width
|
||||||
|
baseImage.alphaData = img.alphaData
|
||||||
|
baseImage.BitsPerComponent = img.BitsPerComponent
|
||||||
|
baseImage.hasAlpha = img.hasAlpha
|
||||||
|
baseImage.ColorComponents = img.ColorComponents
|
||||||
|
|
||||||
samples := img.GetSamples()
|
samples := img.GetSamples()
|
||||||
N := this.Base.GetNumComponents()
|
N := this.Base.GetNumComponents()
|
||||||
@ -2371,11 +2396,15 @@ func (this *PdfColorspaceSpecialSeparation) ColorFromFloats(vals []float64) (Pdf
|
|||||||
input := []float64{tint}
|
input := []float64{tint}
|
||||||
output, err := this.TintTransform.Evaluate(input)
|
output, err := this.TintTransform.Evaluate(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
common.Log.Debug("Error, failed to evaluate: %v", err)
|
||||||
|
common.Log.Trace("Tint transform: %+v", this.TintTransform)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
common.Log.Trace("Processing ColorFromFloats(%+v) on AlternateSpace: %#v", output, this.AlternateSpace)
|
||||||
color, err := this.AlternateSpace.ColorFromFloats(output)
|
color, err := this.AlternateSpace.ColorFromFloats(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
common.Log.Debug("Error, failed to evaluate in alternate space: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2469,6 +2498,7 @@ func (this *PdfColorspaceDeviceN) String() string {
|
|||||||
return "DeviceN"
|
return "DeviceN"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetNumComponents returns the number of input color components, i.e. that are input to the tint transform.
|
||||||
func (this *PdfColorspaceDeviceN) GetNumComponents() int {
|
func (this *PdfColorspaceDeviceN) GetNumComponents() int {
|
||||||
return len(*this.ColorantNames)
|
return len(*this.ColorantNames)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user