Skip to content

Commit

Permalink
add custome raw
Browse files Browse the repository at this point in the history
  • Loading branch information
fierceX committed Apr 2, 2024
1 parent a90f303 commit a720468
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/scanner/media_encoding/encode_photo.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ func (img *EncodeMediaData) EncodeHighRes(outputPath string) error {

// Use darktable if there is no counterpart JPEG file to use instead
if contentType.IsRaw() && img.CounterpartPath == nil {
if executable_worker.DarktableCli.IsInstalled() {
if executable_worker.CustomRawCli.IsInstalled() {
err := executable_worker.CustomRawCli.EncodeJpeg(img.Media.Path, outputPath, 70)
if err != nil {
return err

Check warning on line 116 in api/scanner/media_encoding/encode_photo.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/encode_photo.go#L113-L116

Added lines #L113 - L116 were not covered by tests
}

}else if executable_worker.DarktableCli.IsInstalled() {

Check warning on line 119 in api/scanner/media_encoding/encode_photo.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/encode_photo.go#L119

Added line #L119 was not covered by tests
err := executable_worker.DarktableCli.EncodeJpeg(img.Media.Path, outputPath, 70)
if err != nil {
return err
Expand Down
50 changes: 50 additions & 0 deletions api/scanner/media_encoding/executable_worker/executable_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ import (
)

func InitializeExecutableWorkers() {
CustomRawCli = newCustomRawWorker()

Check warning on line 17 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L17

Added line #L17 was not covered by tests
DarktableCli = newDarktableWorker()
FfmpegCli = newFfmpegWorker()
}

var CustomRawCli *CustomRawWorker = nil
var DarktableCli *DarktableWorker = nil
var FfmpegCli *FfmpegWorker = nil

type CustomRawWorker struct {
path string
}

type ExecutableWorker interface {
Path() string
}
Expand All @@ -33,6 +39,22 @@ type FfmpegWorker struct {
path string
}

func newCustomRawWorker() *CustomRawWorker {
if utils.EnvDisableRawProcessing.GetBool() {
log.Printf("Executable worker disabled (%s=1)\n", utils.EnvDisableRawProcessing.GetName())
return nil

Check warning on line 45 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L43-L45

Added lines #L43 - L45 were not covered by tests
}

var path = utils.EnvCustomRawProcessing.GetValue()

Check warning on line 48 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L48

Added line #L48 was not covered by tests

if path != "" {
return &CustomRawWorker{
path:path,

Check warning on line 52 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L50-L52

Added lines #L50 - L52 were not covered by tests
}
}
return nil

Check warning on line 55 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L55

Added line #L55 was not covered by tests
}

func newDarktableWorker() *DarktableWorker {
if utils.EnvDisableRawProcessing.GetBool() {
log.Printf("Executable worker disabled (%s=1): darktable\n", utils.EnvDisableRawProcessing.GetName())
Expand Down Expand Up @@ -85,6 +107,10 @@ func newFfmpegWorker() *FfmpegWorker {
return nil
}

func (worker *CustomRawWorker) IsInstalled() bool {
return worker != nil

Check warning on line 111 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L111

Added line #L111 was not covered by tests
}

func (worker *DarktableWorker) IsInstalled() bool {
return worker != nil
}
Expand All @@ -93,6 +119,30 @@ func (worker *FfmpegWorker) IsInstalled() bool {
return worker != nil
}

func (worker *CustomRawWorker) EncodeJpeg(inputPath string, outputPath string, jpegQuality int) error {
tmpDir, err := ioutil.TempDir("/tmp", "photoview-convert")
if err != nil {
log.Fatal(err)

Check warning on line 125 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L123-L125

Added lines #L123 - L125 were not covered by tests
}
defer os.RemoveAll(tmpDir)

Check warning on line 127 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L127

Added line #L127 was not covered by tests

args := []string{
worker.path,
inputPath,
outputPath,
fmt.Sprintf("%d", jpegQuality),

Check warning on line 133 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L129-L133

Added lines #L129 - L133 were not covered by tests
}


cmd := exec.Command("sh", args...)

Check warning on line 137 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L137

Added line #L137 was not covered by tests

if err := cmd.Run(); err != nil {
return errors.Wrapf(err, "encoding image using: %s %v", worker.path, args)

Check warning on line 140 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L139-L140

Added lines #L139 - L140 were not covered by tests
}

return nil

Check warning on line 143 in api/scanner/media_encoding/executable_worker/executable_worker.go

View check run for this annotation

Codecov / codecov/patch

api/scanner/media_encoding/executable_worker/executable_worker.go#L143

Added line #L143 was not covered by tests
}

func (worker *DarktableWorker) EncodeJpeg(inputPath string, outputPath string, jpegQuality int) error {
tmpDir, err := ioutil.TempDir("/tmp", "photoview-darktable")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions api/utils/environment_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
EnvDisableFaceRecognition EnvironmentVariable = "PHOTOVIEW_DISABLE_FACE_RECOGNITION"
EnvDisableVideoEncoding EnvironmentVariable = "PHOTOVIEW_DISABLE_VIDEO_ENCODING"
EnvDisableRawProcessing EnvironmentVariable = "PHOTOVIEW_DISABLE_RAW_PROCESSING"
EnvCustomRawProcessing EnvironmentVariable = "PHOTOVIEW_CUSTOM_RAW_PROCESSING"
)

// GetName returns the name of the environment variable itself
Expand Down

0 comments on commit a720468

Please sign in to comment.