Improve code documentation

This commit is contained in:
Adrian-George Bostan 2019-01-23 18:57:01 +02:00
parent 83052bbc62
commit 195105ee56
4 changed files with 5 additions and 3 deletions

View File

@ -1048,7 +1048,7 @@ func (enc *DCTEncoder) EncodeBytes(data []byte) ([]byte, error) {
val := uint16(data[i])<<8 | uint16(data[i+1])
c = gocolor.Gray16{val}
} else {
// Account 1-bit/2-bit color images
// Account for 1-bit/2-bit color images.
val := uint32(data[i]) * 255 / uint32(math.Pow(2, float64(enc.BitsPerComponent))-1)
c = gocolor.Gray{uint8(val & 0xff)}
}

View File

@ -300,7 +300,7 @@ func (cs *PdfColorspaceDeviceGray) ImageToRGB(img Image) (Image, error) {
var rgbSamples []uint32
for i := 0; i < len(samples); i++ {
// Account 1-bit/2-bit color images
// Account for 1-bit/2-bit color images.
grayVal := samples[i] * 255 / uint32(math.Pow(2, float64(img.BitsPerComponent))-1)
rgbSamples = append(rgbSamples, grayVal, grayVal, grayVal)
}

View File

@ -171,7 +171,7 @@ func (img *Image) ToGoImage() (goimage.Image, error) {
val := uint16(samples[i])<<8 | uint16(samples[i+1])
c = gocolor.Gray16{val}
} else {
// Account 1-bit/2-bit color images
// Account for 1-bit/2-bit color images.
val := samples[i] * 255 / uint32(math.Pow(2, float64(img.BitsPerComponent))-1)
c = gocolor.Gray{uint8(val & 0xff)}
}

View File

@ -51,11 +51,13 @@ func scaleImage(stream *core.PdfObjectStream, scale float64) error {
return fmt.Errorf("optimization is not supported for color space %s", xImg.ColorSpace.String())
}
draw.CatmullRom.Scale(newImage, newImage.Bounds(), goimg, goimg.Bounds(), draw.Over, &draw.Options{})
i, err = model.ImageHandling.NewImageFromGoImage(newImage)
if err != nil {
return err
}
// NewImageFromGoImage always returns a RGBA image.
xImg.SetImage(i, model.NewPdfColorspaceDeviceRGB())
xImg.ToPdfObject()
return nil