├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── go.mod ├── go.sum ├── goheif.go ├── goheif_test.go ├── heic2jpg └── main.go ├── heif ├── LICENSE ├── README.md ├── bmff │ └── bmff.go ├── heif.go ├── heif_test.go └── testdata │ ├── park.heic │ └── rotate.heic ├── libde265 ├── README.md ├── extra │ ├── vendorkeep.go │ ├── win32cond.c │ └── win32cond.h ├── include_cgo.go ├── libde265-all.inl ├── libde265.cc ├── libde265.go └── libde265 │ ├── CMakeLists.txt │ ├── COPYING │ ├── Makefile.am │ ├── Makefile.vc7 │ ├── acceleration.h │ ├── alloc_pool.cc │ ├── alloc_pool.h │ ├── arm │ ├── Makefile.am │ ├── arm.cc │ ├── arm.h │ ├── asm.S │ ├── cpudetect.S │ ├── hevcdsp_qpel_neon.S │ ├── neon.S │ └── vendorkeep.go │ ├── bitstream.cc │ ├── bitstream.h │ ├── cabac.cc │ ├── cabac.h │ ├── configparam.cc │ ├── configparam.h │ ├── contextmodel.cc │ ├── contextmodel.h │ ├── de265-version.h │ ├── de265-version.h.in │ ├── de265.cc │ ├── de265.h │ ├── deblock.cc │ ├── deblock.h │ ├── decctx.cc │ ├── decctx.h │ ├── dpb.cc │ ├── dpb.h │ ├── en265.cc │ ├── en265.h │ ├── fallback-dct.cc │ ├── fallback-dct.h │ ├── fallback-motion.cc │ ├── fallback-motion.h │ ├── fallback.cc │ ├── fallback.h │ ├── image-io.cc │ ├── image-io.h │ ├── image.cc │ ├── image.h │ ├── intrapred.cc │ ├── intrapred.h │ ├── md5.cc │ ├── md5.h │ ├── motion.cc │ ├── motion.h │ ├── nal-parser.cc │ ├── nal-parser.h │ ├── nal.cc │ ├── nal.h │ ├── pps.cc │ ├── pps.h │ ├── quality.cc │ ├── quality.h │ ├── refpic.cc │ ├── refpic.h │ ├── sao.cc │ ├── sao.h │ ├── scan.cc │ ├── scan.h │ ├── sei.cc │ ├── sei.h │ ├── slice.cc │ ├── slice.h │ ├── sps.cc │ ├── sps.h │ ├── threads.cc │ ├── threads.h │ ├── transform.cc │ ├── transform.h │ ├── util.cc │ ├── util.h │ ├── vendorkeep.go │ ├── visualize.cc │ ├── visualize.h │ ├── vps.cc │ ├── vps.h │ ├── vui.cc │ ├── vui.h │ └── x86 │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── sse-dct.cc │ ├── sse-dct.h │ ├── sse-motion.cc │ ├── sse-motion.h │ ├── sse.cc │ ├── sse.h │ └── vendorkeep.go └── testdata └── camel.heic /.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-vendored 2 | *.go linguist-vendored=false 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | .vscode 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Jack Deng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | Note: The directories 'heif' and 'libde265' contain third-party code which is 24 | licensed under their respective licenses (Apache-2.0 and LGPL-3.0) as provided 25 | in those directories. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoHeif - A go gettable decoder/converter for HEIC based on libde265 2 | 3 | ## Install 4 | - `heic2jpg` to convert HEIC files to JPG preserving exif 5 | 6 | ``` go get github.com/jdeng/goheif/...``` 7 | 8 | - Tested 9 | - Mac OS X (High Sierra) 10 | - Linux (Ubuntu 16.04 / GCC 5.4) 11 | - Windows 7 64bit with TDM-GCC 32 (GCC 5.1) and golang 1.12 windows/386 12 | 13 | - Code Sample 14 | ``` 15 | func main() { 16 | flag.Parse() 17 | ... 18 | 19 | fin, fout := flag.Arg(0), flag.Arg(1) 20 | fi, err := os.Open(fin) 21 | if err != nil { 22 | log.Fatal(err) 23 | } 24 | defer fi.Close() 25 | 26 | exif, err := goheif.ExtractExif(fi) 27 | if err != nil { 28 | log.Printf("Warning: no EXIF from %s: %v\n", fin, err) 29 | } 30 | 31 | img, err := goheif.Decode(fi) 32 | if err != nil { 33 | log.Fatalf("Failed to parse %s: %v\n", fin, err) 34 | } 35 | 36 | fo, err := os.OpenFile(fout, os.O_RDWR|os.O_CREATE, 0644) 37 | if err != nil { 38 | log.Fatalf("Failed to create output file %s: %v\n", fout, err) 39 | } 40 | defer fo.Close() 41 | 42 | w, _ := newWriterExif(fo, exif) 43 | err = jpeg.Encode(w, img, nil) 44 | if err != nil { 45 | log.Fatalf("Failed to encode %s: %v\n", fout, err) 46 | } 47 | 48 | log.Printf("Convert %s to %s successfully\n", fin, fout) 49 | } 50 | ``` 51 | 52 | ## What is done 53 | 54 | - Changes make to @bradfitz's (https://github.com/bradfitz) golang heif parser 55 | - Some minor bugfixes 56 | - A few new box parsers, noteably 'iref' and 'hvcC' 57 | 58 | - Include libde265's source code (SSE by default enabled) and a simple golang binding 59 | 60 | - A Utility `heic2jpg` to illustrate the usage. 61 | 62 | ## License 63 | 64 | - heif and libde265 are in their own licenses 65 | 66 | - goheif.go, libde265 golang binding and the `heic2jpg` utility are in MIT license 67 | 68 | ## Credits 69 | - heif parser by @bradfitz (https://github.com/go4org/go4/tree/master/media/heif) 70 | - libde265 (https://github.com/strukturag/libde265) 71 | - implementation learnt from libheif (https://github.com/strukturag/libheif) 72 | 73 | ## TODO 74 | - Upstream the changes to heif? 75 | 76 | 77 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jdeng/goheif 2 | 3 | go 1.22.3 4 | 5 | require github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd 6 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd h1:CmH9+J6ZSsIjUK3dcGsnCnO41eRBOnY12zwkn5qVwgc= 2 | github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk= 3 | -------------------------------------------------------------------------------- /goheif.go: -------------------------------------------------------------------------------- 1 | package goheif 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "fmt" 7 | "image" 8 | "image/color" 9 | "io" 10 | 11 | "github.com/jdeng/goheif/heif" 12 | "github.com/jdeng/goheif/libde265" 13 | ) 14 | 15 | // SafeEncoding uses more memory but seems to make 16 | // the library safer to use in containers. 17 | var SafeEncoding bool 18 | 19 | type gridBox struct { 20 | columns, rows int 21 | width, height int 22 | } 23 | 24 | func newGridBox(data []byte) (*gridBox, error) { 25 | if len(data) < 8 { 26 | return nil, fmt.Errorf("invalid data") 27 | } 28 | // version := data[0] 29 | flags := data[1] 30 | rows := int(data[2]) + 1 31 | columns := int(data[3]) + 1 32 | 33 | var width, height int 34 | if (flags & 1) != 0 { 35 | if len(data) < 12 { 36 | return nil, fmt.Errorf("invalid data") 37 | } 38 | 39 | width = int(data[4])<<24 | int(data[5])<<16 | int(data[6])<<8 | int(data[7]) 40 | height = int(data[8])<<24 | int(data[9])<<16 | int(data[10])<<8 | int(data[11]) 41 | } else { 42 | width = int(data[4])<<8 | int(data[5]) 43 | height = int(data[6])<<8 | int(data[7]) 44 | } 45 | 46 | return &gridBox{columns: columns, rows: rows, width: width, height: height}, nil 47 | } 48 | 49 | func decodeHevcItem(dec *libde265.Decoder, hf *heif.File, item *heif.Item) (*image.YCbCr, error) { 50 | if item.Info.ItemType != "hvc1" { 51 | return nil, fmt.Errorf("unsupported item type: %s", item.Info.ItemType) 52 | } 53 | 54 | hvcc, ok := item.HevcConfig() 55 | if !ok { 56 | return nil, errors.New("no hvcC") 57 | } 58 | 59 | hdr := hvcc.AsHeader() 60 | data, err := hf.GetItemData(item) 61 | if err != nil { 62 | return nil, err 63 | } 64 | 65 | dec.Reset() 66 | dec.Push(hdr) 67 | tile, err := dec.DecodeImage(data) 68 | if err != nil { 69 | return nil, err 70 | } 71 | 72 | ycc, ok := tile.(*image.YCbCr) 73 | if !ok { 74 | return nil, errors.New("tile is not YCbCr") 75 | } 76 | 77 | return ycc, nil 78 | } 79 | 80 | func ExtractExif(ra io.ReaderAt) ([]byte, error) { 81 | hf := heif.Open(ra) 82 | return hf.EXIF() 83 | } 84 | 85 | func Decode(r io.Reader) (image.Image, error) { 86 | ra, err := asReaderAt(r) 87 | if err != nil { 88 | return nil, err 89 | } 90 | 91 | hf := heif.Open(ra) 92 | 93 | it, err := hf.PrimaryItem() 94 | if err != nil { 95 | return nil, err 96 | } 97 | 98 | width, height, ok := it.SpatialExtents() 99 | if !ok { 100 | return nil, errors.New("no dimension") 101 | } 102 | 103 | if it.Info == nil { 104 | return nil, errors.New("no item info") 105 | } 106 | 107 | dec, err := libde265.NewDecoder(libde265.WithSafeEncoding(SafeEncoding)) 108 | if err != nil { 109 | return nil, err 110 | } 111 | defer dec.Free() 112 | if it.Info.ItemType == "hvc1" { 113 | return decodeHevcItem(dec, hf, it) 114 | } 115 | 116 | if it.Info.ItemType != "grid" { 117 | return nil, errors.New("no grid") 118 | } 119 | 120 | data, err := hf.GetItemData(it) 121 | if err != nil { 122 | return nil, err 123 | } 124 | 125 | grid, err := newGridBox(data) 126 | if err != nil { 127 | return nil, err 128 | } 129 | 130 | dimg := it.Reference("dimg") 131 | if dimg == nil { 132 | return nil, errors.New("no dimg") 133 | } 134 | 135 | if len(dimg.ToItemIDs) != grid.columns*grid.rows { 136 | return nil, fmt.Errorf("tiles number not matched: %d != %d", len(dimg.ToItemIDs), grid.columns*grid.rows) 137 | } 138 | 139 | var out *image.YCbCr 140 | var tileWidth, tileHeight int 141 | for i, y := 0, 0; y < grid.rows; y++ { 142 | for x := 0; x < grid.columns; x++ { 143 | id := dimg.ToItemIDs[i] 144 | item, err := hf.ItemByID(id) 145 | if err != nil { 146 | return nil, err 147 | } 148 | 149 | ycc, err := decodeHevcItem(dec, hf, item) 150 | if err != nil { 151 | return nil, err 152 | } 153 | 154 | rect := ycc.Bounds() 155 | if tileWidth == 0 { 156 | tileWidth, tileHeight = rect.Dx(), rect.Dy() 157 | xwidth, xheight := tileWidth*grid.columns, tileHeight*grid.rows 158 | out = image.NewYCbCr(image.Rectangle{image.Pt(0, 0), image.Pt(xwidth, xheight)}, ycc.SubsampleRatio) 159 | } 160 | 161 | if tileWidth != rect.Dx() || tileHeight != rect.Dy() { 162 | return nil, errors.New("inconsistent tile dimensions") 163 | } 164 | 165 | // copy y stride data 166 | for j := 0; j < rect.Dy(); j += 1 { 167 | copy(out.Y[(y*tileHeight+j)*out.YStride+x*ycc.YStride:], ycc.Y[j*ycc.YStride:(j+1)*ycc.YStride]) 168 | } 169 | 170 | // height of c strides 171 | cHeight := len(ycc.Cb) / ycc.CStride 172 | 173 | // copy c stride data 174 | for j := 0; j < cHeight; j += 1 { 175 | copy(out.Cb[(y*cHeight+j)*out.CStride+x*ycc.CStride:], ycc.Cb[j*ycc.CStride:(j+1)*ycc.CStride]) 176 | copy(out.Cr[(y*cHeight+j)*out.CStride+x*ycc.CStride:], ycc.Cr[j*ycc.CStride:(j+1)*ycc.CStride]) 177 | } 178 | 179 | i++ 180 | } 181 | } 182 | 183 | //crop to actual size when applicable 184 | out.Rect = image.Rectangle{image.Pt(0, 0), image.Pt(width, height)} 185 | return out, nil 186 | } 187 | 188 | func DecodeConfig(r io.Reader) (image.Config, error) { 189 | var config image.Config 190 | 191 | ra, err := asReaderAt(r) 192 | if err != nil { 193 | return config, err 194 | } 195 | 196 | hf := heif.Open(ra) 197 | 198 | it, err := hf.PrimaryItem() 199 | if err != nil { 200 | return config, err 201 | } 202 | 203 | width, height, ok := it.SpatialExtents() 204 | if !ok { 205 | return config, errors.New("no dimension") 206 | } 207 | 208 | config = image.Config{ 209 | ColorModel: color.YCbCrModel, 210 | Width: width, 211 | Height: height, 212 | } 213 | return config, nil 214 | } 215 | 216 | func asReaderAt(r io.Reader) (io.ReaderAt, error) { 217 | if ra, ok := r.(io.ReaderAt); ok { 218 | return ra, nil 219 | } 220 | 221 | b, err := io.ReadAll(r) 222 | if err != nil { 223 | return nil, err 224 | } 225 | 226 | return bytes.NewReader(b), nil 227 | } 228 | 229 | func init() { 230 | libde265.Init() 231 | // they check for "ftyp" at the 5th bytes, let's do the same... 232 | // https://github.com/strukturag/libheif/blob/master/libheif/heif.cc#L94 233 | image.RegisterFormat("heic", "????ftyp", Decode, DecodeConfig) 234 | } 235 | -------------------------------------------------------------------------------- /goheif_test.go: -------------------------------------------------------------------------------- 1 | package goheif 2 | 3 | import ( 4 | "bytes" 5 | "image" 6 | "io" 7 | "os" 8 | "testing" 9 | ) 10 | 11 | func TestFormatRegistered(t *testing.T) { 12 | b, err := os.ReadFile("testdata/camel.heic") 13 | if err != nil { 14 | t.Fatal(err) 15 | } 16 | 17 | img, dec, err := image.Decode(bytes.NewReader(b)) 18 | if err != nil { 19 | t.Fatalf("unable to decode heic image: %s", err) 20 | } 21 | 22 | if got, want := dec, "heic"; got != want { 23 | t.Errorf("unexpected decoder: got %s, want %s", got, want) 24 | } 25 | 26 | if w, h := img.Bounds().Dx(), img.Bounds().Dy(); w != 1596 || h != 1064 { 27 | t.Errorf("unexpected decoded image size: got %dx%d, want 1596x1064", w, h) 28 | } 29 | } 30 | 31 | func BenchmarkSafeEncoding(b *testing.B) { 32 | benchEncoding(b, true) 33 | } 34 | 35 | func BenchmarkRegularEncoding(b *testing.B) { 36 | benchEncoding(b, false) 37 | } 38 | 39 | func benchEncoding(b *testing.B, safe bool) { 40 | b.Helper() 41 | 42 | currentSetting := SafeEncoding 43 | defer func() { 44 | SafeEncoding = currentSetting 45 | }() 46 | SafeEncoding = safe 47 | 48 | f, err := os.ReadFile("testdata/camel.heic") 49 | if err != nil { 50 | b.Fatal(err) 51 | } 52 | r := bytes.NewReader(f) 53 | 54 | b.ResetTimer() 55 | b.ReportAllocs() 56 | for i := 0; i < b.N; i++ { 57 | Decode(r) 58 | r.Seek(0, io.SeekStart) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /heic2jpg/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "image/jpeg" 7 | "io" 8 | "log" 9 | "os" 10 | 11 | "github.com/jdeng/goheif" 12 | ) 13 | 14 | // Skip Writer for exif writing 15 | type writerSkipper struct { 16 | w io.Writer 17 | bytesToSkip int 18 | } 19 | 20 | func (w *writerSkipper) Write(data []byte) (int, error) { 21 | if w.bytesToSkip <= 0 { 22 | return w.w.Write(data) 23 | } 24 | 25 | if dataLen := len(data); dataLen < w.bytesToSkip { 26 | w.bytesToSkip -= dataLen 27 | return dataLen, nil 28 | } 29 | 30 | if n, err := w.w.Write(data[w.bytesToSkip:]); err == nil { 31 | n += w.bytesToSkip 32 | w.bytesToSkip = 0 33 | return n, nil 34 | } else { 35 | return n, err 36 | } 37 | } 38 | 39 | func newWriterExif(w io.Writer, exif []byte) (io.Writer, error) { 40 | writer := &writerSkipper{w, 2} 41 | soi := []byte{0xff, 0xd8} 42 | if _, err := w.Write(soi); err != nil { 43 | return nil, err 44 | } 45 | 46 | if exif != nil { 47 | app1Marker := 0xe1 48 | markerlen := 2 + len(exif) 49 | marker := []byte{0xff, uint8(app1Marker), uint8(markerlen >> 8), uint8(markerlen & 0xff)} 50 | if _, err := w.Write(marker); err != nil { 51 | return nil, err 52 | } 53 | 54 | if _, err := w.Write(exif); err != nil { 55 | return nil, err 56 | } 57 | } 58 | 59 | return writer, nil 60 | } 61 | 62 | func main() { 63 | flag.Parse() 64 | if flag.NArg() != 2 { 65 | fmt.Fprintf(os.Stderr, "usage: heic2jpg \n") 66 | os.Exit(1) 67 | } 68 | 69 | fin, fout := flag.Arg(0), flag.Arg(1) 70 | fi, err := os.Open(fin) 71 | if err != nil { 72 | log.Fatal(err) 73 | } 74 | defer fi.Close() 75 | 76 | exif, err := goheif.ExtractExif(fi) 77 | if err != nil { 78 | log.Printf("Warning: no EXIF from %s: %v\n", fin, err) 79 | } 80 | 81 | img, err := goheif.Decode(fi) 82 | if err != nil { 83 | log.Fatalf("Failed to parse %s: %v\n", fin, err) 84 | } 85 | 86 | fo, err := os.OpenFile(fout, os.O_RDWR|os.O_CREATE, 0644) 87 | if err != nil { 88 | log.Fatalf("Failed to create output file %s: %v\n", fout, err) 89 | } 90 | defer fo.Close() 91 | 92 | w, _ := newWriterExif(fo, exif) 93 | err = jpeg.Encode(w, img, nil) 94 | if err != nil { 95 | log.Fatalf("Failed to encode %s: %v\n", fout, err) 96 | } 97 | 98 | log.Printf("Convert %s to %s successfully\n", fin, fout) 99 | } 100 | -------------------------------------------------------------------------------- /heif/README.md: -------------------------------------------------------------------------------- 1 | This directory is copied from https://github.com/go4org/go4/tree/master/media/heif with modifications in `heif.go` and `bmff.go`. 2 | -------------------------------------------------------------------------------- /heif/heif_test.go: -------------------------------------------------------------------------------- 1 | package heif 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "os" 7 | "testing" 8 | 9 | "github.com/rwcarlsen/goexif/exif" 10 | "github.com/rwcarlsen/goexif/tiff" 11 | ) 12 | 13 | func TestAll(t *testing.T) { 14 | f, err := os.Open("testdata/park.heic") 15 | if err != nil { 16 | t.Fatal(err) 17 | } 18 | defer f.Close() 19 | h := Open(f) 20 | 21 | // meta 22 | _, err = h.getMeta() 23 | if err != nil { 24 | t.Fatalf("getMeta: %v", err) 25 | } 26 | 27 | it, err := h.PrimaryItem() 28 | if err != nil { 29 | t.Fatalf("PrimaryItem: %v", err) 30 | } 31 | if want := uint32(49); it.ID != want { 32 | t.Errorf("PrimaryIem ID = %v; want %v", it.ID, want) 33 | } 34 | if it.Location == nil { 35 | t.Errorf("Item.Location is nil") 36 | } 37 | if it.Info == nil { 38 | t.Errorf("Item.Info is nil") 39 | } 40 | if len(it.Properties) == 0 { 41 | t.Errorf("Item.Properties is empty") 42 | } 43 | for _, prop := range it.Properties { 44 | t.Logf(" property: %q, %#v", prop.Type(), prop) 45 | } 46 | if w, h, ok := it.SpatialExtents(); !ok || w == 0 || h == 0 { 47 | t.Errorf("no spatial extents found") 48 | } else { 49 | t.Logf("dimensions: %v x %v", w, h) 50 | } 51 | 52 | // exif 53 | exbuf, err := h.EXIF() 54 | if err != nil { 55 | t.Errorf("EXIF: %v", err) 56 | } else { 57 | const magic = "Exif\x00\x00" 58 | if !bytes.HasPrefix(exbuf, []byte(magic)) { 59 | t.Errorf("Exif buffer doesn't start with %q: got %q", magic, exbuf) 60 | } 61 | x, err := exif.Decode(bytes.NewReader(exbuf)) 62 | if err != nil { 63 | t.Fatalf("EXIF decode: %v", err) 64 | } 65 | got := map[string]string{} 66 | if err := x.Walk(walkFunc(func(name exif.FieldName, tag *tiff.Tag) error { 67 | got[fmt.Sprint(name)] = fmt.Sprint(tag) 68 | return nil 69 | })); err != nil { 70 | t.Fatalf("EXIF walk: %v", err) 71 | } 72 | if g, w := len(got), 56; g < w { 73 | t.Errorf("saw %v EXIF tags; want at least %v", g, w) 74 | } 75 | if g, w := got["GPSLongitude"], `["122/1","21/1","3776/100"]`; g != w { 76 | t.Errorf("GPSLongitude = %#q; want %#q", g, w) 77 | } 78 | 79 | } 80 | } 81 | 82 | func TestRotations(t *testing.T) { 83 | f, err := os.Open("testdata/rotate.heic") 84 | if err != nil { 85 | t.Fatal(err) 86 | } 87 | defer f.Close() 88 | h := Open(f) 89 | it, err := h.PrimaryItem() 90 | if err != nil { 91 | t.Fatalf("PrimaryItem: %v", err) 92 | } 93 | if r := it.Rotations(); r != 3 { 94 | t.Errorf("Rotations = %v; want %v", r, 3) 95 | } 96 | sw, sh, ok := it.SpatialExtents() 97 | if !ok { 98 | t.Fatalf("expected spatial extents") 99 | } 100 | vw, vh, ok := it.VisualDimensions() 101 | if !ok { 102 | t.Fatalf("expected visual dimensions") 103 | } 104 | if vw != sh || vh != sw { 105 | t.Errorf("visual dimensions = %v, %v; want %v, %v", vw, vh, sh, sw) 106 | } 107 | } 108 | 109 | type walkFunc func(exif.FieldName, *tiff.Tag) error 110 | 111 | func (f walkFunc) Walk(name exif.FieldName, tag *tiff.Tag) error { 112 | return f(name, tag) 113 | } 114 | -------------------------------------------------------------------------------- /heif/testdata/park.heic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdeng/goheif/0b111b5c3adb32c9d0c76c60c58d5787782edb22/heif/testdata/park.heic -------------------------------------------------------------------------------- /heif/testdata/rotate.heic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdeng/goheif/0b111b5c3adb32c9d0c76c60c58d5787782edb22/heif/testdata/rotate.heic -------------------------------------------------------------------------------- /libde265/README.md: -------------------------------------------------------------------------------- 1 | The `libde265` directory is copied from https://github.com/strukturag/libde265/tree/master/libde265. Encoder code is removed. 2 | -------------------------------------------------------------------------------- /libde265/extra/vendorkeep.go: -------------------------------------------------------------------------------- 1 | //go:build vendorkeep 2 | // +build vendorkeep 3 | 4 | package cgowrapper 5 | -------------------------------------------------------------------------------- /libde265/extra/win32cond.c: -------------------------------------------------------------------------------- 1 | /** 2 | * pthread_cond API for Win32 3 | * 4 | * ACE(TM), TAO(TM), CIAO(TM), DAnCE>(TM), and CoSMIC(TM) (henceforth 5 | * referred to as "DOC software") are copyrighted by Douglas C. Schmidt 6 | * and his research group at Washington University, University of California, 7 | * Irvine, and Vanderbilt University, Copyright (c) 1993-2009, all rights 8 | * reserved. 9 | * 10 | * Since DOC software is open-source, freely available software, you are free 11 | * to use, modify, copy, and distribute--perpetually and irrevocably--the DOC 12 | * software source code and object code produced from the source, as well as 13 | * copy and distribute modified versions of this software. You must, however, 14 | * include this copyright statement along with any code built using DOC 15 | * software that you release. 16 | * 17 | * No copyright statement needs to be provided if you just ship binary 18 | * executables of your software products. 19 | * 20 | * See "Strategies for Implementing POSIX Condition Variables on Win32" at 21 | * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html 22 | */ 23 | 24 | #include 25 | 26 | #include "win32cond.h" 27 | 28 | int win32_cond_init(win32_cond_t *cv) 29 | { 30 | cv->waiters_count_ = 0; 31 | cv->was_broadcast_ = 0; 32 | cv->sema_ = CreateSemaphore (NULL, // no security 33 | 0, // initially 0 34 | 0x7fffffff, // max count 35 | NULL); // unnamed 36 | InitializeCriticalSection (&cv->waiters_count_lock_); 37 | cv->waiters_done_ = CreateEvent (NULL, // no security 38 | FALSE, // auto-reset 39 | FALSE, // non-signaled initially 40 | NULL); // unnamed 41 | return 0; 42 | } 43 | 44 | int win32_cond_destroy(win32_cond_t *cv) 45 | { 46 | CloseHandle(cv->waiters_done_); 47 | DeleteCriticalSection(&cv->waiters_count_lock_); 48 | CloseHandle(cv->sema_); 49 | return 0; 50 | } 51 | 52 | int win32_cond_wait(win32_cond_t *cv, HANDLE *external_mutex) 53 | { 54 | int last_waiter; 55 | 56 | // Avoid race conditions. 57 | EnterCriticalSection (&cv->waiters_count_lock_); 58 | cv->waiters_count_++; 59 | LeaveCriticalSection (&cv->waiters_count_lock_); 60 | 61 | // This call atomically releases the mutex and waits on the 62 | // semaphore until or 63 | // are called by another thread. 64 | SignalObjectAndWait (*external_mutex, cv->sema_, INFINITE, FALSE); 65 | 66 | // Reacquire lock to avoid race conditions. 67 | EnterCriticalSection (&cv->waiters_count_lock_); 68 | 69 | // We're no longer waiting... 70 | cv->waiters_count_--; 71 | 72 | // Check to see if we're the last waiter after . 73 | last_waiter = cv->was_broadcast_ && cv->waiters_count_ == 0; 74 | 75 | LeaveCriticalSection (&cv->waiters_count_lock_); 76 | 77 | // If we're the last waiter thread during this particular broadcast 78 | // then let all the other threads proceed. 79 | if (last_waiter) 80 | // This call atomically signals the event and waits until 81 | // it can acquire the . This is required to ensure fairness. 82 | SignalObjectAndWait (cv->waiters_done_, *external_mutex, INFINITE, FALSE); 83 | else 84 | // Always regain the external mutex since that's the guarantee we 85 | // give to our callers. 86 | WaitForSingleObject (*external_mutex, INFINITE); 87 | return 0; 88 | } 89 | 90 | int win32_cond_signal(win32_cond_t *cv) 91 | { 92 | int have_waiters; 93 | 94 | EnterCriticalSection (&cv->waiters_count_lock_); 95 | have_waiters = cv->waiters_count_ > 0; 96 | LeaveCriticalSection (&cv->waiters_count_lock_); 97 | 98 | // If there aren't any waiters, then this is a no-op. 99 | if (have_waiters) 100 | ReleaseSemaphore (cv->sema_, 1, 0); 101 | return 0; 102 | } 103 | 104 | int win32_cond_broadcast(win32_cond_t *cv) 105 | { 106 | int have_waiters = 0; 107 | 108 | // This is needed to ensure that and are 109 | // consistent relative to each other. 110 | EnterCriticalSection (&cv->waiters_count_lock_); 111 | 112 | if (cv->waiters_count_ > 0) { 113 | // We are broadcasting, even if there is just one waiter... 114 | // Record that we are broadcasting, which helps optimize 115 | // for the non-broadcast case. 116 | cv->was_broadcast_ = 1; 117 | have_waiters = 1; 118 | } 119 | 120 | if (have_waiters) { 121 | // Wake up all the waiters atomically. 122 | ReleaseSemaphore (cv->sema_, cv->waiters_count_, 0); 123 | 124 | LeaveCriticalSection (&cv->waiters_count_lock_); 125 | 126 | // Wait for all the awakened threads to acquire the counting 127 | // semaphore. 128 | WaitForSingleObject (cv->waiters_done_, INFINITE); 129 | // This assignment is okay, even without the held 130 | // because no other waiter threads can wake up to access it. 131 | cv->was_broadcast_ = 0; 132 | } 133 | else 134 | LeaveCriticalSection (&cv->waiters_count_lock_); 135 | return 0; 136 | } 137 | -------------------------------------------------------------------------------- /libde265/extra/win32cond.h: -------------------------------------------------------------------------------- 1 | #ifndef WIN32COND_H 2 | #define WIN32COND_H 3 | 4 | /** 5 | * pthread_cond API for Win32 6 | * 7 | * ACE(TM), TAO(TM), CIAO(TM), DAnCE>(TM), and CoSMIC(TM) (henceforth 8 | * referred to as "DOC software") are copyrighted by Douglas C. Schmidt 9 | * and his research group at Washington University, University of California, 10 | * Irvine, and Vanderbilt University, Copyright (c) 1993-2009, all rights 11 | * reserved. 12 | * 13 | * Since DOC software is open-source, freely available software, you are free 14 | * to use, modify, copy, and distribute--perpetually and irrevocably--the DOC 15 | * software source code and object code produced from the source, as well as 16 | * copy and distribute modified versions of this software. You must, however, 17 | * include this copyright statement along with any code built using DOC 18 | * software that you release. 19 | * 20 | * No copyright statement needs to be provided if you just ship binary 21 | * executables of your software products. 22 | * 23 | * See "Strategies for Implementing POSIX Condition Variables on Win32" at 24 | * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html 25 | */ 26 | 27 | #include 28 | 29 | typedef struct 30 | { 31 | long waiters_count_; 32 | // Number of waiting threads. 33 | 34 | CRITICAL_SECTION waiters_count_lock_; 35 | // Serialize access to . 36 | 37 | HANDLE sema_; 38 | // Semaphore used to queue up threads waiting for the condition to 39 | // become signaled. 40 | 41 | HANDLE waiters_done_; 42 | // An auto-reset event used by the broadcast/signal thread to wait 43 | // for all the waiting thread(s) to wake up and be released from the 44 | // semaphore. 45 | 46 | size_t was_broadcast_; 47 | // Keeps track of whether we were broadcasting or signaling. This 48 | // allows us to optimize the code if we're just signaling. 49 | } win32_cond_t; 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | int win32_cond_init(win32_cond_t *cv); 56 | int win32_cond_destroy(win32_cond_t *cv); 57 | int win32_cond_wait(win32_cond_t *cv, HANDLE *external_mutex); 58 | int win32_cond_signal(win32_cond_t *cv); 59 | int win32_cond_broadcast(win32_cond_t *cv); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /libde265/include_cgo.go: -------------------------------------------------------------------------------- 1 | //go:build vendorkeep 2 | // +build vendorkeep 3 | 4 | package libde265 5 | 6 | // https://github.com/golang/go/issues/26366 7 | 8 | // This file exists purely to prevent the golang toolchain from stripping 9 | // away the c source directories and files when `go mod vendor` is used 10 | // to populate a `vendor/` directory of a project depending on `goheif`. 11 | // 12 | // How it works: 13 | // - every directory which only includes c/c++ source files receives a 14 | // vendorkeep.go file. 15 | // - every directory we want to preserve is included here as a _ import. 16 | // - every dummy go file is given a build tag to exclude it from the regular 17 | // build. 18 | 19 | import ( 20 | // Prevent go tooling from stripping out the c source files. 21 | _ "github.com/jdeng/goheif/libde265/extra" 22 | _ "github.com/jdeng/goheif/libde265/libde265" 23 | _ "github.com/jdeng/goheif/libde265/libde265/arm" 24 | _ "github.com/jdeng/goheif/libde265/libde265/x86" 25 | ) 26 | -------------------------------------------------------------------------------- /libde265/libde265-all.inl: -------------------------------------------------------------------------------- 1 | #if _WIN32 2 | #include "extra/win32cond.c" 3 | #define HAVE___MINGW_ALIGNED_MALLOC 1 4 | #else 5 | #define HAVE_POSIX_MEMALIGN 1 6 | #endif 7 | 8 | //#define HAVE_NEON 1 // disable NEON for ARM as cgo wont compile the .S files 9 | 10 | #include "alloc_pool.cc" 11 | #include "bitstream.cc" 12 | #include "cabac.cc" 13 | #include "configparam.cc" 14 | #include "contextmodel.cc" 15 | #include "de265.cc" 16 | #include "deblock.cc" 17 | #include "decctx.cc" 18 | #include "dpb.cc" 19 | // #include "en265.cc" 20 | #include "fallback-dct.cc" 21 | #include "fallback-motion.cc" 22 | #include "fallback.cc" 23 | #include "image-io.cc" 24 | #include "image.cc" 25 | #include "intrapred.cc" 26 | #include "md5.cc" 27 | #include "motion.cc" 28 | #include "nal-parser.cc" 29 | #include "nal.cc" 30 | #include "pps.cc" 31 | #include "quality.cc" 32 | #include "refpic.cc" 33 | #include "sao.cc" 34 | #include "scan.cc" 35 | #include "sei.cc" 36 | #include "slice.cc" 37 | #include "sps.cc" 38 | #include "threads.cc" 39 | #include "transform.cc" 40 | #include "util.cc" 41 | #include "visualize.cc" 42 | #include "vps.cc" 43 | #include "vui.cc" 44 | 45 | #ifdef HAVE_SSE4_1 46 | #include "x86/sse-dct.cc" 47 | #include "x86/sse-motion.cc" 48 | #include "x86/sse.cc" 49 | #endif 50 | 51 | #ifdef HAVE_ARM 52 | #include "arm/arm.cc" 53 | #endif 54 | 55 | 56 | -------------------------------------------------------------------------------- /libde265/libde265.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include "libde265-all.inl" 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /libde265/libde265.go: -------------------------------------------------------------------------------- 1 | package libde265 2 | 3 | //#cgo CFLAGS: -I. 4 | //#cgo amd64 CXXFLAGS: -Ilibde265 -I. -std=c++11 -DHAVE_SSE4_1 -msse4.1 5 | //#cgo arm64 CXXFLAGS: -Ilibde265 -I. -std=c++11 -DHAVE_ARM 6 | //#cgo darwin,amd64 CXXFLAGS: -Ilibde265 -I. -std=c++11 -DHAVE_SSE4_1 -msse4.1 -Wno-constant-conversion 7 | //#cgo darwin,amd64 CXXFLAGS: -Ilibde265 -I. -std=c++11 -DHAVE_ARM 8 | // #include 9 | // #include 10 | // #include "libde265/de265.h" 11 | import "C" 12 | 13 | import ( 14 | "errors" 15 | "fmt" 16 | "image" 17 | "unsafe" 18 | ) 19 | 20 | type Decoder struct { 21 | ctx unsafe.Pointer 22 | hasImage bool 23 | safeEncode bool 24 | } 25 | 26 | func Init() { 27 | C.de265_init() 28 | } 29 | 30 | func Fini() { 31 | C.de265_free() 32 | } 33 | 34 | func NewDecoder(opts ...Option) (*Decoder, error) { 35 | p := C.de265_new_decoder() 36 | if p == nil { 37 | return nil, errors.New("unable to create decoder") 38 | } 39 | 40 | dec := &Decoder{ctx: p, hasImage: false} 41 | for _, opt := range opts { 42 | opt(dec) 43 | } 44 | 45 | return dec, nil 46 | } 47 | 48 | type Option func(*Decoder) 49 | 50 | func WithSafeEncoding(b bool) Option { 51 | return func(dec *Decoder) { 52 | dec.safeEncode = b 53 | } 54 | } 55 | 56 | func (dec *Decoder) Free() { 57 | dec.Reset() 58 | C.de265_free_decoder(dec.ctx) 59 | } 60 | 61 | func (dec *Decoder) Reset() { 62 | if dec.ctx != nil && dec.hasImage { 63 | C.de265_release_next_picture(dec.ctx) 64 | dec.hasImage = false 65 | } 66 | 67 | C.de265_reset(dec.ctx) 68 | } 69 | 70 | func (dec *Decoder) Push(data []byte) error { 71 | var pos int 72 | totalSize := len(data) 73 | for pos < totalSize { 74 | if pos+4 > totalSize { 75 | return errors.New("invalid NAL data") 76 | } 77 | 78 | nalSize := uint32(data[pos])<<24 | uint32(data[pos+1])<<16 | uint32(data[pos+2])<<8 | uint32(data[pos+3]) 79 | pos += 4 80 | 81 | if pos+int(nalSize) > totalSize { 82 | return fmt.Errorf("invalid NAL size: %d", nalSize) 83 | } 84 | 85 | C.de265_push_NAL(dec.ctx, unsafe.Pointer(&data[pos]), C.int(nalSize), C.de265_PTS(0), nil) 86 | pos += int(nalSize) 87 | } 88 | 89 | return nil 90 | } 91 | 92 | func (dec *Decoder) DecodeImage(data []byte) (image.Image, error) { 93 | if dec.hasImage { 94 | fmt.Printf("previous image may leak") 95 | } 96 | 97 | if len(data) > 0 { 98 | if err := dec.Push(data); err != nil { 99 | return nil, err 100 | } 101 | } 102 | 103 | if ret := C.de265_flush_data(dec.ctx); ret != C.DE265_OK { 104 | return nil, fmt.Errorf("flush_data error: %d", ret) 105 | } 106 | 107 | var more C.int = 1 108 | for more != 0 { 109 | if decerr := C.de265_decode(dec.ctx, &more); decerr != C.DE265_OK { 110 | return nil, fmt.Errorf("decode error: %d", decerr) 111 | } 112 | 113 | for { 114 | warning := C.de265_get_warning(dec.ctx) 115 | if warning == C.DE265_OK { 116 | break 117 | } 118 | fmt.Printf("warning: %v\n", C.GoString(C.de265_get_error_text(warning))) 119 | } 120 | 121 | if img := C.de265_get_next_picture(dec.ctx); img != nil { 122 | dec.hasImage = true // lazy release 123 | 124 | width := C.de265_get_image_width(img, 0) 125 | height := C.de265_get_image_height(img, 0) 126 | 127 | var ystride, cstride C.int 128 | y := C.de265_get_image_plane(img, 0, &ystride) 129 | cb := C.de265_get_image_plane(img, 1, &cstride) 130 | cheight := C.de265_get_image_height(img, 1) 131 | cr := C.de265_get_image_plane(img, 2, &cstride) 132 | // crh := C.de265_get_image_height(img, 2) 133 | 134 | // sanity check 135 | if int(height)*int(ystride) >= int(1<<30) { 136 | return nil, fmt.Errorf("image too big") 137 | } 138 | 139 | var r image.YCbCrSubsampleRatio 140 | switch chroma := C.de265_get_chroma_format(img); chroma { 141 | case C.de265_chroma_420: 142 | r = image.YCbCrSubsampleRatio420 143 | case C.de265_chroma_422: 144 | r = image.YCbCrSubsampleRatio422 145 | case C.de265_chroma_444: 146 | r = image.YCbCrSubsampleRatio444 147 | } 148 | ycc := &image.YCbCr{ 149 | YStride: int(ystride), 150 | CStride: int(cstride), 151 | SubsampleRatio: r, 152 | Rect: image.Rectangle{Min: image.Point{0, 0}, Max: image.Point{int(width), int(height)}}, 153 | } 154 | if dec.safeEncode { 155 | ycc.Y = C.GoBytes(unsafe.Pointer(y), C.int(height*ystride)) 156 | ycc.Cb = C.GoBytes(unsafe.Pointer(cb), C.int(cheight*cstride)) 157 | ycc.Cr = C.GoBytes(unsafe.Pointer(cr), C.int(cheight*cstride)) 158 | } else { 159 | // Calculate the exact sizes needed 160 | ySize := int(height) * int(ystride) 161 | cSize := int(cheight) * int(cstride) 162 | 163 | // Create slices directly from pointers with exact sizes 164 | ycc.Y = unsafe.Slice((*byte)(y), ySize) 165 | ycc.Cb = unsafe.Slice((*byte)(cb), cSize) 166 | ycc.Cr = unsafe.Slice((*byte)(cr), cSize) 167 | } 168 | 169 | //C.de265_release_next_picture(dec.ctx) 170 | 171 | return ycc, nil 172 | } 173 | } 174 | 175 | return nil, errors.New("no picture") 176 | } 177 | -------------------------------------------------------------------------------- /libde265/libde265/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CMakePackageConfigHelpers) 2 | 3 | set (libde265_sources 4 | alloc_pool.cc 5 | bitstream.cc 6 | cabac.cc 7 | configparam.cc 8 | contextmodel.cc 9 | de265.cc 10 | deblock.cc 11 | decctx.cc 12 | dpb.cc 13 | en265.cc 14 | fallback-dct.cc 15 | fallback-motion.cc 16 | fallback.cc 17 | image-io.cc 18 | image.cc 19 | intrapred.cc 20 | md5.cc 21 | motion.cc 22 | nal-parser.cc 23 | nal.cc 24 | pps.cc 25 | quality.cc 26 | refpic.cc 27 | sao.cc 28 | scan.cc 29 | sei.cc 30 | slice.cc 31 | sps.cc 32 | threads.cc 33 | transform.cc 34 | util.cc 35 | visualize.cc 36 | vps.cc 37 | vui.cc 38 | ) 39 | 40 | set (libde265_headers 41 | acceleration.h 42 | alloc_pool.h 43 | bitstream.h 44 | cabac.h 45 | configparam.h 46 | de265-version.h 47 | contextmodel.h 48 | de265.h 49 | deblock.h 50 | decctx.h 51 | dpb.h 52 | en265.h 53 | fallback-dct.h 54 | fallback-motion.h 55 | fallback.h 56 | image-io.h 57 | image.h 58 | intrapred.h 59 | md5.h 60 | motion.h 61 | nal-parser.h 62 | nal.h 63 | pps.h 64 | quality.h 65 | refpic.h 66 | sao.h 67 | scan.h 68 | sei.h 69 | slice.h 70 | sps.h 71 | threads.h 72 | transform.h 73 | util.h 74 | visualize.h 75 | vps.h 76 | vui.h 77 | ) 78 | 79 | set (libde265_public_headers 80 | de265.h 81 | en265.h 82 | ${CMAKE_CURRENT_BINARY_DIR}/de265-version.h 83 | ) 84 | 85 | if(MSVC OR MINGW) 86 | set (libde265_sources 87 | ${libde265_sources} 88 | ../extra/win32cond.c 89 | ../extra/win32cond.h 90 | ) 91 | endif() 92 | 93 | add_definitions(-DLIBDE265_EXPORTS) 94 | 95 | add_subdirectory (encoder) 96 | 97 | check_c_source_compiles( 98 | "#if !defined(__x86_64) && !defined(__i386__) \ 99 | && !defined(_M_IX86) && !defined(_M_AMD64) 100 | #error not x86 101 | #endif 102 | int main(){return 0;}" 103 | HAVE_X86) 104 | 105 | if(HAVE_X86) 106 | if (MSVC) 107 | set(SUPPORTS_SSE2 1) 108 | set(SUPPORTS_SSSE3 1) 109 | set(SUPPORTS_SSE4_1 1) 110 | else (MSVC) 111 | check_c_compiler_flag(-msse2 SUPPORTS_SSE2) 112 | check_c_compiler_flag(-mssse3 SUPPORTS_SSSE3) 113 | check_c_compiler_flag(-msse4.1 SUPPORTS_SSE4_1) 114 | endif (MSVC) 115 | 116 | if(SUPPORTS_SSE4_1) 117 | add_definitions(-DHAVE_SSE4_1) 118 | endif() 119 | if(SUPPORTS_SSE4_1 OR (SUPPORTS_SSE2 AND SUPPORTS_SSSE3)) 120 | add_subdirectory (x86) 121 | endif() 122 | endif() 123 | 124 | add_library(de265 ${libde265_sources} ${ENCODER_OBJECTS} ${X86_OBJECTS}) 125 | target_link_libraries(de265 PRIVATE Threads::Threads) 126 | target_include_directories(de265 PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}) 127 | 128 | write_basic_package_version_file(libde265ConfigVersion.cmake COMPATIBILITY ExactVersion) 129 | 130 | if (WIN32) 131 | set_target_properties(de265 PROPERTIES PREFIX "lib") 132 | endif() 133 | 134 | install(TARGETS de265 EXPORT libde265Config 135 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 136 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 137 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 138 | ) 139 | 140 | install(FILES ${libde265_public_headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libde265) 141 | install(EXPORT libde265Config DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libde265") 142 | 143 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libde265ConfigVersion.cmake DESTINATION 144 | "${CMAKE_INSTALL_LIBDIR}/cmake/libde265") 145 | 146 | 147 | # --- pkg-config 148 | 149 | set(prefix ${CMAKE_INSTALL_PREFIX}) 150 | set(exec_prefix "\${prefix}") 151 | if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") 152 | set(libdir "${CMAKE_INSTALL_LIBDIR}") 153 | else() 154 | set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") 155 | endif() 156 | if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") 157 | set(includedir "${CMAKE_INSTALL_INCLUDEDIR}") 158 | else() 159 | set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") 160 | endif() 161 | 162 | set(VERSION ${PROJECT_VERSION}) # so that the replacement in libde265.pc will work with both autotools and CMake 163 | configure_file(../libde265.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libde265.pc @ONLY) 164 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libde265.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 165 | -------------------------------------------------------------------------------- /libde265/libde265/COPYING: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /libde265/libde265/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = subdir-objects 2 | 3 | lib_LTLIBRARIES = libde265.la 4 | 5 | libde265_ladir = \ 6 | $(includedir)/libde265 7 | 8 | libde265_la_CPPFLAGS = 9 | libde265_la_CFLAGS = \ 10 | $(CFLAG_VISIBILITY) \ 11 | -DLIBDE265_EXPORTS 12 | libde265_la_CXXFLAGS = \ 13 | $(CFLAG_VISIBILITY) \ 14 | -DLIBDE265_EXPORTS \ 15 | -I$(top_srcdir) 16 | 17 | if HAVE_VISIBILITY 18 | libde265_la_CFLAGS += -DHAVE_VISIBILITY 19 | libde265_la_CXXFLAGS += -DHAVE_VISIBILITY 20 | endif 21 | 22 | libde265_la_LDFLAGS = -version-info $(LIBDE265_CURRENT):$(LIBDE265_REVISION):$(LIBDE265_AGE) 23 | 24 | libde265_la_SOURCES = \ 25 | acceleration.h \ 26 | alloc_pool.h \ 27 | alloc_pool.cc \ 28 | bitstream.cc \ 29 | bitstream.h \ 30 | cabac.cc \ 31 | cabac.h \ 32 | configparam.cc \ 33 | configparam.h \ 34 | contextmodel.cc \ 35 | contextmodel.h \ 36 | de265.cc \ 37 | deblock.cc \ 38 | deblock.h \ 39 | decctx.cc \ 40 | decctx.h \ 41 | fallback.cc \ 42 | fallback.h \ 43 | fallback-dct.h \ 44 | fallback-dct.cc \ 45 | fallback-motion.cc \ 46 | fallback-motion.h \ 47 | dpb.cc \ 48 | dpb.h \ 49 | image.cc \ 50 | image.h \ 51 | image-io.h \ 52 | image-io.cc \ 53 | intrapred.cc \ 54 | intrapred.h \ 55 | md5.cc \ 56 | md5.h \ 57 | motion.cc \ 58 | motion.h \ 59 | nal.cc \ 60 | nal.h \ 61 | nal-parser.cc \ 62 | nal-parser.h \ 63 | pps.cc \ 64 | pps.h \ 65 | quality.cc \ 66 | quality.h \ 67 | refpic.cc \ 68 | refpic.h \ 69 | sao.cc \ 70 | sao.h \ 71 | scan.cc \ 72 | scan.h \ 73 | sei.cc \ 74 | sei.h \ 75 | slice.cc \ 76 | slice.h \ 77 | sps.cc \ 78 | sps.h \ 79 | threads.cc \ 80 | threads.h \ 81 | transform.cc \ 82 | transform.h \ 83 | util.cc \ 84 | util.h \ 85 | visualize.cc \ 86 | visualize.h \ 87 | vps.cc \ 88 | vps.h \ 89 | vui.cc \ 90 | vui.h 91 | 92 | SUBDIRS = 93 | libde265_la_LIBADD = 94 | 95 | if ENABLE_ENCODER 96 | libde265_la_SOURCES += en265.h en265.cc 97 | SUBDIRS += encoder 98 | libde265_la_LIBADD += encoder/libde265_encoder.la 99 | endif 100 | 101 | if ENABLE_SSE_OPT 102 | SUBDIRS += x86 103 | libde265_la_LIBADD += x86/libde265_x86.la 104 | endif 105 | 106 | if ENABLE_ARM_OPT 107 | SUBDIRS += arm 108 | libde265_la_LIBADD += arm/libde265_arm.la 109 | endif 110 | 111 | if MINGW 112 | libde265_la_SOURCES += ../extra/win32cond.c ../extra/win32cond.h 113 | libde265_la_LDFLAGS += -no-undefined -static-libgcc -static-libstdc++ 114 | endif 115 | 116 | EXTRA_DIST = Makefile.vc7 \ 117 | CMakeLists.txt 118 | 119 | libde265_la_HEADERS = \ 120 | de265.h \ 121 | de265-version.h 122 | -------------------------------------------------------------------------------- /libde265/libde265/Makefile.vc7: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for Microsoft Visual Studio 2003 3 | # 4 | CFLAGS=/I..\extra /I.. /I. 5 | CC=cl /nologo 6 | LINK=link /nologo /subsystem:console 7 | DEFINES=/DWIN32 /D_WIN32_WINNT=0x0400 /DNDEBUG /DLIBDE265_EXPORTS /D_CRT_SECURE_NO_WARNINGS /DHAVE_SSE4_1 /DHAVE_STDINT_H 8 | 9 | CFLAGS=$(CFLAGS) /MT /Ox /Ob2 /Oi /TP /W4 /GL /EHsc 10 | 11 | # type conversion, possible loss of data 12 | CFLAGS=$(CFLAGS) /wd4244 13 | # unreferenced formal parameter 14 | CFLAGS=$(CFLAGS) /wd4100 15 | # local variable is initialized but not referenced 16 | CFLAGS=$(CFLAGS) /wd4189 17 | # unreferenced local function has been removed 18 | CFLAGS=$(CFLAGS) /wd4505 19 | # padded structures 20 | CFLAGS=$(CFLAGS) /wd4324 21 | # conversion signed/unsigned 22 | CFLAGS=$(CFLAGS) /wd4245 23 | # comparison signed/unsigned 24 | CFLAGS=$(CFLAGS) /wd4018 /wd4389 25 | # possible loss of data with return 26 | CFLAGS=$(CFLAGS) /wd4267 27 | # forcing value to bool (performance warning) 28 | CFLAGS=$(CFLAGS) /wd4800 29 | 30 | CFLAGS=$(CFLAGS) $(DEFINES) 31 | 32 | OBJS=\ 33 | alloc_pool.obj \ 34 | bitstream.obj \ 35 | cabac.obj \ 36 | configparam.obj \ 37 | contextmodel.obj \ 38 | de265.obj \ 39 | deblock.obj \ 40 | decctx.obj \ 41 | dpb.obj \ 42 | en265.obj \ 43 | fallback-dct.obj \ 44 | fallback-motion.obj \ 45 | fallback.obj \ 46 | image.obj \ 47 | image-io.obj \ 48 | intrapred.obj \ 49 | md5.obj \ 50 | motion.obj \ 51 | nal.obj \ 52 | nal-parser.obj \ 53 | pps.obj \ 54 | quality.obj \ 55 | refpic.obj \ 56 | sao.obj \ 57 | scan.obj \ 58 | sei.obj \ 59 | slice.obj \ 60 | sps.obj \ 61 | threads.obj \ 62 | transform.obj \ 63 | util.obj \ 64 | visualize.obj \ 65 | vps.obj \ 66 | vui.obj \ 67 | encoder\encoder-core.obj \ 68 | encoder\encoder-types.obj \ 69 | encoder\encoder-context.obj \ 70 | encoder\encoder-params.obj \ 71 | encoder\encoder-syntax.obj \ 72 | encoder\encoder-intrapred.obj \ 73 | encoder\encoder-motion.obj \ 74 | encoder\encpicbuf.obj \ 75 | encoder\sop.obj \ 76 | encoder\algo\algo.obj \ 77 | encoder\algo\cb-interpartmode.obj \ 78 | encoder\algo\cb-intra-inter.obj \ 79 | encoder\algo\cb-intrapartmode.obj \ 80 | encoder\algo\cb-mergeindex.obj \ 81 | encoder\algo\cb-skip.obj \ 82 | encoder\algo\cb-split.obj \ 83 | encoder\algo\coding-options.obj \ 84 | encoder\algo\ctb-qscale.obj \ 85 | encoder\algo\pb-mv.obj \ 86 | encoder\algo\tb-intrapredmode.obj \ 87 | encoder\algo\tb-rateestim.obj \ 88 | encoder\algo\tb-split.obj \ 89 | encoder\algo\tb-transform.obj \ 90 | x86\sse.obj \ 91 | x86\sse-dct.obj \ 92 | x86\sse-motion.obj \ 93 | ..\extra\win32cond.obj 94 | 95 | all: libde265.dll 96 | 97 | .c.obj: 98 | $(CC) /c $*.c /Fo$*.obj $(CFLAGS) 99 | 100 | .cc.obj: 101 | $(CC) /c $*.cc /Fo$*.obj $(CFLAGS) 102 | 103 | libde265.dll: $(OBJS) 104 | $(LINK) /dll /out:libde265.dll $** 105 | 106 | clean: 107 | del libde265.dll 108 | del $(OBJS) 109 | -------------------------------------------------------------------------------- /libde265/libde265/alloc_pool.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2014 struktur AG, Dirk Farin 4 | * 5 | * Authors: Dirk Farin 6 | * 7 | * This file is part of libde265. 8 | * 9 | * libde265 is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * libde265 is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with libde265. If not, see . 21 | */ 22 | 23 | #include "libde265/alloc_pool.h" 24 | #include "libde265/util.h" 25 | #include 26 | #include 27 | 28 | #define DEBUG_MEMORY 1 29 | 30 | 31 | alloc_pool::alloc_pool(size_t objSize, int poolSize, bool grow) 32 | : mObjSize(objSize), 33 | mPoolSize(poolSize), 34 | mGrow(grow) 35 | { 36 | m_freeList.reserve(poolSize); 37 | m_memBlocks.reserve(8); 38 | 39 | add_memory_block(); 40 | } 41 | 42 | 43 | void alloc_pool::add_memory_block() 44 | { 45 | uint8_t* p = new uint8_t[mObjSize * mPoolSize]; 46 | m_memBlocks.push_back(p); 47 | 48 | for (int i=0;i 4 | * 5 | * Authors: Dirk Farin 6 | * 7 | * This file is part of libde265. 8 | * 9 | * libde265 is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * libde265 is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with libde265. If not, see . 21 | */ 22 | 23 | #ifndef ALLOC_POOL_H 24 | #define ALLOC_POOL_H 25 | 26 | #ifdef HAVE_CONFIG_H 27 | #include "config.h" 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | class alloc_pool 36 | { 37 | public: 38 | alloc_pool(size_t objSize, int poolSize=1000, bool grow=true); 39 | ~alloc_pool(); 40 | 41 | void* new_obj(const size_t size); 42 | void delete_obj(void*); 43 | void purge(); 44 | 45 | private: 46 | size_t mObjSize; 47 | int mPoolSize; 48 | bool mGrow; 49 | 50 | std::vector m_memBlocks; 51 | std::vector m_freeList; 52 | 53 | void add_memory_block(); 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /libde265/libde265/arm/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libde265_arm.la 2 | 3 | libde265_arm_la_CXXFLAGS = -I.. $(CFLAG_VISIBILITY) 4 | libde265_arm_la_SOURCES = arm.cc arm.h 5 | libde265_arm_la_LIBADD = 6 | 7 | if HAVE_VISIBILITY 8 | libde265_arm_la_CXXFLAGS += -DHAVE_VISIBILITY 9 | endif 10 | 11 | 12 | if ENABLE_NEON_OPT 13 | # NEON specific functions 14 | 15 | noinst_LTLIBRARIES += libde265_arm_neon.la 16 | libde265_arm_la_LIBADD += libde265_arm_neon.la 17 | libde265_arm_neon_la_CXXFLAGS = -mfpu=neon -I.. $(CFLAG_VISIBILITY) 18 | libde265_arm_neon_la_CCASFLAGS = -mfpu=neon -I.. \ 19 | -DHAVE_NEON \ 20 | -DEXTERN_ASM= \ 21 | -DHAVE_AS_FUNC \ 22 | -DHAVE_SECTION_DATA_REL_RO 23 | 24 | if ENABLE_ARM_THUMB 25 | libde265_arm_neon_la_CCASFLAGS += -DCONFIG_THUMB 26 | endif 27 | 28 | libde265_arm_neon_la_SOURCES = \ 29 | asm.S \ 30 | cpudetect.S \ 31 | hevcdsp_qpel_neon.S \ 32 | neon.S 33 | 34 | if HAVE_VISIBILITY 35 | libde265_arm_neon_la_CXXFLAGS += -DHAVE_VISIBILITY 36 | endif 37 | 38 | endif 39 | -------------------------------------------------------------------------------- /libde265/libde265/arm/arm.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2015 struktur AG, Joachim Bauch 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "arm.h" 26 | 27 | #ifdef HAVE_NEON 28 | 29 | #define QPEL_FUNC(name) \ 30 | extern "C" void ff_##name(int16_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride, \ 31 | int height, int width); \ 32 | void libde265_##name(int16_t *dst, ptrdiff_t dststride, const uint8_t *src, ptrdiff_t srcstride, \ 33 | int width, int height, int16_t* mcbuffer) { \ 34 | ff_##name(dst, dststride, src, srcstride, height, width); \ 35 | } 36 | 37 | QPEL_FUNC(hevc_put_qpel_v1_neon_8); 38 | QPEL_FUNC(hevc_put_qpel_v2_neon_8); 39 | QPEL_FUNC(hevc_put_qpel_v3_neon_8); 40 | QPEL_FUNC(hevc_put_qpel_h1_neon_8); 41 | QPEL_FUNC(hevc_put_qpel_h2_neon_8); 42 | QPEL_FUNC(hevc_put_qpel_h3_neon_8); 43 | QPEL_FUNC(hevc_put_qpel_h1v1_neon_8); 44 | QPEL_FUNC(hevc_put_qpel_h1v2_neon_8); 45 | QPEL_FUNC(hevc_put_qpel_h1v3_neon_8); 46 | QPEL_FUNC(hevc_put_qpel_h2v1_neon_8); 47 | QPEL_FUNC(hevc_put_qpel_h2v2_neon_8); 48 | QPEL_FUNC(hevc_put_qpel_h2v3_neon_8); 49 | QPEL_FUNC(hevc_put_qpel_h3v1_neon_8); 50 | QPEL_FUNC(hevc_put_qpel_h3v2_neon_8); 51 | QPEL_FUNC(hevc_put_qpel_h3v3_neon_8); 52 | #undef QPEL_FUNC 53 | 54 | #if defined(HAVE_SIGNAL_H) && defined(HAVE_SETJMP_H) 55 | 56 | #include 57 | #include 58 | 59 | extern "C" void libde265_detect_neon(void); 60 | 61 | static jmp_buf jump_env; 62 | 63 | static void sighandler(int sig) { 64 | (void)sig; 65 | longjmp(jump_env, 1); 66 | } 67 | 68 | static bool has_NEON() { 69 | static bool checked_NEON = false; 70 | static bool have_NEON = false; 71 | 72 | if (!checked_NEON) { 73 | void (*oldsignal)(int); 74 | 75 | checked_NEON = true; 76 | oldsignal = signal(SIGILL, sighandler); 77 | if (setjmp(jump_env)) { 78 | signal(SIGILL, oldsignal); 79 | have_NEON = false; 80 | return false; 81 | } 82 | libde265_detect_neon(); 83 | signal(SIGILL, oldsignal); 84 | have_NEON = true; 85 | } 86 | 87 | return have_NEON; 88 | } 89 | 90 | #else // #if defined(HAVE_SIGNAL_H) && defined(HAVE_SETJMP_H) 91 | 92 | #warning "Don't know how to detect NEON support at runtime- will be disabled" 93 | 94 | static bool has_NEON() { 95 | return false; 96 | } 97 | 98 | #endif 99 | 100 | #endif // #ifdef HAVE_NEON 101 | 102 | void init_acceleration_functions_arm(struct acceleration_functions* accel) 103 | { 104 | #ifdef HAVE_NEON 105 | if (has_NEON()) { 106 | accel->put_hevc_qpel_8[0][1] = libde265_hevc_put_qpel_v1_neon_8; 107 | accel->put_hevc_qpel_8[0][2] = libde265_hevc_put_qpel_v2_neon_8; 108 | accel->put_hevc_qpel_8[0][3] = libde265_hevc_put_qpel_v3_neon_8; 109 | accel->put_hevc_qpel_8[1][0] = libde265_hevc_put_qpel_h1_neon_8; 110 | accel->put_hevc_qpel_8[1][1] = libde265_hevc_put_qpel_h1v1_neon_8; 111 | accel->put_hevc_qpel_8[1][2] = libde265_hevc_put_qpel_h1v2_neon_8; 112 | accel->put_hevc_qpel_8[1][3] = libde265_hevc_put_qpel_h1v3_neon_8; 113 | accel->put_hevc_qpel_8[2][0] = libde265_hevc_put_qpel_h2_neon_8; 114 | accel->put_hevc_qpel_8[2][1] = libde265_hevc_put_qpel_h2v1_neon_8; 115 | accel->put_hevc_qpel_8[2][2] = libde265_hevc_put_qpel_h2v2_neon_8; 116 | accel->put_hevc_qpel_8[2][3] = libde265_hevc_put_qpel_h2v3_neon_8; 117 | accel->put_hevc_qpel_8[3][0] = libde265_hevc_put_qpel_h3_neon_8; 118 | accel->put_hevc_qpel_8[3][1] = libde265_hevc_put_qpel_h3v1_neon_8; 119 | accel->put_hevc_qpel_8[3][2] = libde265_hevc_put_qpel_h3v2_neon_8; 120 | accel->put_hevc_qpel_8[3][3] = libde265_hevc_put_qpel_h3v3_neon_8; 121 | } 122 | #endif // #ifdef HAVE_NEON 123 | } 124 | -------------------------------------------------------------------------------- /libde265/libde265/arm/arm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2015 struktur AG, Joachim Bauch 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef LIBDE265_ARM_H 22 | #define LIBDE265_ARM_H 23 | 24 | #include "acceleration.h" 25 | 26 | void init_acceleration_functions_arm(struct acceleration_functions* accel); 27 | 28 | #endif // LIBDE265_ARM_H 29 | -------------------------------------------------------------------------------- /libde265/libde265/arm/cpudetect.S: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2015 struktur AG, Joachim Bauch 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #include "asm.S" 22 | #include "neon.S" 23 | 24 | // we execute a simple NEON instruction and check if SIGILL is triggered to 25 | // detect if the CPU support NEON code 26 | function libde265_detect_neon, export=1 27 | vand q0, q0, q0 28 | bx lr 29 | endfunc 30 | -------------------------------------------------------------------------------- /libde265/libde265/arm/neon.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008 Mans Rullgard 3 | * 4 | * This file is part of FFmpeg. 5 | * 6 | * FFmpeg is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * FFmpeg is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with FFmpeg; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | */ 20 | 21 | .macro transpose_8x8 r0, r1, r2, r3, r4, r5, r6, r7 22 | vtrn.32 \r0, \r4 23 | vtrn.32 \r1, \r5 24 | vtrn.32 \r2, \r6 25 | vtrn.32 \r3, \r7 26 | vtrn.16 \r0, \r2 27 | vtrn.16 \r1, \r3 28 | vtrn.16 \r4, \r6 29 | vtrn.16 \r5, \r7 30 | vtrn.8 \r0, \r1 31 | vtrn.8 \r2, \r3 32 | vtrn.8 \r4, \r5 33 | vtrn.8 \r6, \r7 34 | .endm 35 | 36 | .macro transpose_4x4 r0, r1, r2, r3 37 | vtrn.16 \r0, \r2 38 | vtrn.16 \r1, \r3 39 | vtrn.8 \r0, \r1 40 | vtrn.8 \r2, \r3 41 | .endm 42 | 43 | .macro swap4 r0, r1, r2, r3, r4, r5, r6, r7 44 | vswp \r0, \r4 45 | vswp \r1, \r5 46 | vswp \r2, \r6 47 | vswp \r3, \r7 48 | .endm 49 | 50 | .macro transpose16_4x4 r0, r1, r2, r3, r4, r5, r6, r7 51 | vtrn.32 \r0, \r2 52 | vtrn.32 \r1, \r3 53 | vtrn.32 \r4, \r6 54 | vtrn.32 \r5, \r7 55 | vtrn.16 \r0, \r1 56 | vtrn.16 \r2, \r3 57 | vtrn.16 \r4, \r5 58 | vtrn.16 \r6, \r7 59 | .endm 60 | -------------------------------------------------------------------------------- /libde265/libde265/arm/vendorkeep.go: -------------------------------------------------------------------------------- 1 | //go:build vendorkeep 2 | // +build vendorkeep 3 | 4 | package cgowrapper 5 | -------------------------------------------------------------------------------- /libde265/libde265/bitstream.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #include "bitstream.h" 22 | #include "de265.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | 30 | void bitreader_init(bitreader* br, unsigned char* buffer, int len) 31 | { 32 | br->data = buffer; 33 | br->bytes_remaining = len; 34 | 35 | br->nextbits=0; 36 | br->nextbits_cnt=0; 37 | 38 | bitreader_refill(br); 39 | } 40 | 41 | void bitreader_refill(bitreader* br) 42 | { 43 | int shift = 64-br->nextbits_cnt; 44 | 45 | while (shift >= 8 && br->bytes_remaining) { 46 | uint64_t newval = *br->data++; 47 | br->bytes_remaining--; 48 | 49 | shift -= 8; 50 | newval <<= shift; 51 | br->nextbits |= newval; 52 | } 53 | 54 | br->nextbits_cnt = 64-shift; 55 | } 56 | 57 | int get_bits(bitreader* br, int n) 58 | { 59 | if (br->nextbits_cnt < n) { 60 | bitreader_refill(br); 61 | } 62 | 63 | uint64_t val = br->nextbits; 64 | val >>= 64-n; 65 | 66 | br->nextbits <<= n; 67 | br->nextbits_cnt -= n; 68 | 69 | return val; 70 | } 71 | 72 | int get_bits_fast(bitreader* br, int n) 73 | { 74 | assert(br->nextbits_cnt >= n); 75 | 76 | uint64_t val = br->nextbits; 77 | val >>= 64-n; 78 | 79 | br->nextbits <<= n; 80 | br->nextbits_cnt -= n; 81 | 82 | return val; 83 | } 84 | 85 | int peek_bits(bitreader* br, int n) 86 | { 87 | if (br->nextbits_cnt < n) { 88 | bitreader_refill(br); 89 | } 90 | 91 | uint64_t val = br->nextbits; 92 | val >>= 64-n; 93 | 94 | return val; 95 | } 96 | 97 | void skip_bits(bitreader* br, int n) 98 | { 99 | if (br->nextbits_cnt < n) { 100 | bitreader_refill(br); 101 | } 102 | 103 | br->nextbits <<= n; 104 | br->nextbits_cnt -= n; 105 | } 106 | 107 | void skip_bits_fast(bitreader* br, int n) 108 | { 109 | br->nextbits <<= n; 110 | br->nextbits_cnt -= n; 111 | } 112 | 113 | void skip_to_byte_boundary(bitreader* br) 114 | { 115 | int nskip = (br->nextbits_cnt & 7); 116 | 117 | br->nextbits <<= nskip; 118 | br->nextbits_cnt -= nskip; 119 | } 120 | 121 | void prepare_for_CABAC(bitreader* br) 122 | { 123 | skip_to_byte_boundary(br); 124 | 125 | int rewind = br->nextbits_cnt/8; 126 | br->data -= rewind; 127 | br->bytes_remaining += rewind; 128 | br->nextbits = 0; 129 | br->nextbits_cnt = 0; 130 | } 131 | 132 | int get_uvlc(bitreader* br) 133 | { 134 | int num_zeros=0; 135 | 136 | while (get_bits(br,1)==0) { 137 | num_zeros++; 138 | 139 | if (num_zeros > MAX_UVLC_LEADING_ZEROS) { return UVLC_ERROR; } 140 | } 141 | 142 | int offset = 0; 143 | if (num_zeros != 0) { 144 | offset = get_bits(br, num_zeros); 145 | int value = offset + (1<0); 147 | return value; 148 | } else { 149 | return 0; 150 | } 151 | } 152 | 153 | int get_svlc(bitreader* br) 154 | { 155 | int v = get_uvlc(br); 156 | if (v==0) return v; 157 | if (v==UVLC_ERROR) return UVLC_ERROR; 158 | 159 | bool negative = ((v&1)==0); 160 | return negative ? -v/2 : (v+1)/2; 161 | } 162 | 163 | bool check_rbsp_trailing_bits(bitreader* br) 164 | { 165 | int stop_bit = get_bits(br,1); 166 | assert(stop_bit==1); 167 | 168 | while (br->nextbits_cnt>0 || br->bytes_remaining>0) { 169 | int filler = get_bits(br,1); 170 | if (filler!=0) { 171 | return false; 172 | } 173 | } 174 | 175 | return true; 176 | } 177 | -------------------------------------------------------------------------------- /libde265/libde265/bitstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_BITSTREAM_H 22 | #define DE265_BITSTREAM_H 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | 31 | 32 | #define MAX_UVLC_LEADING_ZEROS 20 33 | #define UVLC_ERROR -99999 34 | 35 | 36 | typedef struct { 37 | uint8_t* data; 38 | int bytes_remaining; 39 | 40 | uint64_t nextbits; // left-aligned bits 41 | int nextbits_cnt; 42 | } bitreader; 43 | 44 | void bitreader_init(bitreader*, unsigned char* buffer, int len); 45 | void bitreader_refill(bitreader*); // refill to at least 56+1 bits 46 | int next_bit(bitreader*); 47 | int next_bit_norefill(bitreader*); 48 | int get_bits(bitreader*, int n); 49 | int get_bits_fast(bitreader*, int n); 50 | int peek_bits(bitreader*, int n); 51 | void skip_bits(bitreader*, int n); 52 | void skip_bits_fast(bitreader*, int n); 53 | void skip_to_byte_boundary(bitreader*); 54 | void prepare_for_CABAC(bitreader*); 55 | int get_uvlc(bitreader*); // may return UVLC_ERROR 56 | int get_svlc(bitreader*); // may return UVLC_ERROR 57 | 58 | bool check_rbsp_trailing_bits(bitreader*); // return true if remaining filler bits are all zero 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /libde265/libde265/cabac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_CABAC_H 22 | #define DE265_CABAC_H 23 | 24 | #include 25 | #include "contextmodel.h" 26 | 27 | 28 | typedef struct { 29 | uint8_t* bitstream_start; 30 | uint8_t* bitstream_curr; 31 | uint8_t* bitstream_end; 32 | 33 | uint32_t range; 34 | uint32_t value; 35 | int16_t bits_needed; 36 | } CABAC_decoder; 37 | 38 | 39 | void init_CABAC_decoder(CABAC_decoder* decoder, uint8_t* bitstream, int length); 40 | void init_CABAC_decoder_2(CABAC_decoder* decoder); 41 | int decode_CABAC_bit(CABAC_decoder* decoder, context_model* model); 42 | int decode_CABAC_TU(CABAC_decoder* decoder, int cMax, context_model* model); 43 | int decode_CABAC_term_bit(CABAC_decoder* decoder); 44 | 45 | int decode_CABAC_bypass(CABAC_decoder* decoder); 46 | int decode_CABAC_TU_bypass(CABAC_decoder* decoder, int cMax); 47 | uint32_t decode_CABAC_FL_bypass(CABAC_decoder* decoder, int nBits); 48 | int decode_CABAC_TR_bypass(CABAC_decoder* decoder, int cRiceParam, int cTRMax); 49 | int decode_CABAC_EGk_bypass(CABAC_decoder* decoder, int k); 50 | 51 | 52 | // --------------------------------------------------------------------------- 53 | 54 | class CABAC_encoder 55 | { 56 | public: 57 | CABAC_encoder() : mCtxModels(NULL) { } 58 | virtual ~CABAC_encoder() { } 59 | 60 | virtual int size() const = 0; 61 | virtual void reset() = 0; 62 | 63 | // --- VLC --- 64 | 65 | virtual void write_bits(uint32_t bits,int n) = 0; 66 | virtual void write_bit(int bit) { write_bits(bit,1); } 67 | virtual void write_uvlc(int value); 68 | virtual void write_svlc(int value); 69 | virtual bool write_startcode() = 0; 70 | virtual void skip_bits(int nBits) = 0; 71 | 72 | virtual void add_trailing_bits(); 73 | virtual int number_free_bits_in_byte() const = 0; 74 | 75 | // output all remaining bits and fill with zeros to next byte boundary 76 | virtual void flush_VLC() { } 77 | 78 | 79 | // --- CABAC --- 80 | 81 | void set_context_models(context_model_table* models) { mCtxModels=models; } 82 | 83 | virtual void init_CABAC() { } 84 | virtual void write_CABAC_bit(int modelIdx, int bit) = 0; 85 | virtual void write_CABAC_bypass(int bit) = 0; 86 | virtual void write_CABAC_TU_bypass(int value, int cMax); 87 | virtual void write_CABAC_FL_bypass(int value, int nBits); 88 | virtual void write_CABAC_term_bit(int bit) = 0; 89 | virtual void flush_CABAC() { } 90 | 91 | void write_CABAC_EGk(int absolute_symbol, int k); // absolute_symbol >= 0 92 | 93 | virtual bool modifies_context() const = 0; 94 | 95 | float RDBits_for_CABAC_bin(int modelIdx, int bit); 96 | 97 | protected: 98 | context_model_table* mCtxModels; 99 | }; 100 | 101 | 102 | class CABAC_encoder_bitstream : public CABAC_encoder 103 | { 104 | public: 105 | CABAC_encoder_bitstream(); 106 | ~CABAC_encoder_bitstream(); 107 | 108 | virtual void reset(); 109 | 110 | virtual int size() const { return data_size; } 111 | uint8_t* data() const { return data_mem; } 112 | 113 | // --- VLC --- 114 | 115 | virtual void write_bits(uint32_t bits,int n); 116 | virtual bool write_startcode(); 117 | virtual void skip_bits(int nBits); 118 | 119 | virtual int number_free_bits_in_byte() const; 120 | 121 | // output all remaining bits and fill with zeros to next byte boundary 122 | virtual void flush_VLC(); 123 | 124 | 125 | // --- CABAC --- 126 | 127 | virtual void init_CABAC(); 128 | virtual void write_CABAC_bit(int modelIdx, int bit); 129 | virtual void write_CABAC_bypass(int bit); 130 | virtual void write_CABAC_term_bit(int bit); 131 | virtual void flush_CABAC(); 132 | 133 | virtual bool modifies_context() const { return true; } 134 | 135 | private: 136 | // data buffer 137 | 138 | uint8_t* data_mem; 139 | uint32_t data_capacity; 140 | uint32_t data_size; 141 | char state; // for inserting emulation-prevention bytes 142 | 143 | // VLC 144 | 145 | uint32_t vlc_buffer; 146 | uint32_t vlc_buffer_len; 147 | 148 | 149 | // CABAC 150 | 151 | uint32_t range; 152 | uint32_t low; 153 | int8_t bits_left; 154 | uint8_t buffered_byte; 155 | uint16_t num_buffered_bytes; 156 | 157 | 158 | bool check_size_and_resize(int nBytes); 159 | void testAndWriteOut(); 160 | void write_out(); 161 | bool append_byte(int byte); 162 | }; 163 | 164 | 165 | class CABAC_encoder_estim : public CABAC_encoder 166 | { 167 | public: 168 | CABAC_encoder_estim() : mFracBits(0) { } 169 | 170 | virtual void reset() { mFracBits=0; } 171 | 172 | virtual int size() const { return mFracBits>>(15+3); } 173 | 174 | uint64_t getFracBits() const { return mFracBits; } 175 | float getRDBits() const { return mFracBits / float(1<<15); } 176 | 177 | // --- VLC --- 178 | 179 | virtual void write_bits(uint32_t bits,int n) { mFracBits += n<<15; } 180 | virtual void write_bit(int bit) { mFracBits+=1<<15; } 181 | virtual bool write_startcode() { mFracBits += (1<<15)*8*3; return true; } 182 | virtual void skip_bits(int nBits) { mFracBits += nBits<<15; } 183 | virtual int number_free_bits_in_byte() const { return 0; } // TODO, good enough for now 184 | 185 | // --- CABAC --- 186 | 187 | virtual void write_CABAC_bit(int modelIdx, int bit); 188 | virtual void write_CABAC_bypass(int bit) { 189 | mFracBits += 0x8000; 190 | } 191 | virtual void write_CABAC_FL_bypass(int value, int nBits) { 192 | mFracBits += nBits<<15; 193 | } 194 | virtual void write_CABAC_term_bit(int bit) { /* not implemented (not needed) */ } 195 | 196 | virtual bool modifies_context() const { return true; } 197 | 198 | protected: 199 | uint64_t mFracBits; 200 | }; 201 | 202 | 203 | class CABAC_encoder_estim_constant : public CABAC_encoder_estim 204 | { 205 | public: 206 | void write_CABAC_bit(int modelIdx, int bit); 207 | 208 | virtual bool modifies_context() const { return false; } 209 | }; 210 | 211 | #endif 212 | -------------------------------------------------------------------------------- /libde265/libde265/contextmodel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * Authors: struktur AG, Dirk Farin 6 | * Min Chen 7 | * 8 | * This file is part of libde265. 9 | * 10 | * libde265 is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as 12 | * published by the Free Software Foundation, either version 3 of 13 | * the License, or (at your option) any later version. 14 | * 15 | * libde265 is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with libde265. If not, see . 22 | */ 23 | 24 | #ifndef DE265_CONTEXTMODEL_H 25 | #define DE265_CONTEXTMODEL_H 26 | 27 | #include "libde265/cabac.h" 28 | #include "libde265/de265.h" 29 | 30 | #include 31 | #include 32 | 33 | 34 | struct context_model { 35 | uint8_t MPSbit : 1; 36 | uint8_t state : 7; 37 | 38 | bool operator==(context_model b) const { return state==b.state && MPSbit==b.MPSbit; } 39 | bool operator!=(context_model b) const { return state!=b.state || MPSbit!=b.MPSbit; } 40 | }; 41 | 42 | 43 | enum context_model_index { 44 | // SAO 45 | CONTEXT_MODEL_SAO_MERGE_FLAG = 0, 46 | CONTEXT_MODEL_SAO_TYPE_IDX = CONTEXT_MODEL_SAO_MERGE_FLAG +1, 47 | 48 | // CB-tree 49 | CONTEXT_MODEL_SPLIT_CU_FLAG = CONTEXT_MODEL_SAO_TYPE_IDX + 1, 50 | CONTEXT_MODEL_CU_SKIP_FLAG = CONTEXT_MODEL_SPLIT_CU_FLAG + 3, 51 | 52 | // intra-prediction 53 | CONTEXT_MODEL_PART_MODE = CONTEXT_MODEL_CU_SKIP_FLAG + 3, 54 | CONTEXT_MODEL_PREV_INTRA_LUMA_PRED_FLAG = CONTEXT_MODEL_PART_MODE + 4, 55 | CONTEXT_MODEL_INTRA_CHROMA_PRED_MODE = CONTEXT_MODEL_PREV_INTRA_LUMA_PRED_FLAG + 1, 56 | 57 | // transform-tree 58 | CONTEXT_MODEL_CBF_LUMA = CONTEXT_MODEL_INTRA_CHROMA_PRED_MODE + 1, 59 | CONTEXT_MODEL_CBF_CHROMA = CONTEXT_MODEL_CBF_LUMA + 2, 60 | CONTEXT_MODEL_SPLIT_TRANSFORM_FLAG = CONTEXT_MODEL_CBF_CHROMA + 4, 61 | CONTEXT_MODEL_CU_CHROMA_QP_OFFSET_FLAG = CONTEXT_MODEL_SPLIT_TRANSFORM_FLAG + 3, 62 | CONTEXT_MODEL_CU_CHROMA_QP_OFFSET_IDX = CONTEXT_MODEL_CU_CHROMA_QP_OFFSET_FLAG + 1, 63 | 64 | // residual 65 | CONTEXT_MODEL_LAST_SIGNIFICANT_COEFFICIENT_X_PREFIX = CONTEXT_MODEL_CU_CHROMA_QP_OFFSET_IDX + 1, 66 | CONTEXT_MODEL_LAST_SIGNIFICANT_COEFFICIENT_Y_PREFIX = CONTEXT_MODEL_LAST_SIGNIFICANT_COEFFICIENT_X_PREFIX + 18, 67 | CONTEXT_MODEL_CODED_SUB_BLOCK_FLAG = CONTEXT_MODEL_LAST_SIGNIFICANT_COEFFICIENT_Y_PREFIX + 18, 68 | CONTEXT_MODEL_SIGNIFICANT_COEFF_FLAG = CONTEXT_MODEL_CODED_SUB_BLOCK_FLAG + 4, 69 | CONTEXT_MODEL_COEFF_ABS_LEVEL_GREATER1_FLAG = CONTEXT_MODEL_SIGNIFICANT_COEFF_FLAG + 42+2, 70 | CONTEXT_MODEL_COEFF_ABS_LEVEL_GREATER2_FLAG = CONTEXT_MODEL_COEFF_ABS_LEVEL_GREATER1_FLAG + 24, 71 | 72 | CONTEXT_MODEL_CU_QP_DELTA_ABS = CONTEXT_MODEL_COEFF_ABS_LEVEL_GREATER2_FLAG + 6, 73 | CONTEXT_MODEL_TRANSFORM_SKIP_FLAG = CONTEXT_MODEL_CU_QP_DELTA_ABS + 2, 74 | CONTEXT_MODEL_RDPCM_FLAG = CONTEXT_MODEL_TRANSFORM_SKIP_FLAG + 2, 75 | CONTEXT_MODEL_RDPCM_DIR = CONTEXT_MODEL_RDPCM_FLAG + 2, 76 | 77 | // motion 78 | CONTEXT_MODEL_MERGE_FLAG = CONTEXT_MODEL_RDPCM_DIR + 2, 79 | CONTEXT_MODEL_MERGE_IDX = CONTEXT_MODEL_MERGE_FLAG + 1, 80 | CONTEXT_MODEL_PRED_MODE_FLAG = CONTEXT_MODEL_MERGE_IDX + 1, 81 | CONTEXT_MODEL_ABS_MVD_GREATER01_FLAG = CONTEXT_MODEL_PRED_MODE_FLAG + 1, 82 | CONTEXT_MODEL_MVP_LX_FLAG = CONTEXT_MODEL_ABS_MVD_GREATER01_FLAG + 2, 83 | CONTEXT_MODEL_RQT_ROOT_CBF = CONTEXT_MODEL_MVP_LX_FLAG + 1, 84 | CONTEXT_MODEL_REF_IDX_LX = CONTEXT_MODEL_RQT_ROOT_CBF + 1, 85 | CONTEXT_MODEL_INTER_PRED_IDC = CONTEXT_MODEL_REF_IDX_LX + 2, 86 | CONTEXT_MODEL_CU_TRANSQUANT_BYPASS_FLAG = CONTEXT_MODEL_INTER_PRED_IDC + 5, 87 | CONTEXT_MODEL_LOG2_RES_SCALE_ABS_PLUS1 = CONTEXT_MODEL_CU_TRANSQUANT_BYPASS_FLAG + 1, 88 | CONTEXT_MODEL_RES_SCALE_SIGN_FLAG = CONTEXT_MODEL_LOG2_RES_SCALE_ABS_PLUS1 + 8, 89 | CONTEXT_MODEL_TABLE_LENGTH = CONTEXT_MODEL_RES_SCALE_SIGN_FLAG + 2 90 | }; 91 | 92 | 93 | 94 | void initialize_CABAC_models(context_model context_model_table[CONTEXT_MODEL_TABLE_LENGTH], 95 | int initType, 96 | int QPY); 97 | 98 | 99 | class context_model_table 100 | { 101 | public: 102 | context_model_table(); 103 | context_model_table(const context_model_table&); 104 | ~context_model_table(); 105 | 106 | void init(int initType, int QPY); 107 | void release(); 108 | void decouple(); 109 | context_model_table transfer(); 110 | context_model_table copy() const { context_model_table t=*this; t.decouple(); return t; } 111 | 112 | bool empty() const { return refcnt != NULL; } 113 | 114 | context_model& operator[](int i) { return model[i]; } 115 | 116 | context_model_table& operator=(const context_model_table&); 117 | 118 | bool operator==(const context_model_table&) const; 119 | 120 | std::string debug_dump() const; 121 | 122 | private: 123 | void decouple_or_alloc_with_empty_data(); 124 | 125 | context_model* model; // [CONTEXT_MODEL_TABLE_LENGTH] 126 | int* refcnt; 127 | }; 128 | 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /libde265/libde265/de265-version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | /* de265-version.h 22 | * 23 | * This file was generated by autoconf when libde265 was built. 24 | * 25 | * DO NOT EDIT THIS FILE. 26 | */ 27 | #ifndef LIBDE265_VERSION_H 28 | #define LIBDE265_VERSION_H 29 | 30 | /* Numeric representation of the version */ 31 | #define LIBDE265_NUMERIC_VERSION 0x01001500 32 | 33 | /* Version string */ 34 | #define LIBDE265_VERSION "1.0.15" 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /libde265/libde265/de265-version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | /* de265-version.h 22 | * 23 | * This file was generated by autoconf when libde265 was built. 24 | * 25 | * DO NOT EDIT THIS FILE. 26 | */ 27 | #ifndef LIBDE265_VERSION_H 28 | #define LIBDE265_VERSION_H 29 | 30 | /* Numeric representation of the version */ 31 | #define LIBDE265_NUMERIC_VERSION @NUMERIC_VERSION@ 32 | 33 | /* Version string */ 34 | #define LIBDE265_VERSION "@PACKAGE_VERSION@" 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /libde265/libde265/deblock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_DEBLOCK_H 22 | #define DE265_DEBLOCK_H 23 | 24 | #include "libde265/decctx.h" 25 | 26 | void add_deblocking_tasks(image_unit* imgunit); 27 | void apply_deblocking_filter(de265_image* img); //decoder_context* ctx); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /libde265/libde265/dpb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_DPB_H 22 | #define DE265_DPB_H 23 | 24 | #include "libde265/image.h" 25 | #include "libde265/sps.h" 26 | 27 | #include 28 | #include 29 | 30 | class decoder_context; 31 | 32 | class decoded_picture_buffer { 33 | public: 34 | decoded_picture_buffer(); 35 | ~decoded_picture_buffer(); 36 | 37 | void set_max_size_of_DPB(int n) { max_images_in_DPB=n; } 38 | void set_norm_size_of_DPB(int n) { norm_images_in_DPB=n; } 39 | 40 | /* Alloc a new image in the DPB and return its index. 41 | If there is no space for a new image, returns the negative value of an de265_error. 42 | I.e. you can check for error by return_value<0, which is error (-return_value); 43 | */ 44 | int new_image(std::shared_ptr sps, decoder_context* decctx, 45 | de265_PTS pts, void* user_data, bool isOutputImage); 46 | 47 | /* Check for a free slot in the DPB. There are some slots reserved for 48 | unavailable reference frames. If high_priority==true, these reserved slots 49 | are included in the check. */ 50 | bool has_free_dpb_picture(bool high_priority) const; 51 | 52 | /* Remove all pictures from DPB and queues. Decoding should be stopped while calling this. */ 53 | void clear(); 54 | 55 | int size() const { return dpb.size(); } 56 | 57 | /* Raw access to the images. */ 58 | 59 | /* */ de265_image* get_image(int index) { 60 | if (index>=dpb.size()) return NULL; 61 | return dpb[index]; 62 | } 63 | 64 | const de265_image* get_image(int index) const { 65 | if (index>=dpb.size()) return NULL; 66 | return dpb[index]; 67 | } 68 | 69 | /* Search DPB for the slot index of a specific picture. */ 70 | int DPB_index_of_picture_with_POC(int poc, int currentID, bool preferLongTerm=false) const; 71 | int DPB_index_of_picture_with_LSB(int lsb, int currentID, bool preferLongTerm=false) const; 72 | int DPB_index_of_picture_with_ID (int id) const; 73 | 74 | 75 | // --- reorder buffer --- 76 | 77 | void insert_image_into_reorder_buffer(struct de265_image* img) { 78 | reorder_output_queue.push_back(img); 79 | } 80 | 81 | int num_pictures_in_reorder_buffer() const { return reorder_output_queue.size(); } 82 | 83 | // move next picture in reorder buffer to output queue 84 | void output_next_picture_in_reorder_buffer(); 85 | 86 | // Move all pictures in reorder buffer to output buffer. Return true if there were any pictures. 87 | bool flush_reorder_buffer(); 88 | 89 | 90 | // --- output buffer --- 91 | 92 | int num_pictures_in_output_queue() const { return image_output_queue.size(); } 93 | 94 | /* Get the next picture in the output queue, but do not remove it from the queue. */ 95 | struct de265_image* get_next_picture_in_output_queue() const { return image_output_queue.front(); } 96 | 97 | /* Remove the next picture in the output queue. */ 98 | void pop_next_picture_in_output_queue(); 99 | 100 | 101 | // --- debug --- 102 | 103 | void log_dpb_content() const; 104 | void log_dpb_queues() const; 105 | 106 | private: 107 | int max_images_in_DPB; 108 | int norm_images_in_DPB; 109 | 110 | std::vector dpb; // decoded picture buffer 111 | 112 | std::vector reorder_output_queue; 113 | std::deque image_output_queue; 114 | 115 | private: 116 | decoded_picture_buffer(const decoded_picture_buffer&); // no copy 117 | decoded_picture_buffer& operator=(const decoded_picture_buffer&); // no copy 118 | }; 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /libde265/libde265/fallback-dct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef FALLBACK_DCT_H 22 | #define FALLBACK_DCT_H 23 | 24 | #include 25 | #include 26 | 27 | #include "util.h" 28 | 29 | 30 | // --- decoding --- 31 | 32 | void transform_skip_8_fallback(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 33 | void transform_bypass_fallback(int32_t *r, const int16_t *coeffs, int nT); 34 | 35 | void transform_skip_rdpcm_v_8_fallback(uint8_t *dst, const int16_t *coeffs, int nT, ptrdiff_t stride); 36 | void transform_skip_rdpcm_h_8_fallback(uint8_t *dst, const int16_t *coeffs, int nT, ptrdiff_t stride); 37 | void transform_bypass_rdpcm_v_fallback(int32_t *r, const int16_t *coeffs,int nT); 38 | void transform_bypass_rdpcm_h_fallback(int32_t *r, const int16_t *coeffs,int nT); 39 | 40 | void transform_4x4_luma_add_8_fallback(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 41 | void transform_4x4_add_8_fallback(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 42 | void transform_8x8_add_8_fallback(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 43 | void transform_16x16_add_8_fallback(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 44 | void transform_32x32_add_8_fallback(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 45 | 46 | 47 | void transform_skip_16_fallback(uint16_t *dst, const int16_t *coeffs, ptrdiff_t stride, int bit_depth); 48 | void transform_bypass_16_fallback(uint16_t *dst, const int16_t *coeffs, int nT, ptrdiff_t stride, int bit_depth); 49 | 50 | void transform_4x4_luma_add_16_fallback(uint16_t *dst, const int16_t *coeffs, ptrdiff_t stride, int bit_depth); 51 | void transform_4x4_add_16_fallback(uint16_t *dst, const int16_t *coeffs, ptrdiff_t stride, int bit_depth); 52 | void transform_8x8_add_16_fallback(uint16_t *dst, const int16_t *coeffs, ptrdiff_t stride, int bit_depth); 53 | void transform_16x16_add_16_fallback(uint16_t *dst, const int16_t *coeffs, ptrdiff_t stride, int bit_depth); 54 | void transform_32x32_add_16_fallback(uint16_t *dst, const int16_t *coeffs, ptrdiff_t stride, int bit_depth); 55 | 56 | void rotate_coefficients_fallback(int16_t *coeff, int nT); 57 | 58 | 59 | void transform_idst_4x4_fallback(int32_t *dst, const int16_t *coeffs, int bdShift, int max_coeff_bits); 60 | void transform_idct_4x4_fallback(int32_t *dst, const int16_t *coeffs, int bdShift, int max_coeff_bits); 61 | void transform_idct_8x8_fallback(int32_t *dst, const int16_t *coeffs, int bdShift, int max_coeff_bits); 62 | void transform_idct_16x16_fallback(int32_t *dst, const int16_t *coeffs, int bdShift, int max_coeff_bits); 63 | void transform_idct_32x32_fallback(int32_t *dst, const int16_t *coeffs, int bdShift, int max_coeff_bits); 64 | 65 | template 66 | void add_residual_fallback(pixel_t *dst, ptrdiff_t stride, 67 | const int32_t* r, int nT, int bit_depth) 68 | { 69 | for (int y=0;y 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef FALLBACK_MOTION_H 22 | #define FALLBACK_MOTION_H 23 | 24 | #include 25 | #include 26 | 27 | 28 | void put_weighted_pred_avg_8_fallback(uint8_t *dst, ptrdiff_t dststride, 29 | const int16_t *src1, const int16_t *src2, 30 | ptrdiff_t srcstride, int width, 31 | int height); 32 | 33 | void put_unweighted_pred_8_fallback(uint8_t *_dst, ptrdiff_t dststride, 34 | const int16_t *src, ptrdiff_t srcstride, 35 | int width, int height); 36 | 37 | void put_weighted_pred_8_fallback(uint8_t *_dst, ptrdiff_t dststride, 38 | const int16_t *src, ptrdiff_t srcstride, 39 | int width, int height, 40 | int w,int o,int log2WD); 41 | void put_weighted_bipred_8_fallback(uint8_t *_dst, ptrdiff_t dststride, 42 | const int16_t *src1, const int16_t *src2, ptrdiff_t srcstride, 43 | int width, int height, 44 | int w1,int o1, int w2,int o2, int log2WD); 45 | 46 | void put_weighted_pred_avg_16_fallback(uint16_t *dst, ptrdiff_t dststride, 47 | const int16_t *src1, const int16_t *src2, 48 | ptrdiff_t srcstride, int width, 49 | int height, int bit_depth); 50 | 51 | void put_unweighted_pred_16_fallback(uint16_t *_dst, ptrdiff_t dststride, 52 | const int16_t *src, ptrdiff_t srcstride, 53 | int width, int height, int bit_depth); 54 | 55 | void put_weighted_pred_16_fallback(uint16_t *_dst, ptrdiff_t dststride, 56 | const int16_t *src, ptrdiff_t srcstride, 57 | int width, int height, 58 | int w,int o,int log2WD, int bit_depth); 59 | void put_weighted_bipred_16_fallback(uint16_t *_dst, ptrdiff_t dststride, 60 | const int16_t *src1, const int16_t *src2, ptrdiff_t srcstride, 61 | int width, int height, 62 | int w1,int o1, int w2,int o2, int log2WD, int bit_depth); 63 | 64 | 65 | 66 | void put_epel_8_fallback(int16_t *dst, ptrdiff_t dststride, 67 | const uint8_t *_src, ptrdiff_t srcstride, 68 | int width, int height, 69 | int mx, int my, int16_t* mcbuffer); 70 | 71 | void put_epel_16_fallback(int16_t *out, ptrdiff_t out_stride, 72 | const uint16_t *src, ptrdiff_t src_stride, 73 | int width, int height, 74 | int mx, int my, int16_t* mcbuffer, int bit_depth); 75 | 76 | template 77 | void put_epel_hv_fallback(int16_t *dst, ptrdiff_t dststride, 78 | const pixel_t *_src, ptrdiff_t srcstride, 79 | int width, int height, 80 | int mx, int my, int16_t* mcbuffer, int bit_depth); 81 | 82 | 83 | #define QPEL(x,y) void put_qpel_ ## x ## _ ## y ## _fallback(int16_t *out, ptrdiff_t out_stride, \ 84 | const uint8_t *src, ptrdiff_t srcstride, \ 85 | int nPbW, int nPbH, int16_t* mcbuffer) 86 | QPEL(0,0); QPEL(0,1); QPEL(0,2); QPEL(0,3); 87 | QPEL(1,0); QPEL(1,1); QPEL(1,2); QPEL(1,3); 88 | QPEL(2,0); QPEL(2,1); QPEL(2,2); QPEL(2,3); 89 | QPEL(3,0); QPEL(3,1); QPEL(3,2); QPEL(3,3); 90 | 91 | #undef QPEL 92 | 93 | 94 | #define QPEL(x,y) void put_qpel_ ## x ## _ ## y ## _fallback_16(int16_t *out, ptrdiff_t out_stride, \ 95 | const uint16_t *src, ptrdiff_t srcstride, \ 96 | int nPbW, int nPbH, int16_t* mcbuffer, int bit_depth) 97 | QPEL(0,0); QPEL(0,1); QPEL(0,2); QPEL(0,3); 98 | QPEL(1,0); QPEL(1,1); QPEL(1,2); QPEL(1,3); 99 | QPEL(2,0); QPEL(2,1); QPEL(2,2); QPEL(2,3); 100 | QPEL(3,0); QPEL(3,1); QPEL(3,2); QPEL(3,3); 101 | 102 | #undef QPEL 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /libde265/libde265/fallback.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #include "fallback.h" 22 | #include "fallback-motion.h" 23 | #include "fallback-dct.h" 24 | 25 | 26 | void init_acceleration_functions_fallback(struct acceleration_functions* accel) 27 | { 28 | accel->put_weighted_pred_avg_8 = put_weighted_pred_avg_8_fallback; 29 | accel->put_unweighted_pred_8 = put_unweighted_pred_8_fallback; 30 | accel->put_weighted_pred_8 = put_weighted_pred_8_fallback; 31 | accel->put_weighted_bipred_8 = put_weighted_bipred_8_fallback; 32 | 33 | accel->put_weighted_pred_avg_16 = put_weighted_pred_avg_16_fallback; 34 | accel->put_unweighted_pred_16 = put_unweighted_pred_16_fallback; 35 | accel->put_weighted_pred_16 = put_weighted_pred_16_fallback; 36 | accel->put_weighted_bipred_16 = put_weighted_bipred_16_fallback; 37 | 38 | 39 | accel->put_hevc_epel_8 = put_epel_8_fallback; 40 | accel->put_hevc_epel_h_8 = put_epel_hv_fallback; 41 | accel->put_hevc_epel_v_8 = put_epel_hv_fallback; 42 | accel->put_hevc_epel_hv_8 = put_epel_hv_fallback; 43 | 44 | accel->put_hevc_qpel_8[0][0] = put_qpel_0_0_fallback; 45 | accel->put_hevc_qpel_8[0][1] = put_qpel_0_1_fallback; 46 | accel->put_hevc_qpel_8[0][2] = put_qpel_0_2_fallback; 47 | accel->put_hevc_qpel_8[0][3] = put_qpel_0_3_fallback; 48 | accel->put_hevc_qpel_8[1][0] = put_qpel_1_0_fallback; 49 | accel->put_hevc_qpel_8[1][1] = put_qpel_1_1_fallback; 50 | accel->put_hevc_qpel_8[1][2] = put_qpel_1_2_fallback; 51 | accel->put_hevc_qpel_8[1][3] = put_qpel_1_3_fallback; 52 | accel->put_hevc_qpel_8[2][0] = put_qpel_2_0_fallback; 53 | accel->put_hevc_qpel_8[2][1] = put_qpel_2_1_fallback; 54 | accel->put_hevc_qpel_8[2][2] = put_qpel_2_2_fallback; 55 | accel->put_hevc_qpel_8[2][3] = put_qpel_2_3_fallback; 56 | accel->put_hevc_qpel_8[3][0] = put_qpel_3_0_fallback; 57 | accel->put_hevc_qpel_8[3][1] = put_qpel_3_1_fallback; 58 | accel->put_hevc_qpel_8[3][2] = put_qpel_3_2_fallback; 59 | accel->put_hevc_qpel_8[3][3] = put_qpel_3_3_fallback; 60 | 61 | accel->put_hevc_epel_16 = put_epel_16_fallback; 62 | accel->put_hevc_epel_h_16 = put_epel_hv_fallback; 63 | accel->put_hevc_epel_v_16 = put_epel_hv_fallback; 64 | accel->put_hevc_epel_hv_16 = put_epel_hv_fallback; 65 | 66 | accel->put_hevc_qpel_16[0][0] = put_qpel_0_0_fallback_16; 67 | accel->put_hevc_qpel_16[0][1] = put_qpel_0_1_fallback_16; 68 | accel->put_hevc_qpel_16[0][2] = put_qpel_0_2_fallback_16; 69 | accel->put_hevc_qpel_16[0][3] = put_qpel_0_3_fallback_16; 70 | accel->put_hevc_qpel_16[1][0] = put_qpel_1_0_fallback_16; 71 | accel->put_hevc_qpel_16[1][1] = put_qpel_1_1_fallback_16; 72 | accel->put_hevc_qpel_16[1][2] = put_qpel_1_2_fallback_16; 73 | accel->put_hevc_qpel_16[1][3] = put_qpel_1_3_fallback_16; 74 | accel->put_hevc_qpel_16[2][0] = put_qpel_2_0_fallback_16; 75 | accel->put_hevc_qpel_16[2][1] = put_qpel_2_1_fallback_16; 76 | accel->put_hevc_qpel_16[2][2] = put_qpel_2_2_fallback_16; 77 | accel->put_hevc_qpel_16[2][3] = put_qpel_2_3_fallback_16; 78 | accel->put_hevc_qpel_16[3][0] = put_qpel_3_0_fallback_16; 79 | accel->put_hevc_qpel_16[3][1] = put_qpel_3_1_fallback_16; 80 | accel->put_hevc_qpel_16[3][2] = put_qpel_3_2_fallback_16; 81 | accel->put_hevc_qpel_16[3][3] = put_qpel_3_3_fallback_16; 82 | 83 | 84 | 85 | accel->transform_skip_8 = transform_skip_8_fallback; 86 | accel->transform_skip_rdpcm_h_8 = transform_skip_rdpcm_h_8_fallback; 87 | accel->transform_skip_rdpcm_v_8 = transform_skip_rdpcm_v_8_fallback; 88 | accel->transform_bypass = transform_bypass_fallback; 89 | accel->transform_bypass_rdpcm_h = transform_bypass_rdpcm_h_fallback; 90 | accel->transform_bypass_rdpcm_v = transform_bypass_rdpcm_v_fallback; 91 | accel->transform_4x4_dst_add_8 = transform_4x4_luma_add_8_fallback; 92 | accel->transform_add_8[0] = transform_4x4_add_8_fallback; 93 | accel->transform_add_8[1] = transform_8x8_add_8_fallback; 94 | accel->transform_add_8[2] = transform_16x16_add_8_fallback; 95 | accel->transform_add_8[3] = transform_32x32_add_8_fallback; 96 | 97 | accel->transform_skip_16 = transform_skip_16_fallback; 98 | accel->transform_4x4_dst_add_16 = transform_4x4_luma_add_16_fallback; 99 | accel->transform_add_16[0] = transform_4x4_add_16_fallback; 100 | accel->transform_add_16[1] = transform_8x8_add_16_fallback; 101 | accel->transform_add_16[2] = transform_16x16_add_16_fallback; 102 | accel->transform_add_16[3] = transform_32x32_add_16_fallback; 103 | 104 | accel->rotate_coefficients = rotate_coefficients_fallback; 105 | accel->add_residual_8 = add_residual_fallback; 106 | accel->add_residual_16 = add_residual_fallback; 107 | accel->rdpcm_h = rdpcm_h_fallback; 108 | accel->rdpcm_v = rdpcm_v_fallback; 109 | accel->transform_skip_residual = transform_skip_residual_fallback; 110 | 111 | accel->transform_idst_4x4 = transform_idst_4x4_fallback; 112 | accel->transform_idct_4x4 = transform_idct_4x4_fallback; 113 | accel->transform_idct_8x8 = transform_idct_8x8_fallback; 114 | accel->transform_idct_16x16 = transform_idct_16x16_fallback; 115 | accel->transform_idct_32x32 = transform_idct_32x32_fallback; 116 | 117 | accel->fwd_transform_4x4_dst_8 = fdst_4x4_8_fallback; 118 | accel->fwd_transform_8[0] = fdct_4x4_8_fallback; 119 | accel->fwd_transform_8[1] = fdct_8x8_8_fallback; 120 | accel->fwd_transform_8[2] = fdct_16x16_8_fallback; 121 | accel->fwd_transform_8[3] = fdct_32x32_8_fallback; 122 | 123 | accel->hadamard_transform_8[0] = hadamard_4x4_8_fallback; 124 | accel->hadamard_transform_8[1] = hadamard_8x8_8_fallback; 125 | accel->hadamard_transform_8[2] = hadamard_16x16_8_fallback; 126 | accel->hadamard_transform_8[3] = hadamard_32x32_8_fallback; 127 | } 128 | -------------------------------------------------------------------------------- /libde265/libde265/fallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_FALLBACK_H 22 | #define DE265_FALLBACK_H 23 | 24 | #include "acceleration.h" 25 | 26 | void init_acceleration_functions_fallback(struct acceleration_functions* lowlevel); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /libde265/libde265/image-io.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * Authors: struktur AG, Dirk Farin 6 | * 7 | * This file is part of libde265. 8 | * 9 | * libde265 is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * libde265 is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with libde265. If not, see . 21 | */ 22 | 23 | #include "libde265/image-io.h" 24 | #include 25 | 26 | 27 | 28 | ImageSource::ImageSource() 29 | { 30 | } 31 | 32 | 33 | ImageSource_YUV::ImageSource_YUV() 34 | : mFH(NULL) 35 | { 36 | } 37 | 38 | 39 | ImageSource_YUV::~ImageSource_YUV() 40 | { 41 | if (mFH) { 42 | fclose(mFH); 43 | } 44 | } 45 | 46 | 47 | bool ImageSource_YUV::set_input_file(const char* filename, int w,int h) 48 | { 49 | assert(mFH==NULL); 50 | 51 | mFH = fopen(filename,"rb"); 52 | if (mFH==NULL) { 53 | return false; 54 | } 55 | 56 | width =w; 57 | height=h; 58 | mReachedEndOfFile = false; 59 | 60 | return true; 61 | } 62 | 63 | 64 | de265_image* ImageSource_YUV::read_next_image() 65 | { 66 | if (mReachedEndOfFile) return NULL; 67 | 68 | de265_image* img = new de265_image; 69 | img->alloc_image(width,height,de265_chroma_420, NULL, false, 70 | NULL, /*NULL,*/ 0, NULL, false); 71 | assert(img); // TODO: error handling 72 | 73 | // --- load image --- 74 | 75 | uint8_t* p; 76 | int stride; 77 | 78 | p = img->get_image_plane(0); stride = img->get_image_stride(0); 79 | for (int y=0;yget_image_plane(1); stride = img->get_image_stride(1); 86 | for (int y=0;yget_image_plane(2); stride = img->get_image_stride(2); 93 | for (int y=0;yget_width(); 160 | int height= img->get_height(); 161 | 162 | p = img->get_image_plane(0); stride = img->get_image_stride(0); 163 | for (int y=0;yget_image_plane(1); stride = img->get_image_stride(1); 169 | for (int y=0;yget_image_plane(2); stride = img->get_image_stride(2); 175 | for (int y=0;y 4 | * 5 | * Authors: struktur AG, Dirk Farin 6 | * 7 | * This file is part of libde265. 8 | * 9 | * libde265 is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as 11 | * published by the Free Software Foundation, either version 3 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * libde265 is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with libde265. If not, see . 21 | */ 22 | 23 | #ifndef IMAGE_IO_H 24 | #define IMAGE_IO_H 25 | 26 | #include "libde265/image.h" 27 | #include 28 | 29 | 30 | class ImageSource 31 | { 32 | public: 33 | LIBDE265_API ImageSource(); 34 | virtual LIBDE265_API ~ImageSource() { } 35 | 36 | //enum ImageStatus { Available, Waiting, EndOfVideo }; 37 | 38 | //virtual ImageStatus get_status() = 0; 39 | virtual LIBDE265_API de265_image* get_image(bool block=true) = 0; 40 | virtual LIBDE265_API void skip_frames(int n) = 0; 41 | 42 | virtual LIBDE265_API int get_width() const = 0; 43 | virtual LIBDE265_API int get_height() const = 0; 44 | }; 45 | 46 | 47 | 48 | class ImageSource_YUV : public ImageSource 49 | { 50 | public: 51 | LIBDE265_API ImageSource_YUV(); 52 | virtual LIBDE265_API ~ImageSource_YUV(); 53 | 54 | bool LIBDE265_API set_input_file(const char* filename, int w,int h); 55 | 56 | //virtual ImageStatus get_status(); 57 | virtual LIBDE265_API de265_image* get_image(bool block=true); 58 | virtual LIBDE265_API void skip_frames(int n); 59 | 60 | virtual LIBDE265_API int get_width() const { return width; } 61 | virtual LIBDE265_API int get_height() const { return height; } 62 | 63 | private: 64 | FILE* mFH; 65 | bool mReachedEndOfFile; 66 | 67 | int width,height; 68 | 69 | de265_image* read_next_image(); 70 | }; 71 | 72 | 73 | 74 | class ImageSink 75 | { 76 | public: 77 | virtual LIBDE265_API ~ImageSink() { } 78 | 79 | virtual LIBDE265_API void send_image(const de265_image* img) = 0; 80 | }; 81 | 82 | class ImageSink_YUV : public ImageSink 83 | { 84 | public: 85 | LIBDE265_API ImageSink_YUV() : mFH(NULL) { } 86 | LIBDE265_API ~ImageSink_YUV(); 87 | 88 | bool LIBDE265_API set_filename(const char* filename); 89 | 90 | virtual LIBDE265_API void send_image(const de265_image* img); 91 | 92 | private: 93 | FILE* mFH; 94 | }; 95 | 96 | 97 | 98 | class PacketSink 99 | { 100 | public: 101 | virtual LIBDE265_API ~PacketSink() { } 102 | 103 | virtual LIBDE265_API void send_packet(const uint8_t* data, int n) = 0; 104 | }; 105 | 106 | 107 | class PacketSink_File : public PacketSink 108 | { 109 | public: 110 | LIBDE265_API PacketSink_File(); 111 | virtual LIBDE265_API ~PacketSink_File(); 112 | 113 | LIBDE265_API void set_filename(const char* filename); 114 | 115 | virtual LIBDE265_API void send_packet(const uint8_t* data, int n); 116 | 117 | private: 118 | FILE* mFH; 119 | }; 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /libde265/libde265/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc. 3 | * MD5 Message-Digest Algorithm (RFC 1321). 4 | * 5 | * Homepage: 6 | * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5 7 | * 8 | * Author: 9 | * Alexander Peslyak, better known as Solar Designer 10 | * 11 | * This software was written by Alexander Peslyak in 2001. No copyright is 12 | * claimed, and the software is hereby placed in the public domain. 13 | * In case this attempt to disclaim copyright and place the software in the 14 | * public domain is deemed null and void, then the software is 15 | * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the 16 | * general public under the following terms: 17 | * 18 | * Redistribution and use in source and binary forms, with or without 19 | * modification, are permitted. 20 | * 21 | * There's ABSOLUTELY NO WARRANTY, express or implied. 22 | * 23 | * See md5.c for more information. 24 | */ 25 | 26 | #ifdef HAVE_OPENSSL 27 | #include 28 | #elif !defined(_MD5_H) 29 | #define _MD5_H 30 | 31 | /* Any 32-bit or wider unsigned integer data type will do */ 32 | typedef unsigned int MD5_u32plus; 33 | 34 | typedef struct { 35 | MD5_u32plus lo, hi; 36 | MD5_u32plus a, b, c, d; 37 | unsigned char buffer[64]; 38 | MD5_u32plus block[16]; 39 | } MD5_CTX; 40 | 41 | extern void MD5_Init(MD5_CTX *ctx); 42 | extern void MD5_Update(MD5_CTX *ctx, void *data, unsigned long size); 43 | extern void MD5_Final(unsigned char *result, MD5_CTX *ctx); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /libde265/libde265/motion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_MOTION_H 22 | #define DE265_MOTION_H 23 | 24 | #include 25 | #include "slice.h" 26 | 27 | class base_context; 28 | class slice_segment_header; 29 | 30 | class MotionVector 31 | { 32 | public: 33 | int16_t x,y; 34 | }; 35 | 36 | 37 | class PBMotion 38 | { 39 | public: 40 | uint8_t predFlag[2]; // which of the two vectors is actually used 41 | int8_t refIdx[2]; // index into RefPicList 42 | MotionVector mv[2]; // the absolute motion vectors 43 | 44 | bool operator==(const PBMotion&) const; 45 | }; 46 | 47 | 48 | class PBMotionCoding 49 | { 50 | public: 51 | // index into RefPicList 52 | int8_t refIdx[2]; 53 | 54 | // motion vector difference 55 | int16_t mvd[2][2]; // [L0/L1][x/y] (only in top left position - ???) 56 | 57 | // enum InterPredIdc, whether this is prediction from L0,L1, or BI 58 | uint8_t inter_pred_idc : 2; 59 | 60 | // which of the two MVPs is used 61 | uint8_t mvp_l0_flag : 1; 62 | uint8_t mvp_l1_flag : 1; 63 | 64 | // whether merge mode is used 65 | uint8_t merge_flag : 1; 66 | uint8_t merge_idx : 3; 67 | }; 68 | 69 | 70 | void get_merge_candidate_list(base_context* ctx, 71 | const slice_segment_header* shdr, 72 | struct de265_image* img, 73 | int xC,int yC, int xP,int yP, 74 | int nCS, int nPbW,int nPbH, int partIdx, 75 | PBMotion* mergeCandList); 76 | 77 | /* 78 | int derive_spatial_merging_candidates(const struct de265_image* img, 79 | int xC, int yC, int nCS, int xP, int yP, 80 | uint8_t singleMCLFlag, 81 | int nPbW, int nPbH, 82 | int partIdx, 83 | MotionVectorSpec* out_cand, 84 | int maxCandidates); 85 | */ 86 | 87 | void generate_inter_prediction_samples(base_context* ctx, 88 | const slice_segment_header* shdr, 89 | struct de265_image* img, 90 | int xC,int yC, 91 | int xB,int yB, 92 | int nCS, int nPbW,int nPbH, 93 | const PBMotion* vi); 94 | 95 | 96 | /* Fill list (two entries) of motion-vector predictors for MVD coding. 97 | */ 98 | void fill_luma_motion_vector_predictors(base_context* ctx, 99 | const slice_segment_header* shdr, 100 | de265_image* img, 101 | int xC,int yC,int nCS,int xP,int yP, 102 | int nPbW,int nPbH, int l, 103 | int refIdx, int partIdx, 104 | MotionVector out_mvpList[2]); 105 | 106 | 107 | void decode_prediction_unit(base_context* ctx,const slice_segment_header* shdr, 108 | de265_image* img, const PBMotionCoding& motion, 109 | int xC,int yC, int xB,int yB, int nCS, int nPbW,int nPbH, int partIdx); 110 | 111 | 112 | 113 | 114 | class MotionVectorAccess 115 | { 116 | public: 117 | virtual enum PartMode get_PartMode(int x,int y) const = 0; 118 | virtual const PBMotion& get_mv_info(int x,int y) const = 0; 119 | }; 120 | 121 | 122 | void get_merge_candidate_list_without_step_9(base_context* ctx, 123 | const slice_segment_header* shdr, 124 | const MotionVectorAccess& mvaccess, 125 | de265_image* img, 126 | int xC,int yC, int xP,int yP, 127 | int nCS, int nPbW,int nPbH, int partIdx, 128 | int max_merge_idx, 129 | PBMotion* mergeCandList); 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /libde265/libde265/nal-parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_NAL_PARSER_H 22 | #define DE265_NAL_PARSER_H 23 | 24 | #include "libde265/sps.h" 25 | #include "libde265/pps.h" 26 | #include "libde265/nal.h" 27 | #include "libde265/util.h" 28 | 29 | #include 30 | #include 31 | 32 | #define DE265_NAL_FREE_LIST_SIZE 16 33 | #define DE265_SKIPPED_BYTES_INITIAL_SIZE 16 34 | 35 | 36 | class NAL_unit { 37 | public: 38 | NAL_unit(); 39 | ~NAL_unit(); 40 | 41 | nal_header header; 42 | 43 | de265_PTS pts; 44 | void* user_data; 45 | 46 | 47 | void clear(); 48 | 49 | // --- rbsp data --- 50 | 51 | LIBDE265_CHECK_RESULT bool resize(int new_size); 52 | LIBDE265_CHECK_RESULT bool append(const unsigned char* data, int n); 53 | LIBDE265_CHECK_RESULT bool set_data(const unsigned char* data, int n); 54 | 55 | int size() const { return data_size; } 56 | void set_size(int s) { data_size=s; } 57 | unsigned char* data() { return nal_data; } 58 | const unsigned char* data() const { return nal_data; } 59 | 60 | 61 | // --- skipped stuffing bytes --- 62 | 63 | int num_skipped_bytes_before(int byte_position, int headerLength) const; 64 | int num_skipped_bytes() const { return skipped_bytes.size(); } 65 | 66 | //void clear_skipped_bytes() { skipped_bytes.clear(); } 67 | 68 | /* Mark a byte as skipped. It is assumed that the byte is already removed 69 | from the input data. The NAL data is not modified. 70 | */ 71 | void insert_skipped_byte(int pos); 72 | 73 | /* Remove all stuffing bytes from NAL data. The NAL data is modified and 74 | the removed bytes are marked as skipped bytes. 75 | */ 76 | void remove_stuffing_bytes(); 77 | 78 | private: 79 | unsigned char* nal_data; 80 | int data_size; 81 | int capacity; 82 | 83 | std::vector skipped_bytes; // up to position[x], there were 'x' skipped bytes 84 | }; 85 | 86 | 87 | class NAL_Parser 88 | { 89 | public: 90 | NAL_Parser(); 91 | ~NAL_Parser(); 92 | 93 | de265_error push_data(const unsigned char* data, int len, 94 | de265_PTS pts, void* user_data = NULL); 95 | 96 | de265_error push_NAL(const unsigned char* data, int len, 97 | de265_PTS pts, void* user_data = NULL); 98 | 99 | NAL_unit* pop_from_NAL_queue(); 100 | de265_error flush_data(); 101 | void mark_end_of_stream() { end_of_stream=true; } 102 | void mark_end_of_frame() { end_of_frame=true; } 103 | void remove_pending_input_data(); 104 | 105 | int bytes_in_input_queue() const { 106 | int size = nBytes_in_NAL_queue; 107 | if (pending_input_NAL) { size += pending_input_NAL->size(); } 108 | return size; 109 | } 110 | 111 | int number_of_NAL_units_pending() const { 112 | int size = NAL_queue.size(); 113 | if (pending_input_NAL) { size++; } 114 | return size; 115 | } 116 | 117 | int number_of_complete_NAL_units_pending() const { 118 | return NAL_queue.size(); 119 | } 120 | 121 | void free_NAL_unit(NAL_unit*); 122 | 123 | 124 | int get_NAL_queue_length() const { return NAL_queue.size(); } 125 | bool is_end_of_stream() const { return end_of_stream; } 126 | bool is_end_of_frame() const { return end_of_frame; } 127 | 128 | private: 129 | // byte-stream level 130 | 131 | bool end_of_stream; // data in pending_input_data is end of stream 132 | bool end_of_frame; // data in pending_input_data is end of frame 133 | int input_push_state; 134 | 135 | NAL_unit* pending_input_NAL; 136 | 137 | 138 | // NAL level 139 | 140 | std::queue NAL_queue; // enqueued NALs have suffing bytes removed 141 | int nBytes_in_NAL_queue; // data bytes currently in NAL_queue 142 | 143 | void push_to_NAL_queue(NAL_unit*); 144 | 145 | 146 | // pool of unused NAL memory 147 | 148 | std::vector NAL_free_list; // maximum size: DE265_NAL_FREE_LIST_SIZE 149 | 150 | LIBDE265_CHECK_RESULT NAL_unit* alloc_NAL_unit(int size); 151 | }; 152 | 153 | 154 | #endif 155 | -------------------------------------------------------------------------------- /libde265/libde265/nal.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #include "nal.h" 22 | #include "cabac.h" 23 | #include 24 | 25 | 26 | void nal_header::read(bitreader* reader) 27 | { 28 | skip_bits(reader,1); 29 | nal_unit_type = get_bits(reader,6); 30 | nuh_layer_id = get_bits(reader,6); 31 | nuh_temporal_id = get_bits(reader,3) -1; 32 | } 33 | 34 | 35 | void nal_header::write(CABAC_encoder& out) const 36 | { 37 | out.skip_bits(1); 38 | out.write_bits(nal_unit_type,6); 39 | out.write_bits(nuh_layer_id ,6); 40 | out.write_bits(nuh_temporal_id+1,3); 41 | } 42 | 43 | 44 | bool isIDR(uint8_t unit_type) 45 | { 46 | return (unit_type == NAL_UNIT_IDR_W_RADL || 47 | unit_type == NAL_UNIT_IDR_N_LP); 48 | } 49 | 50 | bool isBLA(uint8_t unit_type) 51 | { 52 | return (unit_type == NAL_UNIT_BLA_W_LP || 53 | unit_type == NAL_UNIT_BLA_W_RADL || 54 | unit_type == NAL_UNIT_BLA_N_LP); 55 | } 56 | 57 | bool isCRA(uint8_t unit_type) 58 | { 59 | return unit_type == NAL_UNIT_CRA_NUT; 60 | } 61 | 62 | bool isRAP(uint8_t unit_type) 63 | { 64 | return isIDR(unit_type) || isBLA(unit_type) || isCRA(unit_type); 65 | } 66 | 67 | bool isRASL(uint8_t unit_type) 68 | { 69 | return (unit_type == NAL_UNIT_RASL_N || 70 | unit_type == NAL_UNIT_RASL_R); 71 | } 72 | 73 | bool isIRAP(uint8_t unit_type) 74 | { 75 | return (unit_type >= NAL_UNIT_BLA_W_LP && 76 | unit_type <= NAL_UNIT_RESERVED_IRAP_VCL23); 77 | } 78 | 79 | bool isRADL(uint8_t unit_type) 80 | { 81 | return (unit_type == NAL_UNIT_RADL_N || 82 | unit_type == NAL_UNIT_RADL_R); 83 | } 84 | 85 | 86 | bool isReferenceNALU(uint8_t unit_type) 87 | { 88 | return ( ((unit_type <= NAL_UNIT_RESERVED_VCL_R15) && (unit_type%2 != 0)) || 89 | ((unit_type >= NAL_UNIT_BLA_W_LP) && 90 | (unit_type <= NAL_UNIT_RESERVED_IRAP_VCL23)) ); 91 | } 92 | 93 | bool isSublayerNonReference(uint8_t unit_type) 94 | { 95 | switch (unit_type) { 96 | case NAL_UNIT_TRAIL_N: 97 | case NAL_UNIT_TSA_N: 98 | case NAL_UNIT_STSA_N: 99 | case NAL_UNIT_RADL_N: 100 | case NAL_UNIT_RASL_N: 101 | case NAL_UNIT_RESERVED_VCL_N10: 102 | case NAL_UNIT_RESERVED_VCL_N12: 103 | case NAL_UNIT_RESERVED_VCL_N14: 104 | return true; 105 | 106 | default: 107 | return false; 108 | } 109 | } 110 | 111 | static const char* NAL_unit_name[] = { 112 | "TRAIL_N", // 0 113 | "TRAIL_R", 114 | "TSA_N", 115 | "TSA_R", 116 | "STSA_N", 117 | "STSA_R", // 5 118 | "RADL_N", 119 | "RADL_R", 120 | "RASL_N", 121 | "RASL_R", 122 | "RESERVED_VCL_N10", // 10 123 | "RESERVED_VCL_R11", 124 | "RESERVED_VCL_N12", 125 | "RESERVED_VCL_R13", 126 | "RESERVED_VCL_N14", 127 | "RESERVED_VCL_R15", // 15 128 | "BLA_W_LP", 129 | "BLA_W_RADL", 130 | "BLA_N_LP", 131 | "IDR_W_RADL", 132 | "IDR_N_LP", // 20 133 | "CRA_NUT", 134 | "RESERVED_IRAP_VCL22", 135 | "RESERVED_IRAP_VCL23", 136 | "RESERVED_VCL24", 137 | "RESERVED_VCL25", // 25 138 | "RESERVED_VCL26", 139 | "RESERVED_VCL27", 140 | "RESERVED_VCL28", 141 | "RESERVED_VCL29", 142 | "RESERVED_VCL30", // 30 143 | "RESERVED_VCL31", 144 | "VPS", 145 | "SPS", 146 | "PPS", 147 | "AUD", // 35 148 | "EOS", 149 | "EOB", 150 | "FD", 151 | "PREFIX_SEI", 152 | "SUFFIX_SEI", // 40 153 | "RESERVED_NVCL41", 154 | "RESERVED_NVCL42", 155 | "RESERVED_NVCL43", 156 | "RESERVED_NVCL44", 157 | "RESERVED_NVCL45", // 45 158 | "RESERVED_NVCL46", 159 | "RESERVED_NVCL47" 160 | }; 161 | 162 | const char* get_NAL_name(uint8_t unit_type) 163 | { 164 | if (unit_type >= 48) { return "INVALID NAL >= 48"; } 165 | return NAL_unit_name[unit_type]; 166 | } 167 | -------------------------------------------------------------------------------- /libde265/libde265/nal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_NAL_H 22 | #define DE265_NAL_H 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | 30 | #include "libde265/bitstream.h" 31 | #include "libde265/cabac.h" 32 | 33 | struct nal_header { 34 | nal_header() { 35 | nal_unit_type = 0; 36 | nuh_layer_id = 0; 37 | nuh_temporal_id = 0; 38 | } 39 | 40 | void read(bitreader* reader); 41 | void write(CABAC_encoder& writer) const; 42 | 43 | void set(int unit_type, int layer_id=0, int temporal_id=0) { 44 | nal_unit_type =unit_type; 45 | nuh_layer_id =layer_id; 46 | nuh_temporal_id=temporal_id; 47 | } 48 | 49 | uint8_t nal_unit_type; 50 | uint8_t nuh_layer_id; 51 | uint8_t nuh_temporal_id; 52 | }; 53 | 54 | #define NAL_UNIT_TRAIL_N 0 55 | #define NAL_UNIT_TRAIL_R 1 56 | #define NAL_UNIT_TSA_N 2 57 | #define NAL_UNIT_TSA_R 3 58 | #define NAL_UNIT_STSA_N 4 59 | #define NAL_UNIT_STSA_R 5 60 | #define NAL_UNIT_RADL_N 6 61 | #define NAL_UNIT_RADL_R 7 62 | #define NAL_UNIT_RASL_N 8 63 | #define NAL_UNIT_RASL_R 9 64 | #define NAL_UNIT_RESERVED_VCL_N10 10 65 | #define NAL_UNIT_RESERVED_VCL_N12 12 66 | #define NAL_UNIT_RESERVED_VCL_N14 14 67 | #define NAL_UNIT_RESERVED_VCL_R11 11 68 | #define NAL_UNIT_RESERVED_VCL_R13 13 69 | #define NAL_UNIT_RESERVED_VCL_R15 15 70 | #define NAL_UNIT_BLA_W_LP 16 // BLA = broken link access 71 | #define NAL_UNIT_BLA_W_RADL 17 72 | #define NAL_UNIT_BLA_N_LP 18 73 | #define NAL_UNIT_IDR_W_RADL 19 74 | #define NAL_UNIT_IDR_N_LP 20 75 | #define NAL_UNIT_CRA_NUT 21 // CRA = clean random access 76 | #define NAL_UNIT_RESERVED_IRAP_VCL22 22 77 | #define NAL_UNIT_RESERVED_IRAP_VCL23 23 78 | #define NAL_UNIT_RESERVED_VCL24 24 79 | #define NAL_UNIT_RESERVED_VCL25 25 80 | #define NAL_UNIT_RESERVED_VCL26 26 81 | #define NAL_UNIT_RESERVED_VCL27 27 82 | #define NAL_UNIT_RESERVED_VCL28 28 83 | #define NAL_UNIT_RESERVED_VCL29 29 84 | #define NAL_UNIT_RESERVED_VCL30 30 85 | #define NAL_UNIT_RESERVED_VCL31 31 86 | #define NAL_UNIT_VPS_NUT 32 87 | #define NAL_UNIT_SPS_NUT 33 88 | #define NAL_UNIT_PPS_NUT 34 89 | #define NAL_UNIT_AUD_NUT 35 90 | #define NAL_UNIT_EOS_NUT 36 91 | #define NAL_UNIT_EOB_NUT 37 92 | #define NAL_UNIT_FD_NUT 38 93 | #define NAL_UNIT_PREFIX_SEI_NUT 39 94 | #define NAL_UNIT_SUFFIX_SEI_NUT 40 95 | #define NAL_UNIT_RESERVED_NVCL41 41 96 | #define NAL_UNIT_RESERVED_NVCL42 42 97 | #define NAL_UNIT_RESERVED_NVCL43 43 98 | #define NAL_UNIT_RESERVED_NVCL44 44 99 | #define NAL_UNIT_RESERVED_NVCL45 45 100 | #define NAL_UNIT_RESERVED_NVCL46 46 101 | #define NAL_UNIT_RESERVED_NVCL47 47 102 | 103 | #define NAL_UNIT_UNDEFINED 255 104 | 105 | bool isIDR(uint8_t unit_type); 106 | bool isBLA(uint8_t unit_type); 107 | bool isCRA(uint8_t unit_type); 108 | bool isRAP(uint8_t unit_type); 109 | bool isRASL(uint8_t unit_type); 110 | bool isIRAP(uint8_t unit_type); 111 | bool isRADL(uint8_t unit_type); 112 | bool isReferenceNALU(uint8_t unit_type); 113 | bool isSublayerNonReference(uint8_t unit_type); 114 | 115 | const char* get_NAL_name(uint8_t unit_type); 116 | 117 | inline bool isIdrPic(uint8_t nal_unit_type) { 118 | return (nal_unit_type == NAL_UNIT_IDR_W_RADL || 119 | nal_unit_type == NAL_UNIT_IDR_N_LP); 120 | } 121 | 122 | inline bool isRapPic(uint8_t nal_unit_type) { 123 | return nal_unit_type >= 16 && nal_unit_type <= 23; 124 | } 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /libde265/libde265/pps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_PPS_H 22 | #define DE265_PPS_H 23 | 24 | #include "libde265/bitstream.h" 25 | #include "libde265/sps.h" // for scaling list only 26 | 27 | #include 28 | #include 29 | 30 | #define DE265_MAX_TILE_COLUMNS 10 31 | #define DE265_MAX_TILE_ROWS 10 32 | 33 | class decoder_context; 34 | class pic_parameter_set; 35 | 36 | 37 | class pps_range_extension 38 | { 39 | public: 40 | pps_range_extension() { reset(); } 41 | 42 | void reset(); 43 | 44 | bool read(bitreader*, decoder_context*, const pic_parameter_set*); 45 | void dump(int fd) const; 46 | 47 | uint8_t log2_max_transform_skip_block_size; 48 | bool cross_component_prediction_enabled_flag; 49 | bool chroma_qp_offset_list_enabled_flag; 50 | uint8_t diff_cu_chroma_qp_offset_depth; 51 | uint8_t chroma_qp_offset_list_len; 52 | int8_t cb_qp_offset_list[6]; 53 | int8_t cr_qp_offset_list[6]; 54 | uint8_t log2_sao_offset_scale_luma; 55 | uint8_t log2_sao_offset_scale_chroma; 56 | }; 57 | 58 | 59 | class pic_parameter_set { 60 | public: 61 | pic_parameter_set(); 62 | ~pic_parameter_set(); 63 | 64 | void reset() { set_defaults(); } 65 | bool read(bitreader*, decoder_context*); 66 | bool write(error_queue*, CABAC_encoder&, 67 | const seq_parameter_set* sps); 68 | 69 | bool is_tile_start_CTB(int ctbX,int ctbY) const; 70 | void dump(int fd) const; 71 | 72 | 73 | void set_defaults(enum PresetSet = Preset_Default); 74 | 75 | bool pps_read; // whether this pps has been read from bitstream 76 | std::shared_ptr sps; 77 | 78 | 79 | char pic_parameter_set_id; 80 | char seq_parameter_set_id; 81 | char dependent_slice_segments_enabled_flag; 82 | char sign_data_hiding_flag; 83 | char cabac_init_present_flag; 84 | char num_ref_idx_l0_default_active; // [1;16] 85 | char num_ref_idx_l1_default_active; // [1;16] 86 | 87 | int pic_init_qp; 88 | char constrained_intra_pred_flag; 89 | char transform_skip_enabled_flag; 90 | 91 | // --- QP --- 92 | 93 | char cu_qp_delta_enabled_flag; 94 | int diff_cu_qp_delta_depth; // [ 0 ; log2_diff_max_min_luma_coding_block_size ] 95 | 96 | int pic_cb_qp_offset; 97 | int pic_cr_qp_offset; 98 | char pps_slice_chroma_qp_offsets_present_flag; 99 | 100 | 101 | char weighted_pred_flag; 102 | char weighted_bipred_flag; 103 | char output_flag_present_flag; 104 | char transquant_bypass_enable_flag; 105 | char entropy_coding_sync_enabled_flag; 106 | 107 | 108 | // --- tiles --- 109 | 110 | char tiles_enabled_flag; 111 | int num_tile_columns; // [1;PicWidthInCtbsY] 112 | int num_tile_rows; // [1;PicHeightInCtbsY] 113 | char uniform_spacing_flag; 114 | 115 | 116 | // --- --- 117 | 118 | char loop_filter_across_tiles_enabled_flag; 119 | char pps_loop_filter_across_slices_enabled_flag; 120 | char deblocking_filter_control_present_flag; 121 | 122 | char deblocking_filter_override_enabled_flag; 123 | char pic_disable_deblocking_filter_flag; 124 | 125 | int beta_offset; 126 | int tc_offset; 127 | 128 | char pic_scaling_list_data_present_flag; 129 | struct scaling_list_data scaling_list; // contains valid data if sps->scaling_list_enabled_flag set 130 | 131 | char lists_modification_present_flag; 132 | int log2_parallel_merge_level; // [2 ; log2(max CB size)] 133 | char num_extra_slice_header_bits; 134 | char slice_segment_header_extension_present_flag; 135 | char pps_extension_flag; 136 | char pps_range_extension_flag; 137 | char pps_multilayer_extension_flag; 138 | char pps_extension_6bits; 139 | 140 | pps_range_extension range_extension; 141 | 142 | 143 | // --- derived values --- 144 | 145 | int Log2MinCuQpDeltaSize; 146 | int Log2MinCuChromaQpOffsetSize; 147 | int Log2MaxTransformSkipSize; 148 | 149 | int colWidth [ DE265_MAX_TILE_COLUMNS ]; 150 | int rowHeight[ DE265_MAX_TILE_ROWS ]; 151 | int colBd [ DE265_MAX_TILE_COLUMNS+1 ]; 152 | int rowBd [ DE265_MAX_TILE_ROWS+1 ]; 153 | 154 | std::vector CtbAddrRStoTS; // #CTBs 155 | std::vector CtbAddrTStoRS; // #CTBs 156 | std::vector TileId; // #CTBs // index in tile-scan order 157 | std::vector TileIdRS; // #CTBs // index in raster-scan order 158 | std::vector MinTbAddrZS; // #TBs [x + y*PicWidthInTbsY] 159 | 160 | void set_derived_values(const seq_parameter_set* sps); 161 | }; 162 | 163 | #endif 164 | -------------------------------------------------------------------------------- /libde265/libde265/quality.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #include "quality.h" 22 | #include 23 | 24 | 25 | uint32_t SSD(const uint8_t* img, int imgStride, 26 | const uint8_t* ref, int refStride, 27 | int width, int height) 28 | { 29 | uint32_t sum=0; 30 | 31 | const uint8_t* iPtr = img; 32 | const uint8_t* rPtr = ref; 33 | 34 | for (int y=0;yget_image_plane_at_pos(cIdx,x0,y0), img1->get_image_stride(cIdx), 109 | img2->get_image_plane_at_pos(cIdx,x0,y0), img2->get_image_stride(cIdx), 110 | 1< 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_QUALITY_H 22 | #define DE265_QUALITY_H 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | LIBDE265_API uint32_t SSD(const uint8_t* img, int imgStride, 30 | const uint8_t* ref, int refStride, 31 | int width, int height); 32 | 33 | LIBDE265_API uint32_t SAD(const uint8_t* img, int imgStride, 34 | const uint8_t* ref, int refStride, 35 | int width, int height); 36 | 37 | LIBDE265_API double MSE(const uint8_t* img, int imgStride, 38 | const uint8_t* ref, int refStride, 39 | int width, int height); 40 | 41 | LIBDE265_API double PSNR(double mse); 42 | 43 | 44 | LIBDE265_API uint32_t compute_distortion_ssd(const de265_image* img1, const de265_image* img2, 45 | int x0, int y0, int log2size, int cIdx); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /libde265/libde265/refpic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_REFPIC_H 22 | #define DE265_REFPIC_H 23 | 24 | #include "libde265/bitstream.h" 25 | 26 | #define MAX_NUM_REF_PICS 16 // maximum defined by standard, may be lower for some Levels 27 | 28 | 29 | class ref_pic_set 30 | { 31 | public: 32 | // Lists of pictures that have to be kept in the decoded picture buffer for future 33 | // reference and that may optionally be used for prediction in the current frame. 34 | // Lists contain the relative POC positions. 35 | int16_t DeltaPocS0[MAX_NUM_REF_PICS]; // sorted in decreasing order (e.g. -1, -2, -4, -7, ...) 36 | int16_t DeltaPocS1[MAX_NUM_REF_PICS]; // sorted in ascending order (e.g. 1, 2, 4, 7) 37 | 38 | // flag for each reference whether this is actually used for prediction in the current frame 39 | uint8_t UsedByCurrPicS0[MAX_NUM_REF_PICS]; 40 | uint8_t UsedByCurrPicS1[MAX_NUM_REF_PICS]; 41 | 42 | uint8_t NumNegativePics; // number of past reference pictures 43 | uint8_t NumPositivePics; // number of future reference pictures 44 | 45 | // --- derived values --- 46 | 47 | void compute_derived_values(); 48 | 49 | uint8_t NumDeltaPocs; // total number of reference pictures (past + future) 50 | 51 | uint8_t NumPocTotalCurr_shortterm_only; /* Total number of reference pictures that may actually 52 | be used for prediction in the current frame. */ 53 | 54 | void reset(); 55 | }; 56 | 57 | 58 | void dump_short_term_ref_pic_set(const ref_pic_set*, FILE* fh); 59 | void dump_compact_short_term_ref_pic_set(const ref_pic_set* set, int range, FILE* fh); 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /libde265/libde265/sao.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_SAO_H 22 | #define DE265_SAO_H 23 | 24 | #include "libde265/decctx.h" 25 | 26 | void apply_sample_adaptive_offset(de265_image* img); 27 | 28 | /* requires less memory than the function above */ 29 | void apply_sample_adaptive_offset_sequential(de265_image* img); 30 | 31 | /* saoInputProgress - the CTB progress that SAO will wait for before beginning processing. 32 | Returns 'true' if any tasks have been added. 33 | */ 34 | bool add_sao_tasks(image_unit* imgunit, int saoInputProgress); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /libde265/libde265/scan.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #include "scan.h" 22 | 23 | static position scan0 = { 0,0 }; 24 | static position scan_h_1[ 2* 2], scan_v_1[ 2* 2], scan_d_1[ 2* 2]; 25 | static position scan_h_2[ 4* 4], scan_v_2[ 4* 4], scan_d_2[ 4* 4]; 26 | static position scan_h_3[ 8* 8], scan_v_3[ 8* 8], scan_d_3[ 8* 8]; 27 | static position scan_h_4[16*16], scan_v_4[16*16], scan_d_4[16*16]; 28 | static position scan_h_5[32*32], scan_v_5[32*32], scan_d_5[32*32]; 29 | 30 | static position* scan_h[7] = { &scan0,scan_h_1,scan_h_2,scan_h_3,scan_h_4,scan_h_5 }; 31 | static position* scan_v[7] = { &scan0,scan_v_1,scan_v_2,scan_v_3,scan_v_4,scan_v_5 }; 32 | static position* scan_d[7] = { &scan0,scan_d_1,scan_d_2,scan_d_3,scan_d_4,scan_d_5 }; 33 | 34 | static void init_scan_h(position* scan, int blkSize) 35 | { 36 | int i=0; 37 | for (int y=0;y=0) { 65 | if (xsubBlock = lastSubBlock; 131 | pos->scanPos = lastScanPos; 132 | } 133 | 134 | 135 | void init_scan_orders() 136 | { 137 | for (int log2size=1;log2size<=5;log2size++) 138 | { 139 | init_scan_h(scan_h[log2size], 1< 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_SCAN_H 22 | #define DE265_SCAN_H 23 | 24 | #include 25 | 26 | typedef struct { 27 | uint8_t x,y; 28 | } position; 29 | 30 | typedef struct { 31 | uint8_t subBlock; 32 | uint8_t scanPos; 33 | } scan_position; 34 | 35 | void init_scan_orders(); 36 | 37 | /* scanIdx: 0 - diag, 1 - horiz, 2 - verti 38 | */ 39 | const position* get_scan_order(int log2BlockSize, int scanIdx); 40 | 41 | scan_position get_scan_position(int x,int y, int scanIdx, int log2BlkSize); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /libde265/libde265/sei.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_SEI_H 22 | #define DE265_SEI_H 23 | 24 | #include "libde265/bitstream.h" 25 | #include "libde265/de265.h" 26 | 27 | 28 | enum sei_payload_type { 29 | sei_payload_type_buffering_period = 0, 30 | sei_payload_type_pic_timing = 1, 31 | sei_payload_type_pan_scan_rect = 2, 32 | sei_payload_type_filler_payload = 3, 33 | sei_payload_type_user_data_registered_itu_t_t35 = 4, 34 | sei_payload_type_user_data_unregistered = 5, 35 | sei_payload_type_recovery_point = 6, 36 | sei_payload_type_scene_info = 9, 37 | sei_payload_type_picture_snapshot = 15, 38 | sei_payload_type_progressive_refinement_segment_start = 16, 39 | sei_payload_type_progressive_refinement_segment_end = 17, 40 | sei_payload_type_film_grain_characteristics = 19, 41 | sei_payload_type_post_filter_hint = 22, 42 | sei_payload_type_tone_mapping_info = 23, 43 | sei_payload_type_frame_packing_arrangement = 45, 44 | sei_payload_type_display_orientation = 47, 45 | sei_payload_type_structure_of_pictures_info = 128, 46 | sei_payload_type_active_parameter_sets = 129, 47 | sei_payload_type_decoding_unit_info = 130, 48 | sei_payload_type_temporal_sub_layer_zero_index = 131, 49 | sei_payload_type_decoded_picture_hash = 132, 50 | sei_payload_type_scalable_nesting = 133, 51 | sei_payload_type_region_refresh_info = 134, 52 | sei_payload_type_no_display = 135, 53 | sei_payload_type_motion_constrained_tile_sets = 136 54 | }; 55 | 56 | 57 | enum sei_decoded_picture_hash_type { 58 | sei_decoded_picture_hash_type_MD5 = 0, 59 | sei_decoded_picture_hash_type_CRC = 1, 60 | sei_decoded_picture_hash_type_checksum = 2 61 | }; 62 | 63 | 64 | typedef struct { 65 | enum sei_decoded_picture_hash_type hash_type; 66 | uint8_t md5[3][16]; 67 | uint16_t crc[3]; 68 | uint32_t checksum[3]; 69 | } sei_decoded_picture_hash; 70 | 71 | 72 | typedef struct { 73 | enum sei_payload_type payload_type; 74 | int payload_size; 75 | 76 | union { 77 | sei_decoded_picture_hash decoded_picture_hash; 78 | } data; 79 | } sei_message; 80 | 81 | class seq_parameter_set; 82 | 83 | const char* sei_type_name(enum sei_payload_type type); 84 | 85 | de265_error read_sei(bitreader* reader, sei_message*, bool suffix, const seq_parameter_set* sps); 86 | void dump_sei(const sei_message*, const seq_parameter_set* sps); 87 | de265_error process_sei(const sei_message*, struct de265_image* img); 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /libde265/libde265/sps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_SPS_H 22 | #define DE265_SPS_H 23 | 24 | #include "libde265/vps.h" 25 | #include "libde265/vui.h" 26 | #include "libde265/bitstream.h" 27 | #include "libde265/refpic.h" 28 | #include "libde265/de265.h" 29 | #include "libde265/cabac.h" 30 | 31 | #include 32 | 33 | class error_queue; 34 | 35 | // #define MAX_REF_PIC_SETS 64 // maximum according to standard 36 | #define MAX_NUM_LT_REF_PICS_SPS 32 37 | 38 | // This is just a safety range. It is chosen such that width/height fits into 16bit integers and the total number of pixels in 32bit integers. 39 | #define MAX_PICTURE_WIDTH 65535 40 | #define MAX_PICTURE_HEIGHT 65535 41 | 42 | enum { 43 | CHROMA_MONO = 0, 44 | CHROMA_420 = 1, 45 | CHROMA_422 = 2, 46 | CHROMA_444 = 3, 47 | CHROMA_444_SEPARATE 48 | }; 49 | 50 | 51 | typedef struct scaling_list_data { 52 | // structure size: approx. 4 kB 53 | 54 | uint8_t ScalingFactor_Size0[6][4][4]; 55 | uint8_t ScalingFactor_Size1[6][8][8]; 56 | uint8_t ScalingFactor_Size2[6][16][16]; 57 | uint8_t ScalingFactor_Size3[6][32][32]; 58 | } scaling_list_data; 59 | 60 | 61 | enum PresetSet { 62 | Preset_Default 63 | }; 64 | 65 | 66 | class sps_range_extension 67 | { 68 | public: 69 | sps_range_extension(); 70 | 71 | uint8_t transform_skip_rotation_enabled_flag; 72 | uint8_t transform_skip_context_enabled_flag; 73 | uint8_t implicit_rdpcm_enabled_flag; 74 | uint8_t explicit_rdpcm_enabled_flag; 75 | uint8_t extended_precision_processing_flag; 76 | uint8_t intra_smoothing_disabled_flag; 77 | uint8_t high_precision_offsets_enabled_flag; 78 | uint8_t persistent_rice_adaptation_enabled_flag; 79 | uint8_t cabac_bypass_alignment_enabled_flag; 80 | 81 | de265_error read(error_queue*, bitreader*); 82 | void dump(int fd) const; 83 | }; 84 | 85 | 86 | class seq_parameter_set { 87 | public: 88 | seq_parameter_set(); 89 | ~seq_parameter_set(); 90 | 91 | de265_error read(error_queue*, bitreader*); 92 | de265_error write(error_queue*, CABAC_encoder&); 93 | 94 | void dump(int fd) const; 95 | 96 | void set_defaults(enum PresetSet = Preset_Default); 97 | void set_CB_log2size_range(int mini,int maxi); 98 | void set_TB_log2size_range(int mini,int maxi); 99 | void set_resolution(int w,int h); 100 | 101 | bool sps_read; // whether the sps has been read from the bitstream 102 | 103 | 104 | char video_parameter_set_id; 105 | char sps_max_sub_layers; // [1;7] 106 | char sps_temporal_id_nesting_flag; 107 | 108 | profile_tier_level profile_tier_level_; 109 | 110 | int seq_parameter_set_id; 111 | int chroma_format_idc; 112 | 113 | char separate_colour_plane_flag; 114 | int pic_width_in_luma_samples; 115 | int pic_height_in_luma_samples; 116 | char conformance_window_flag; 117 | 118 | int conf_win_left_offset; 119 | int conf_win_right_offset; 120 | int conf_win_top_offset; 121 | int conf_win_bottom_offset; 122 | 123 | int bit_depth_luma; 124 | int bit_depth_chroma; 125 | 126 | int log2_max_pic_order_cnt_lsb; 127 | char sps_sub_layer_ordering_info_present_flag; 128 | 129 | int sps_max_dec_pic_buffering[7]; // for each temporal layer 130 | int sps_max_num_reorder_pics[7]; 131 | int sps_max_latency_increase_plus1[7]; 132 | 133 | int log2_min_luma_coding_block_size; // smallest CB size [3;6] 134 | int log2_diff_max_min_luma_coding_block_size; // largest CB size 135 | int log2_min_transform_block_size; // smallest TB size [2;5] 136 | int log2_diff_max_min_transform_block_size; // largest TB size 137 | int max_transform_hierarchy_depth_inter; 138 | int max_transform_hierarchy_depth_intra; 139 | 140 | char scaling_list_enable_flag; 141 | char sps_scaling_list_data_present_flag; /* if not set, the default scaling lists will be set 142 | in scaling_list */ 143 | 144 | struct scaling_list_data scaling_list; 145 | 146 | char amp_enabled_flag; 147 | char sample_adaptive_offset_enabled_flag; 148 | char pcm_enabled_flag; 149 | 150 | char pcm_sample_bit_depth_luma; 151 | char pcm_sample_bit_depth_chroma; 152 | int log2_min_pcm_luma_coding_block_size; 153 | int log2_diff_max_min_pcm_luma_coding_block_size; 154 | char pcm_loop_filter_disable_flag; 155 | 156 | int num_short_term_ref_pic_sets() const { return ref_pic_sets.size(); } 157 | std::vector ref_pic_sets; // [0 ; num_short_term_ref_pic_set (<=MAX_REF_PIC_SETS) ) 158 | 159 | char long_term_ref_pics_present_flag; 160 | 161 | int num_long_term_ref_pics_sps; 162 | 163 | int lt_ref_pic_poc_lsb_sps[MAX_NUM_LT_REF_PICS_SPS]; 164 | char used_by_curr_pic_lt_sps_flag[MAX_NUM_LT_REF_PICS_SPS]; 165 | 166 | char sps_temporal_mvp_enabled_flag; 167 | char strong_intra_smoothing_enable_flag; 168 | 169 | char vui_parameters_present_flag; 170 | video_usability_information vui; 171 | 172 | char sps_extension_present_flag; 173 | char sps_range_extension_flag; 174 | char sps_multilayer_extension_flag; 175 | char sps_extension_6bits; 176 | 177 | sps_range_extension range_extension; 178 | 179 | /* 180 | if( sps_extension_flag ) 181 | while( more_rbsp_data() ) 182 | sps_extension_data_flag 183 | u(1) 184 | rbsp_trailing_bits() 185 | */ 186 | 187 | 188 | // --- derived values --- 189 | 190 | de265_error compute_derived_values(bool sanitize_values = false); 191 | 192 | int BitDepth_Y; 193 | int QpBdOffset_Y; 194 | int BitDepth_C; 195 | int QpBdOffset_C; 196 | 197 | int ChromaArrayType; 198 | int SubWidthC, SubHeightC; 199 | int WinUnitX, WinUnitY; 200 | 201 | int MaxPicOrderCntLsb; 202 | 203 | int Log2MinCbSizeY; 204 | int Log2CtbSizeY; 205 | int MinCbSizeY; 206 | int CtbSizeY; 207 | int PicWidthInMinCbsY; 208 | int PicWidthInCtbsY; 209 | int PicHeightInMinCbsY; 210 | int PicHeightInCtbsY; 211 | int PicSizeInMinCbsY; 212 | int PicSizeInCtbsY; 213 | uint32_t PicSizeInSamplesY; 214 | 215 | int CtbWidthC, CtbHeightC; 216 | 217 | int PicWidthInTbsY; // not in standard 218 | int PicHeightInTbsY; // not in standard 219 | int PicSizeInTbsY; // not in standard 220 | 221 | int Log2MinTrafoSize; 222 | int Log2MaxTrafoSize; 223 | 224 | int Log2MinPUSize; 225 | int PicWidthInMinPUs; // might be rounded up 226 | int PicHeightInMinPUs; // might be rounded up 227 | 228 | int Log2MinIpcmCbSizeY; 229 | int Log2MaxIpcmCbSizeY; 230 | 231 | int SpsMaxLatencyPictures[7]; // [temporal layer] 232 | 233 | uint8_t WpOffsetBdShiftY; 234 | uint8_t WpOffsetBdShiftC; 235 | int32_t WpOffsetHalfRangeY; 236 | int32_t WpOffsetHalfRangeC; 237 | 238 | 239 | int getPUIndexRS(int pixelX,int pixelY) const { 240 | return (pixelX>>Log2MinPUSize) + (pixelY>>Log2MinPUSize)*PicWidthInMinPUs; 241 | } 242 | 243 | int get_bit_depth(int cIdx) const { 244 | if (cIdx==0) return BitDepth_Y; 245 | else return BitDepth_C; 246 | } 247 | 248 | int get_chroma_shift_W(int cIdx) const { return cIdx ? SubWidthC -1 : 0; } 249 | int get_chroma_shift_H(int cIdx) const { return cIdx ? SubHeightC-1 : 0; } 250 | }; 251 | 252 | de265_error read_scaling_list(bitreader*, const seq_parameter_set*, scaling_list_data*, bool inPPS); 253 | de265_error write_scaling_list(CABAC_encoder& out, const seq_parameter_set* sps, 254 | scaling_list_data* sclist, bool inPPS); 255 | void set_default_scaling_lists(scaling_list_data*); 256 | 257 | #endif 258 | -------------------------------------------------------------------------------- /libde265/libde265/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_THREADS_H 22 | #define DE265_THREADS_H 23 | 24 | #include "libde265/de265.h" 25 | 26 | #ifdef HAVE_CONFIG_H 27 | #include "config.h" 28 | #endif 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #ifndef _WIN32 35 | #include 36 | 37 | typedef pthread_t de265_thread; 38 | typedef pthread_mutex_t de265_mutex; 39 | typedef pthread_cond_t de265_cond; 40 | 41 | #else // _WIN32 42 | #if !defined(NOMINMAX) 43 | #define NOMINMAX 1 44 | #endif 45 | #include 46 | #include "../extra/win32cond.h" 47 | #if _MSC_VER > 1310 48 | #include 49 | #endif 50 | 51 | typedef HANDLE de265_thread; 52 | typedef HANDLE de265_mutex; 53 | typedef win32_cond_t de265_cond; 54 | #endif // _WIN32 55 | 56 | #ifndef _WIN32 57 | int de265_thread_create(de265_thread* t, void *(*start_routine) (void *), void *arg); 58 | #else 59 | int de265_thread_create(de265_thread* t, LPTHREAD_START_ROUTINE start_routine, void *arg); 60 | #endif 61 | void de265_thread_join(de265_thread t); 62 | void de265_thread_destroy(de265_thread* t); 63 | void de265_mutex_init(de265_mutex* m); 64 | void de265_mutex_destroy(de265_mutex* m); 65 | void de265_mutex_lock(de265_mutex* m); 66 | void de265_mutex_unlock(de265_mutex* m); 67 | void de265_cond_init(de265_cond* c); 68 | void de265_cond_destroy(de265_cond* c); 69 | void de265_cond_broadcast(de265_cond* c, de265_mutex* m); 70 | void de265_cond_wait(de265_cond* c,de265_mutex* m); 71 | void de265_cond_signal(de265_cond* c); 72 | 73 | 74 | class de265_progress_lock 75 | { 76 | public: 77 | de265_progress_lock(); 78 | ~de265_progress_lock(); 79 | 80 | void wait_for_progress(int progress); 81 | void set_progress(int progress); 82 | void increase_progress(int progress); 83 | int get_progress() const; 84 | void reset(int value=0) { mProgress=value; } 85 | 86 | private: 87 | int mProgress; 88 | 89 | // private data 90 | 91 | de265_mutex mutex; 92 | de265_cond cond; 93 | }; 94 | 95 | 96 | 97 | class thread_task 98 | { 99 | public: 100 | thread_task() : state(Queued) { } 101 | virtual ~thread_task() { } 102 | 103 | enum { Queued, Running, Blocked, Finished } state; 104 | 105 | virtual void work() = 0; 106 | 107 | virtual std::string name() const { return "noname"; } 108 | }; 109 | 110 | 111 | #define MAX_THREADS 32 112 | 113 | /* TODO NOTE: When unblocking a task, we have to check first 114 | if there are threads waiting because of the run-count limit. 115 | If there are higher-priority tasks, those should be run instead 116 | of the just unblocked task. 117 | */ 118 | 119 | class thread_pool 120 | { 121 | public: 122 | bool stopped; 123 | 124 | std::deque tasks; // we are not the owner 125 | 126 | de265_thread thread[MAX_THREADS]; 127 | int num_threads; 128 | 129 | int num_threads_working; 130 | 131 | int ctbx[MAX_THREADS]; // the CTB the thread is working on 132 | int ctby[MAX_THREADS]; 133 | 134 | de265_mutex mutex; 135 | de265_cond cond_var; 136 | }; 137 | 138 | 139 | de265_error start_thread_pool(thread_pool* pool, int num_threads); 140 | void stop_thread_pool(thread_pool* pool); // do not process remaining tasks 141 | 142 | void add_task(thread_pool* pool, thread_task* task); // TOCO: can make thread_task const 143 | 144 | #endif 145 | -------------------------------------------------------------------------------- /libde265/libde265/transform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_TRANSFORM_H 22 | #define DE265_TRANSFORM_H 23 | 24 | #include "libde265/de265.h" 25 | #include "libde265/decctx.h" 26 | 27 | extern const int tab8_22[]; 28 | 29 | LIBDE265_INLINE static int table8_22(int qPi) 30 | { 31 | if (qPi<30) return qPi; 32 | if (qPi>=43) return qPi-6; 33 | return tab8_22[qPi-30]; 34 | } 35 | 36 | // (8.6.1) 37 | void decode_quantization_parameters(thread_context* tctx, int xC,int yC, 38 | int xCUBase, int yCUBase); 39 | 40 | // (8.6.2) 41 | void scale_coefficients(thread_context* tctx, 42 | int xT,int yT, // position of TU in frame (chroma adapted) 43 | int x0,int y0, // position of CU in frame (chroma adapted) 44 | int nT, int cIdx, 45 | bool transform_skip_flag, bool intra, int rdpcmMode); 46 | 47 | 48 | void inv_transform(acceleration_functions* acceleration, 49 | uint8_t* dst, int dstStride, int16_t* coeff, 50 | int log2TbSize, int trType); 51 | 52 | void fwd_transform(acceleration_functions* acceleration, 53 | int16_t* coeff, int coeffStride, int log2TbSize, int trType, 54 | const int16_t* src, int srcStride); 55 | 56 | void quant_coefficients(int16_t* out_coeff, 57 | const int16_t* in_coeff, 58 | int log2TrSize, int qp, 59 | bool intra); 60 | 61 | void dequant_coefficients(int16_t* out_coeff, 62 | const int16_t* in_coeff, 63 | int log2TrSize, int qP); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /libde265/libde265/util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #include "util.h" 22 | #include "de265.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | 29 | void copy_subimage(uint8_t* dst,int dststride, 30 | const uint8_t* src,int srcstride, 31 | int w, int h) 32 | { 33 | for (int y=0;y=2; 133 | } 134 | #endif 135 | 136 | #ifdef DE265_LOG_TRACE 137 | void logtrace(enum LogModule module, const char* string, ...) 138 | { 139 | if (verbosity<3) return; 140 | if (current_poc < log_poc_start) { return; } 141 | if (disable_log[module]) return; 142 | 143 | //if (module != LogSymbols /*&& module != LogCABAC*/) { return; } 144 | //if (logcnt<319500) return; 145 | 146 | //if (module != LogCABAC) return; 147 | 148 | va_list va; 149 | 150 | if (string[0]=='$') { 151 | int id = string[1]-'0'; 152 | logcnt[id]++; 153 | fprintf(stdout, "[%ld] ",logcnt[id]); 154 | 155 | string += 3; 156 | } 157 | 158 | int noPrefix = (string[0]=='*'); 159 | if (!noPrefix) { } // fprintf(stdout, "ERR: "); 160 | va_start(va, string); 161 | vfprintf(stdout, string + (noPrefix ? 1 : 0), va); 162 | va_end(va); 163 | fflush(stdout); 164 | } 165 | #endif 166 | 167 | void log2fh(FILE* fh, const char* string, ...) 168 | { 169 | va_list va; 170 | 171 | int noPrefix = (string[0]=='*'); 172 | if (!noPrefix) fprintf(stdout, "INFO: "); 173 | va_start(va, string); 174 | vfprintf(fh, string + (noPrefix ? 1 : 0), va); 175 | va_end(va); 176 | fflush(stdout); 177 | } 178 | 179 | 180 | 181 | void printBlk(const char* title, const int16_t* data, int blksize, int stride, 182 | const std::string& prefix) 183 | { 184 | if (title) printf("%s%s:\n",prefix.c_str(),title); 185 | 186 | for (int y=0;y 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_UTIL_H 22 | #define DE265_UTIL_H 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include "config.h" 26 | #endif 27 | 28 | #ifndef _MSC_VER 29 | #include 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #include "libde265/de265.h" 36 | 37 | #ifdef __GNUC__ 38 | #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) 39 | #endif 40 | 41 | #ifdef _MSC_VER 42 | #define LIBDE265_DECLARE_ALIGNED( var, n ) __declspec(align(n)) var 43 | #define likely(x) (x) 44 | #define unlikely(x) (x) 45 | #else 46 | #define LIBDE265_DECLARE_ALIGNED( var, n ) var __attribute__((aligned(n))) 47 | #define likely(x) __builtin_expect(!!(x), 1) 48 | #define unlikely(x) __builtin_expect(!!(x), 0) 49 | #endif 50 | 51 | #if defined(__GNUC__) && (__GNUC__ >= 4) 52 | #define LIBDE265_CHECK_RESULT __attribute__ ((warn_unused_result)) 53 | #elif defined(_MSC_VER) && (_MSC_VER >= 1700) 54 | #define LIBDE265_CHECK_RESULT _Check_return_ 55 | #else 56 | #define LIBDE265_CHECK_RESULT 57 | #endif 58 | 59 | // Be careful with these alignment instructions. They only specify the alignment within 60 | // a struct. But they cannot make sure that the base address of the struct has the same alignment 61 | // when it is dynamically allocated. 62 | #define ALIGNED_32( var ) LIBDE265_DECLARE_ALIGNED( var, 32 ) 63 | #define ALIGNED_16( var ) LIBDE265_DECLARE_ALIGNED( var, 16 ) 64 | #define ALIGNED_8( var ) LIBDE265_DECLARE_ALIGNED( var, 8 ) 65 | #define ALIGNED_4( var ) LIBDE265_DECLARE_ALIGNED( var, 4 ) 66 | 67 | // C++11 specific features 68 | #if defined(_MSC_VER) || (!__clang__ && __GNUC__ && GCC_VERSION < 40600) 69 | #define FOR_LOOP(type, var, list) for each (type var in list) 70 | #undef FOR_LOOP_AUTO_SUPPORT 71 | #else 72 | #define FOR_LOOP(type, var, list) for (type var : list) 73 | #define FOR_LOOP_AUTO_SUPPORT 1 74 | #endif 75 | 76 | #ifdef USE_STD_TR1_NAMESPACE 77 | #include 78 | namespace std { using namespace std::tr1; } 79 | #endif 80 | 81 | #ifdef NEED_STD_MOVE_FALLBACK 82 | // Provide fallback variant of "std::move" for older compilers with 83 | // incomplete/broken C++11 support. 84 | namespace std { 85 | 86 | template 87 | inline typename std::remove_reference<_Tp>::type&& move(_Tp&& __t) { 88 | return static_cast::type&&>(__t); 89 | } 90 | 91 | } // namespace std 92 | #endif 93 | 94 | #ifdef NEED_NULLPTR_FALLBACK 95 | // Compilers with partial/incomplete support for C++11 don't know about 96 | // "nullptr". A simple alias should be fine for our use case. 97 | #define nullptr NULL 98 | #endif 99 | 100 | #ifdef _MSC_VER 101 | #ifdef _CPPRTTI 102 | #define RTTI_ENABLED 103 | #endif 104 | #else 105 | #ifdef __GXX_RTTI 106 | #define RTTI_ENABLED 107 | #endif 108 | #endif 109 | 110 | //inline uint8_t Clip1_8bit(int16_t value) { if (value<=0) return 0; else if (value>=255) return 255; else return value; } 111 | #define Clip1_8bit(value) ((value)<0 ? 0 : (value)>255 ? 255 : (value)) 112 | #define Clip_BitDepth(value, bit_depth) ((value)<0 ? 0 : (value)>((1<(high) ? (high) : (value)) 114 | #define Sign(value) (((value)<0) ? -1 : ((value)>0) ? 1 : 0) 115 | #define abs_value(a) (((a)<0) ? -(a) : (a)) 116 | #define libde265_min(a,b) (((a)<(b)) ? (a) : (b)) 117 | #define libde265_max(a,b) (((a)>(b)) ? (a) : (b)) 118 | 119 | LIBDE265_INLINE static int ceil_div(int num,int denom) 120 | { 121 | num += denom-1; 122 | return num/denom; 123 | } 124 | 125 | LIBDE265_INLINE static int ceil_log2(int val) 126 | { 127 | int n=0; 128 | while (val > (1<1) { 139 | n++; 140 | v>>=1; 141 | } 142 | 143 | return n; 144 | } 145 | 146 | LIBDE265_INLINE static int Log2SizeToArea(int v) 147 | { 148 | return (1<<(v<<1)); 149 | } 150 | 151 | void copy_subimage(uint8_t* dst,int dststride, 152 | const uint8_t* src,int srcstride, 153 | int w, int h); 154 | 155 | 156 | // === logging === 157 | 158 | enum LogModule { 159 | LogHighlevel, 160 | LogHeaders, 161 | LogSlice, 162 | LogDPB, 163 | LogMotion, 164 | LogTransform, 165 | LogDeblock, 166 | LogSAO, 167 | LogSEI, 168 | LogIntraPred, 169 | LogPixels, 170 | LogSymbols, 171 | LogCABAC, 172 | LogEncoder, 173 | LogEncoderMetadata, 174 | NUMBER_OF_LogModules 175 | }; 176 | 177 | 178 | #if defined(DE265_LOG_ERROR) || defined(DE265_LOG_INFO) || defined(DE265_LOG_DEBUG) || defined(DE265_LOG_TRACE) 179 | # define DE265_LOGGING 1 180 | void enable_logging(enum LogModule); 181 | void disable_logging(enum LogModule); 182 | #else 183 | #define enable_logging(x) { } 184 | #define disable_logging(x) { } 185 | #endif 186 | 187 | #ifdef DE265_LOGGING 188 | void log_set_current_POC(int poc); 189 | #else 190 | #define log_set_current_POC(poc) { } 191 | #endif 192 | 193 | #ifdef DE265_LOG_ERROR 194 | void logerror(enum LogModule module, const char* string, ...); 195 | #else 196 | #define logerror(a,b, ...) { } 197 | #endif 198 | 199 | #ifdef DE265_LOG_INFO 200 | void loginfo (enum LogModule module, const char* string, ...); 201 | #else 202 | #define loginfo(a,b, ...) { } 203 | #endif 204 | 205 | #ifdef DE265_LOG_DEBUG 206 | void logdebug(enum LogModule module, const char* string, ...); 207 | bool logdebug_enabled(enum LogModule module); 208 | #else 209 | #define logdebug(a,b, ...) { } 210 | inline bool logdebug_enabled(enum LogModule module) { return false; } 211 | #endif 212 | 213 | #ifdef DE265_LOG_TRACE 214 | void logtrace(enum LogModule module, const char* string, ...); 215 | #else 216 | #define logtrace(a,b, ...) { } 217 | #endif 218 | 219 | void log2fh(FILE* fh, const char* string, ...); 220 | 221 | 222 | void printBlk(const char* title,const int32_t* data, int blksize, int stride, const std::string& prefix=" "); 223 | void printBlk(const char* title,const int16_t* data, int blksize, int stride, const std::string& prefix=" "); 224 | void printBlk(const char* title,const uint8_t* data, int blksize, int stride, const std::string& prefix=" "); 225 | 226 | void debug_set_image_output(void (*)(const struct de265_image*, int slot)); 227 | void debug_show_image(const struct de265_image*, int slot); 228 | 229 | #endif 230 | -------------------------------------------------------------------------------- /libde265/libde265/vendorkeep.go: -------------------------------------------------------------------------------- 1 | //go:build vendorkeep 2 | // +build vendorkeep 3 | 4 | package cgowrapper 5 | -------------------------------------------------------------------------------- /libde265/libde265/visualize.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_VISUALIZE_H 22 | #define DE265_VISUALIZE_H 23 | 24 | #include "libde265/de265.h" 25 | #include "libde265/image.h" 26 | 27 | 28 | void write_picture_to_file(const de265_image* img, const char* filename); 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | // TODO: these should either move to "sherlock265", or be part of the 35 | // "official" public API 36 | LIBDE265_API void draw_CB_grid(const de265_image* img, uint8_t* dst, int stride, uint32_t value, int pixelSize); 37 | LIBDE265_API void draw_TB_grid(const de265_image* img, uint8_t* dst, int stride, uint32_t value, int pixelSize); 38 | LIBDE265_API void draw_PB_grid(const de265_image* img, uint8_t* dst, int stride, uint32_t value, int pixelSize); 39 | LIBDE265_API void draw_PB_pred_modes(const de265_image* img, uint8_t* dst, int stride, int pixelSize); 40 | LIBDE265_API void draw_intra_pred_modes(const de265_image* img, uint8_t* dst, int stride, uint32_t value, int pixelSize); 41 | LIBDE265_API void draw_QuantPY(const de265_image* img, uint8_t* dst, int stride, int pixelSize); 42 | LIBDE265_API void draw_Motion(const de265_image* img, uint8_t* dst, int stride, int pixelSize); 43 | LIBDE265_API void draw_Slices(const de265_image* img, uint8_t* dst, int stride, int pixelSize); 44 | LIBDE265_API void draw_Tiles(const de265_image* img, uint8_t* dst, int stride, int pixelSize); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libde265/libde265/vps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_VPS_H 22 | #define DE265_VPS_H 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include "libde265/bitstream.h" 29 | #include "libde265/de265.h" 30 | #include "libde265/cabac.h" 31 | 32 | #include 33 | 34 | class error_queue; 35 | 36 | #define MAX_TEMPORAL_SUBLAYERS 8 37 | 38 | 39 | enum profile_idc { 40 | Profile_Main = 1, 41 | Profile_Main10 = 2, 42 | Profile_MainStillPicture = 3, 43 | Profile_FormatRangeExtensions = 4 44 | }; 45 | 46 | 47 | class profile_data { 48 | public: 49 | void read(bitreader* reader); 50 | void write(CABAC_encoder& writer) const; 51 | void dump(bool general, FILE* fh) const; 52 | 53 | void set_defaults(enum profile_idc, int level_major, int level_minor); 54 | 55 | // --- profile --- 56 | 57 | char profile_present_flag; // always true for general profile 58 | 59 | char profile_space; // currently always 0 60 | char tier_flag; // main tier or low tier (see Table A-66/A-67) 61 | enum profile_idc profile_idc; // profile 62 | 63 | char profile_compatibility_flag[32]; // to which profile we are compatible 64 | 65 | char progressive_source_flag; 66 | char interlaced_source_flag; 67 | char non_packed_constraint_flag; 68 | char frame_only_constraint_flag; 69 | 70 | 71 | // --- level --- 72 | 73 | char level_present_flag; // always true for general level 74 | int level_idc; // level * 30 75 | }; 76 | 77 | 78 | class profile_tier_level 79 | { 80 | public: 81 | void read(bitreader* reader, int max_sub_layers); 82 | void write(CABAC_encoder& writer, int max_sub_layers) const; 83 | void dump(int max_sub_layers, FILE* fh) const; 84 | 85 | profile_data general; 86 | 87 | //bool sub_layer_profile_present[MAX_TEMPORAL_SUBLAYERS]; 88 | //bool sub_layer_level_present[MAX_TEMPORAL_SUBLAYERS]; 89 | 90 | profile_data sub_layer[MAX_TEMPORAL_SUBLAYERS]; 91 | }; 92 | 93 | 94 | /* 95 | struct bit_rate_pic_rate_info { 96 | char bit_rate_info_present_flag[8]; 97 | char pic_rate_info_present_flag[8]; 98 | 99 | int avg_bit_rate[8]; 100 | int max_bit_rate[8]; 101 | 102 | char constant_pic_rate_idc[8]; 103 | int avg_pic_rate[8]; 104 | 105 | }; 106 | 107 | void read_bit_rate_pic_rate_info(bitreader* reader, 108 | struct bit_rate_pic_rate_info* hdr, 109 | int TempLevelLow, 110 | int TempLevelHigh); 111 | 112 | void dump_bit_rate_pic_rate_info(struct bit_rate_pic_rate_info* hdr, 113 | int TempLevelLow, 114 | int TempLevelHigh); 115 | */ 116 | 117 | 118 | typedef struct { 119 | int vps_max_dec_pic_buffering; // [1 ; ] 120 | int vps_max_num_reorder_pics; // [0 ; ] 121 | int vps_max_latency_increase; // 0 -> no limit, otherwise value is (x-1) 122 | } layer_data; 123 | 124 | 125 | class video_parameter_set 126 | { 127 | public: 128 | de265_error read(error_queue* errqueue, bitreader* reader); 129 | de265_error write(error_queue* errqueue, CABAC_encoder& out) const; 130 | void dump(int fd) const; 131 | 132 | void set_defaults(enum profile_idc profile, int level_major, int level_minor); 133 | 134 | int video_parameter_set_id; 135 | int vps_max_layers; // [1;?] currently always 1 136 | int vps_max_sub_layers; // [1;7] number of temporal sub-layers 137 | int vps_temporal_id_nesting_flag; // indicate temporal up-switching always possible 138 | profile_tier_level profile_tier_level_; 139 | 140 | int vps_sub_layer_ordering_info_present_flag; 141 | layer_data layer[MAX_TEMPORAL_SUBLAYERS]; 142 | 143 | uint8_t vps_max_layer_id; // max value for nuh_layer_id in NALs 144 | int vps_num_layer_sets; // [1;1024], currently always 1 145 | 146 | std::vector > layer_id_included_flag; // max size = [1024][64] 147 | 148 | 149 | // --- timing info --- 150 | 151 | char vps_timing_info_present_flag; 152 | uint32_t vps_num_units_in_tick; 153 | uint32_t vps_time_scale; 154 | char vps_poc_proportional_to_timing_flag; 155 | uint32_t vps_num_ticks_poc_diff_one; 156 | 157 | int vps_num_hrd_parameters; // currently [0;1] 158 | 159 | std::vector hrd_layer_set_idx; // max size = 1024 160 | std::vector cprms_present_flag; // max size = 1024 161 | 162 | 163 | // --- vps extension --- 164 | 165 | char vps_extension_flag; 166 | }; 167 | 168 | 169 | #endif 170 | -------------------------------------------------------------------------------- /libde265/libde265/vui.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_VUI_H 22 | #define DE265_VUI_H 23 | 24 | #include "libde265/de265.h" 25 | #include "libde265/bitstream.h" 26 | 27 | #include 28 | 29 | class error_queue; 30 | class seq_parameter_set; 31 | 32 | 33 | enum VideoFormat { 34 | VideoFormat_Component = 0, 35 | VideoFormat_PAL = 1, 36 | VideoFormat_NTSC = 2, 37 | VideoFormat_SECAM = 3, 38 | VideoFormat_MAC = 4, 39 | VideoFormat_Unspecified = 5 40 | }; 41 | 42 | const char* get_video_format_name(enum VideoFormat); 43 | 44 | 45 | class video_usability_information 46 | { 47 | public: 48 | video_usability_information(); 49 | 50 | de265_error hrd_parameters(error_queue*, bitreader*, const seq_parameter_set*); 51 | de265_error read(error_queue*, bitreader*, const seq_parameter_set*); 52 | void dump(int fd) const; 53 | 54 | 55 | // --- sample aspect ratio (SAR) --- 56 | 57 | bool aspect_ratio_info_present_flag; 58 | uint16_t sar_width; // sar_width and sar_height are zero if unspecified 59 | uint16_t sar_height; 60 | 61 | 62 | // --- overscan --- 63 | 64 | bool overscan_info_present_flag; 65 | bool overscan_appropriate_flag; 66 | 67 | 68 | // --- video signal type --- 69 | 70 | bool video_signal_type_present_flag; 71 | enum VideoFormat video_format; 72 | bool video_full_range_flag; 73 | bool colour_description_present_flag; 74 | uint8_t colour_primaries; 75 | uint8_t transfer_characteristics; 76 | uint8_t matrix_coeffs; 77 | 78 | // --- chroma / interlaced --- 79 | 80 | bool chroma_loc_info_present_flag; 81 | uint8_t chroma_sample_loc_type_top_field; 82 | uint8_t chroma_sample_loc_type_bottom_field; 83 | 84 | bool neutral_chroma_indication_flag; 85 | bool field_seq_flag; 86 | bool frame_field_info_present_flag; 87 | 88 | // --- default display window --- 89 | 90 | bool default_display_window_flag; 91 | uint32_t def_disp_win_left_offset; 92 | uint32_t def_disp_win_right_offset; 93 | uint32_t def_disp_win_top_offset; 94 | uint32_t def_disp_win_bottom_offset; 95 | 96 | 97 | // --- timing --- 98 | 99 | bool vui_timing_info_present_flag; 100 | uint32_t vui_num_units_in_tick; 101 | uint32_t vui_time_scale; 102 | 103 | bool vui_poc_proportional_to_timing_flag; 104 | uint32_t vui_num_ticks_poc_diff_one; 105 | 106 | 107 | // --- hrd parameters --- 108 | 109 | bool vui_hrd_parameters_present_flag; 110 | bool nal_hrd_parameters_present_flag; 111 | bool vcl_hrd_parameters_present_flag; 112 | bool sub_pic_hrd_params_present_flag; 113 | uint32_t tick_divisor_minus2; 114 | uint32_t du_cpb_removal_delay_increment_length_minus1; 115 | bool sub_pic_cpb_params_in_pic_timing_sei_flag; 116 | uint32_t dpb_output_delay_du_length_minus1; 117 | uint32_t bit_rate_scale; 118 | uint32_t cpb_size_scale; 119 | uint32_t cpb_size_du_scale; 120 | uint32_t initial_cpb_removal_delay_length_minus1; 121 | uint32_t au_cpb_removal_delay_length_minus1; 122 | uint32_t dpb_output_delay_length_minus1; 123 | bool fixed_pic_rate_general_flag[7]; 124 | bool fixed_pic_rate_within_cvs_flag[7]; 125 | bool low_delay_hrd_flag[7]; 126 | uint32_t cpb_cnt_minus1[7]; 127 | uint32_t elemental_duration_in_tc_minus1[7]; 128 | uint32_t bit_rate_value_minus1[7][32][2]; 129 | uint32_t cpb_size_value_minus1[7][32][2]; 130 | uint32_t cpb_size_du_value_minus1[7][32][2]; 131 | uint32_t bit_rate_du_value_minus1[7][32][2]; 132 | bool cbr_flag[7][32][2]; 133 | 134 | // --- bitstream restriction --- 135 | 136 | bool bitstream_restriction_flag; 137 | bool tiles_fixed_structure_flag; 138 | bool motion_vectors_over_pic_boundaries_flag; 139 | bool restricted_ref_pic_lists_flag; 140 | uint16_t min_spatial_segmentation_idc; 141 | uint8_t max_bytes_per_pic_denom; 142 | uint8_t max_bits_per_min_cu_denom; 143 | uint8_t log2_max_mv_length_horizontal; 144 | uint8_t log2_max_mv_length_vertical; 145 | }; 146 | 147 | 148 | #endif 149 | -------------------------------------------------------------------------------- /libde265/libde265/x86/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set (x86_sources 2 | sse.cc sse.h 3 | ) 4 | 5 | set (x86_sse_sources 6 | sse-motion.cc sse-motion.h sse-dct.h sse-dct.cc 7 | ) 8 | 9 | add_library(x86 OBJECT ${x86_sources}) 10 | 11 | add_library(x86_sse OBJECT ${x86_sse_sources}) 12 | 13 | set(sse_flags "") 14 | 15 | if(NOT MSVC) 16 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 17 | set(sse_flags "${sse_flags} -msse4.1") 18 | else(CMAKE_SIZEOF_VOID_P EQUAL 8) 19 | set(sse_flags "${sse_flags} -msse2 -mssse3 -msse4.1") 20 | endif(CMAKE_SIZEOF_VOID_P EQUAL 8) 21 | endif() 22 | 23 | set(X86_OBJECTS $ $ PARENT_SCOPE) 24 | 25 | SET_TARGET_PROPERTIES(x86_sse PROPERTIES COMPILE_FLAGS "${sse_flags}") 26 | -------------------------------------------------------------------------------- /libde265/libde265/x86/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_LTLIBRARIES = libde265_x86.la libde265_x86_sse.la 2 | 3 | libde265_x86_la_CXXFLAGS = -I$(top_srcdir)/libde265 $(CFLAG_VISIBILITY) 4 | libde265_x86_la_SOURCES = sse.cc sse.h 5 | libde265_x86_la_LIBADD = libde265_x86_sse.la 6 | 7 | if HAVE_VISIBILITY 8 | libde265_x86_la_CXXFLAGS += -DHAVE_VISIBILITY 9 | endif 10 | 11 | 12 | # SSE4 specific functions 13 | 14 | libde265_x86_sse_la_CXXFLAGS = -msse4.1 -I$(top_srcdir) -I$(top_srcdir)/libde265 $(CFLAG_VISIBILITY) 15 | libde265_x86_sse_la_SOURCES = sse-motion.cc sse-motion.h sse-dct.h sse-dct.cc 16 | 17 | if HAVE_VISIBILITY 18 | libde265_x86_sse_la_CXXFLAGS += -DHAVE_VISIBILITY 19 | endif 20 | 21 | EXTRA_DIST = \ 22 | CMakeLists.txt 23 | -------------------------------------------------------------------------------- /libde265/libde265/x86/sse-dct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013 openHEVC contributors 4 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 5 | * 6 | * This file is part of libde265. 7 | * 8 | * libde265 is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * libde265 is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with libde265. If not, see . 20 | */ 21 | 22 | #ifndef SSE_DCT_H 23 | #define SSE_DCT_H 24 | 25 | #include 26 | #include 27 | 28 | void ff_hevc_transform_skip_8_sse(uint8_t *_dst, const int16_t *coeffs, ptrdiff_t _stride); 29 | void ff_hevc_transform_4x4_luma_add_8_sse4(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 30 | void ff_hevc_transform_4x4_add_8_sse4(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 31 | void ff_hevc_transform_8x8_add_8_sse4(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 32 | void ff_hevc_transform_16x16_add_8_sse4(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 33 | void ff_hevc_transform_32x32_add_8_sse4(uint8_t *dst, const int16_t *coeffs, ptrdiff_t stride); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /libde265/libde265/x86/sse-motion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013 openHEVC contributors 4 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 5 | * 6 | * This file is part of libde265. 7 | * 8 | * libde265 is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as 10 | * published by the Free Software Foundation, either version 3 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * libde265 is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with libde265. If not, see . 20 | */ 21 | 22 | #ifndef SSE_MOTION_H 23 | #define SSE_MOTION_H 24 | 25 | #include 26 | #include 27 | 28 | 29 | void ff_hevc_put_unweighted_pred_8_sse(uint8_t *_dst, ptrdiff_t dststride, 30 | const int16_t *src, ptrdiff_t srcstride, 31 | int width, int height); 32 | 33 | void ff_hevc_put_weighted_pred_avg_8_sse(uint8_t *_dst, ptrdiff_t dststride, 34 | const int16_t *src1, const int16_t *src2, 35 | ptrdiff_t srcstride, int width, 36 | int height); 37 | 38 | void ff_hevc_put_hevc_epel_pixels_8_sse(int16_t *dst, ptrdiff_t dststride, 39 | const uint8_t *_src, ptrdiff_t srcstride, 40 | int width, int height, 41 | int mx, int my, int16_t* mcbuffer); 42 | void ff_hevc_put_hevc_epel_h_8_sse(int16_t *dst, ptrdiff_t dststride, 43 | const uint8_t *_src, ptrdiff_t srcstride, 44 | int width, int height, 45 | int mx, int my, int16_t* mcbuffer, int bit_depth); 46 | void ff_hevc_put_hevc_epel_v_8_sse(int16_t *dst, ptrdiff_t dststride, 47 | const uint8_t *_src, ptrdiff_t srcstride, 48 | int width, int height, 49 | int mx, int my, int16_t* mcbuffer, int bit_depth); 50 | void ff_hevc_put_hevc_epel_hv_8_sse(int16_t *dst, ptrdiff_t dststride, 51 | const uint8_t *_src, ptrdiff_t srcstride, 52 | int width, int height, 53 | int mx, int my, int16_t* mcbuffer, int bit_depth); 54 | 55 | void ff_hevc_put_hevc_qpel_pixels_8_sse(int16_t *dst, ptrdiff_t dststride, 56 | const uint8_t *src, ptrdiff_t srcstride, 57 | int width, int height, int16_t* mcbuffer); 58 | void ff_hevc_put_hevc_qpel_v_1_8_sse(int16_t *dst, ptrdiff_t dststride, 59 | const uint8_t *src, ptrdiff_t srcstride, 60 | int width, int height, int16_t* mcbuffer); 61 | void ff_hevc_put_hevc_qpel_v_2_8_sse(int16_t *dst, ptrdiff_t dststride, 62 | const uint8_t *src, ptrdiff_t srcstride, 63 | int width, int height, int16_t* mcbuffer); 64 | void ff_hevc_put_hevc_qpel_v_3_8_sse(int16_t *dst, ptrdiff_t dststride, 65 | const uint8_t *src, ptrdiff_t srcstride, 66 | int width, int height, int16_t* mcbuffer); 67 | void ff_hevc_put_hevc_qpel_h_1_8_sse(int16_t *dst, ptrdiff_t dststride, 68 | const uint8_t *src, ptrdiff_t srcstride, 69 | int width, int height, int16_t* mcbuffer); 70 | void ff_hevc_put_hevc_qpel_h_1_v_1_sse(int16_t *dst, ptrdiff_t dststride, 71 | const uint8_t *src, ptrdiff_t srcstride, 72 | int width, int height, int16_t* mcbuffer); 73 | void ff_hevc_put_hevc_qpel_h_1_v_2_sse(int16_t *dst, ptrdiff_t dststride, 74 | const uint8_t *src, ptrdiff_t srcstride, 75 | int width, int height, int16_t* mcbuffer); 76 | void ff_hevc_put_hevc_qpel_h_1_v_3_sse(int16_t *dst, ptrdiff_t dststride, 77 | const uint8_t *src, ptrdiff_t srcstride, 78 | int width, int height, int16_t* mcbuffer); 79 | void ff_hevc_put_hevc_qpel_h_2_8_sse(int16_t *dst, ptrdiff_t dststride, 80 | const uint8_t *src, ptrdiff_t srcstride, 81 | int width, int height, int16_t* mcbuffer); 82 | void ff_hevc_put_hevc_qpel_h_2_v_1_sse(int16_t *dst, ptrdiff_t dststride, 83 | const uint8_t *src, ptrdiff_t srcstride, 84 | int width, int height, int16_t* mcbuffer); 85 | void ff_hevc_put_hevc_qpel_h_2_v_2_sse(int16_t *dst, ptrdiff_t dststride, 86 | const uint8_t *src, ptrdiff_t srcstride, 87 | int width, int height, int16_t* mcbuffer); 88 | void ff_hevc_put_hevc_qpel_h_2_v_3_sse(int16_t *dst, ptrdiff_t dststride, 89 | const uint8_t *src, ptrdiff_t srcstride, 90 | int width, int height, int16_t* mcbuffer); 91 | void ff_hevc_put_hevc_qpel_h_3_8_sse(int16_t *dst, ptrdiff_t dststride, 92 | const uint8_t *src, ptrdiff_t srcstride, 93 | int width, int height, int16_t* mcbuffer); 94 | void ff_hevc_put_hevc_qpel_h_3_v_1_sse(int16_t *dst, ptrdiff_t dststride, 95 | const uint8_t *src, ptrdiff_t srcstride, 96 | int width, int height, int16_t* mcbuffer); 97 | void ff_hevc_put_hevc_qpel_h_3_v_2_sse(int16_t *dst, ptrdiff_t dststride, 98 | const uint8_t *src, ptrdiff_t srcstride, 99 | int width, int height, int16_t* mcbuffer); 100 | void ff_hevc_put_hevc_qpel_h_3_v_3_sse(int16_t *dst, ptrdiff_t dststride, 101 | const uint8_t *src, ptrdiff_t srcstride, 102 | int width, int height, int16_t* mcbuffer); 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /libde265/libde265/x86/sse.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifdef _MSC_VER 22 | #include 23 | #endif 24 | 25 | #include "x86/sse.h" 26 | #include "x86/sse-motion.h" 27 | #include "x86/sse-dct.h" 28 | 29 | #ifdef HAVE_CONFIG_H 30 | #include "config.h" 31 | #endif 32 | 33 | #ifdef __GNUC__ 34 | #include 35 | #endif 36 | 37 | void init_acceleration_functions_sse(struct acceleration_functions* accel) 38 | { 39 | uint32_t ecx=0,edx=0; 40 | 41 | #ifdef _MSC_VER 42 | uint32_t regs[4]; 43 | int a = 1; 44 | 45 | __cpuid((int *)regs, (int)a); 46 | 47 | ecx = regs[2]; 48 | edx = regs[3]; 49 | #else 50 | uint32_t eax,ebx; 51 | __get_cpuid(1, &eax,&ebx,&ecx,&edx); 52 | #endif 53 | 54 | // printf("CPUID EAX=1 -> ECX=%x EDX=%x\n", regs[2], regs[3]); 55 | 56 | //int have_MMX = !!(edx & (1<<23)); 57 | int have_SSE = !!(edx & (1<<25)); 58 | int have_SSE4_1 = !!(ecx & (1<<19)); 59 | 60 | // printf("MMX:%d SSE:%d SSE4_1:%d\n",have_MMX,have_SSE,have_SSE4_1); 61 | 62 | if (have_SSE) { 63 | } 64 | 65 | #if HAVE_SSE4_1 66 | if (have_SSE4_1) { 67 | accel->put_unweighted_pred_8 = ff_hevc_put_unweighted_pred_8_sse; 68 | accel->put_weighted_pred_avg_8 = ff_hevc_put_weighted_pred_avg_8_sse; 69 | 70 | accel->put_hevc_epel_8 = ff_hevc_put_hevc_epel_pixels_8_sse; 71 | accel->put_hevc_epel_h_8 = ff_hevc_put_hevc_epel_h_8_sse; 72 | accel->put_hevc_epel_v_8 = ff_hevc_put_hevc_epel_v_8_sse; 73 | accel->put_hevc_epel_hv_8 = ff_hevc_put_hevc_epel_hv_8_sse; 74 | 75 | accel->put_hevc_qpel_8[0][0] = ff_hevc_put_hevc_qpel_pixels_8_sse; 76 | accel->put_hevc_qpel_8[0][1] = ff_hevc_put_hevc_qpel_v_1_8_sse; 77 | accel->put_hevc_qpel_8[0][2] = ff_hevc_put_hevc_qpel_v_2_8_sse; 78 | accel->put_hevc_qpel_8[0][3] = ff_hevc_put_hevc_qpel_v_3_8_sse; 79 | accel->put_hevc_qpel_8[1][0] = ff_hevc_put_hevc_qpel_h_1_8_sse; 80 | accel->put_hevc_qpel_8[1][1] = ff_hevc_put_hevc_qpel_h_1_v_1_sse; 81 | accel->put_hevc_qpel_8[1][2] = ff_hevc_put_hevc_qpel_h_1_v_2_sse; 82 | accel->put_hevc_qpel_8[1][3] = ff_hevc_put_hevc_qpel_h_1_v_3_sse; 83 | accel->put_hevc_qpel_8[2][0] = ff_hevc_put_hevc_qpel_h_2_8_sse; 84 | accel->put_hevc_qpel_8[2][1] = ff_hevc_put_hevc_qpel_h_2_v_1_sse; 85 | accel->put_hevc_qpel_8[2][2] = ff_hevc_put_hevc_qpel_h_2_v_2_sse; 86 | accel->put_hevc_qpel_8[2][3] = ff_hevc_put_hevc_qpel_h_2_v_3_sse; 87 | accel->put_hevc_qpel_8[3][0] = ff_hevc_put_hevc_qpel_h_3_8_sse; 88 | accel->put_hevc_qpel_8[3][1] = ff_hevc_put_hevc_qpel_h_3_v_1_sse; 89 | accel->put_hevc_qpel_8[3][2] = ff_hevc_put_hevc_qpel_h_3_v_2_sse; 90 | accel->put_hevc_qpel_8[3][3] = ff_hevc_put_hevc_qpel_h_3_v_3_sse; 91 | 92 | accel->transform_skip_8 = ff_hevc_transform_skip_8_sse; 93 | 94 | // actually, for these two functions, the scalar fallback seems to be faster than the SSE code 95 | //accel->transform_4x4_luma_add_8 = ff_hevc_transform_4x4_luma_add_8_sse4; // SSE-4 only TODO 96 | //accel->transform_4x4_add_8 = ff_hevc_transform_4x4_add_8_sse4; 97 | 98 | accel->transform_add_8[1] = ff_hevc_transform_8x8_add_8_sse4; 99 | accel->transform_add_8[2] = ff_hevc_transform_16x16_add_8_sse4; 100 | accel->transform_add_8[3] = ff_hevc_transform_32x32_add_8_sse4; 101 | } 102 | #endif 103 | } 104 | 105 | -------------------------------------------------------------------------------- /libde265/libde265/x86/sse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * H.265 video codec. 3 | * Copyright (c) 2013-2014 struktur AG, Dirk Farin 4 | * 5 | * This file is part of libde265. 6 | * 7 | * libde265 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation, either version 3 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * libde265 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with libde265. If not, see . 19 | */ 20 | 21 | #ifndef DE265_SSE_H 22 | #define DE265_SSE_H 23 | 24 | #include "acceleration.h" 25 | 26 | void init_acceleration_functions_sse(struct acceleration_functions* accel); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /libde265/libde265/x86/vendorkeep.go: -------------------------------------------------------------------------------- 1 | //go:build vendorkeep 2 | // +build vendorkeep 3 | 4 | package cgowrapper 5 | -------------------------------------------------------------------------------- /testdata/camel.heic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jdeng/goheif/0b111b5c3adb32c9d0c76c60c58d5787782edb22/testdata/camel.heic --------------------------------------------------------------------------------