func decodePbmRaw(r io.Reader, width, height, _ int) image.Image { im := img.NewBitmap(width, height) if _, err := io.ReadFull(r, im.Pix); err != nil { panic(err) } return im }
// decode reads an X11 bitmap from r and stores the result in d. func (d *decoder) decode(r io.Reader, configOnly bool) (im *img.Bitmap, err error) { defer func() { if r := recover(); r != nil { if s, ok := r.(string); ok { err = errors.New("xbm:" + s) } else { err = r.(error) } } }() // Add buffering if r does not provide ReadByte. if rr, ok := r.(reader); ok { d.r = rr } else { d.r = bufio.NewReader(r) } d.readHeader() if configOnly { return } im = img.NewBitmap(d.width, d.height) p := im.Pix if len(d.line) > 0 { p = d.scan(p, d.line) } for len(p) > 0 { line, isPfx, err := d.r.ReadLine() if isPfx { goto malformed } if err != nil { return nil, err } p = d.scan(p, line) } return malformed: return nil, errors.New("xbm: data probably malformed") }