Skip to content

Commit

Permalink
Add support for paletted cache cost
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilyOrg committed Sep 18, 2022
1 parent 53a6fe5 commit a8679f4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/image/cache.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package image

import (
"fmt"
"image"
"log"
"photofield/internal/metrics"
"reflect"
"time"
Expand Down Expand Up @@ -93,11 +93,18 @@ func newImageCache(caches Caches) ImageCache {
return int64(unsafe.Sizeof(*img)) +
int64(cap(img.Pix))*int64(unsafe.Sizeof(img.Pix[0]))

case *image.Paletted:
return int64(unsafe.Sizeof(*img)) +
int64(cap(img.Pix))*int64(unsafe.Sizeof(img.Pix[0])) +
int64(cap(img.Palette))*int64(unsafe.Sizeof(img.Pix[0]))

case nil:
return 1

default:
panic(fmt.Sprintf("Unable to compute cost, unsupported image format %v", reflect.TypeOf(img)))
log.Printf("Unable to compute cost, unsupported image format %v", reflect.TypeOf(img))
// Fallback image size (10MB)
return 10000000
}
},
})
Expand Down

0 comments on commit a8679f4

Please sign in to comment.