Created
July 13, 2021 13:22
-
-
Save tbonfort/1e8630cf4b9bc82471c164e422c1cce7 to your computer and use it in GitHub Desktop.
cogger c wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "C" | |
import ( | |
"fmt" | |
"os" | |
"unsafe" | |
"github.com/airbusgeo/cogger" | |
"github.com/google/tiff" | |
) | |
//export cogify | |
func cogify(out *C.char, in **C.char, nin C.int) C.int { | |
infiles := (*[1 << 28]unsafe.Pointer)(unsafe.Pointer(in))[:nin:nin] | |
readers := make([]tiff.ReadAtReadSeeker, len(infiles)) | |
output := C.GoString(out) | |
for i, cinput := range infiles { | |
input := C.GoString((*C.char)(cinput)) | |
topFile, err := os.Open(input) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "open %s: %v", input, err) | |
return 1 | |
} | |
defer topFile.Close() | |
readers[i] = topFile | |
} | |
outf, err := os.Create(output) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "create %s: %v", output, err) | |
return 1 | |
} | |
err = cogger.Rewrite(outf, readers...) | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "mucog write: %v", err) | |
return 1 | |
} | |
err = outf.Close() | |
if err != nil { | |
fmt.Fprintf(os.Stderr, "close %s: %v", output, err) | |
return 1 | |
} | |
return 0 | |
} | |
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern int cogify(char* out, char** in, int nin); | |
int main(int argc, char **argv) { | |
char *infiles[] = { | |
"../testdata/exttest.tif", | |
"../testdata/exttest.tif.2", | |
}; | |
cogify("output.tif", infiles,2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
build: | |
go build -o cogify.so -buildmode=c-shared . | |
gcc -o main main.c cogify.so | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment