github.com/pdfcpu/pdfcpu@v0.11.1/pkg/filter/dctDecode.go (about) 1 /* 2 Copyright 2021 The pdfcpu Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package filter 18 19 import ( 20 "bytes" 21 "encoding/gob" 22 "image/jpeg" 23 "io" 24 ) 25 26 type dctDecode struct { 27 baseFilter 28 } 29 30 // Encode implements encoding for a DCTDecode filter. 31 func (f dctDecode) Encode(r io.Reader) (io.Reader, error) { 32 33 return nil, nil 34 } 35 36 // Decode implements decoding for a DCTDecode filter. 37 func (f dctDecode) Decode(r io.Reader) (io.Reader, error) { 38 return f.DecodeLength(r, -1) 39 } 40 41 func (f dctDecode) DecodeLength(r io.Reader, maxLen int64) (io.Reader, error) { 42 im, err := jpeg.Decode(r) 43 if err != nil { 44 return nil, err 45 } 46 47 var b bytes.Buffer 48 49 enc := gob.NewEncoder(&b) 50 51 if err := enc.Encode(im); err != nil { 52 return nil, err 53 } 54 55 return &b, nil 56 }