Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEF image size is wrong and extra parameters are invalid #281

Closed
llanc opened this issue Oct 12, 2023 · 5 comments
Closed

NEF image size is wrong and extra parameters are invalid #281

llanc opened this issue Oct 12, 2023 · 5 comments
Assignees
Labels
discussion This topic needs some discussion.

Comments

@llanc
Copy link
Contributor

llanc commented Oct 12, 2023

Describe the bug
When converting NEF (NIKON ELECTRIC FILM) format, the resulting webp loses its original pixel ratio. The QUALITY parameter and extra parameters is invalid. Not sure if other RAW formats are ok.

To Reproduce
Just use a NEF image.

Expected behavior
NEF images or other RAW images can work fine.

Screenshots and logs
webp
image
image
NEF
image
image

Environment (please complete the following information):

  • OS: debian 11
  • version or branchd: docker latest

Additional context
none

@n0vad3v
Copy link
Member

n0vad3v commented Oct 13, 2023

From our docs:

Currently supported image format: JPEG, PNG, BMP, GIF, SVG, HEIC

NEF format is currently NOT supported, and the problem seems libwebp related, I've tried using cwebp like:

cwebp DSC_0001.NEF -o output.webp
TIFFReadDirectory: Warning, Unknown field with tag 36867 (0x9003) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 37398 (0x9216) encountered.
Saving file 'output.webp'
File:      DSC_0001.NEF
Dimension: 160 x 120
Output:    4310 bytes Y-U-V-All-PSNR 37.27 38.71 39.62   37.81 dB
           (1.80 bpp)
block count:  intra4:         64  (80.00%)
              intra16:        16  (20.00%)
              skipped:         6  (7.50%)
bytes used:  header:            142  (3.3%)
             mode-partition:    335  (7.8%)
 Residuals bytes  |segment 1|segment 2|segment 3|segment 4|  total
    macroblocks:  |      20%|      21%|      38%|      21%|      80
      quantizer:  |      36 |      30 |      22 |      16 |
   filter level:  |      11 |       7 |       4 |       2 |
du -ch DSC_0001.NEF
12M	DSC_0001.NEF
12M	total

du -ch output.webp 
8.0K	output.webp
8.0K	total

This gives similar results from what you've posted.

@BennyThink BennyThink added the discussion This topic needs some discussion. label Oct 13, 2023
@llanc
Copy link
Contributor Author

llanc commented Oct 13, 2023

How about converting NEF (RAW) images to JPG first and then to WEBP?

@n0vad3v
Copy link
Member

n0vad3v commented Oct 14, 2023

How about converting NEF (RAW) images to JPG first and then to WEBP?

No, it's not that easy, NEF images are little bit hard to deal with, for example, if you use file to check for a NEF image, you'll find it has no standard dimension data:

file 1.NEF 
1.NEF: TIFF image data, big-endian, direntries=25, height=0, bps=0, compression=none, PhotometricInterpretation=RGB, manufacturer=NIKON CORPORATION, model=NIKON XXXXX, orientation=upper-left, width=0

Note height=0 and width=0

So currently we suggest you to convert those NEF images to JPEG or some other supported image formats before using WebP Server Go to render them.

BTW, I've tried https://github.com/rwcarlsen/goexif for extracting info from the above NEF image, and has incorrect results:

package main

import (
	"fmt"
	"os"

	"github.com/rwcarlsen/goexif/exif"
	"github.com/rwcarlsen/goexif/mknote"
)

func main() {

	nefFile, err := os.Open("1.NEF")
	if err != nil {
		fmt.Println(err)
	}
	defer nefFile.Close()
	exif.RegisterParsers(mknote.All...)

	exifData, err := exif.Decode(nefFile)
	if err != nil {
		fmt.Println(err)
	}

	camModel, _ := exifData.Get(exif.Model) // normally, don't ignore errors!
	fmt.Println(camModel.StringVal())

	XResolution, _ := exifData.Get(exif.XResolution)
	YResolution, _ := exifData.Get(exif.YResolution)
	ResolutionUnit, _ := exifData.Get(exif.ResolutionUnit)
	PixelXDimension, _ := exifData.Get(exif.PixelXDimension)
	PixelYDmension, _ := exifData.Get(exif.PixelYDimension)
	ImageWidth, _ := exifData.Get(exif.ImageWidth)
	ImageLength, _ := exifData.Get(exif.ImageLength)

	fmt.Println(XResolution)
	fmt.Println(YResolution)
	fmt.Println(ResolutionUnit)
	fmt.Println(PixelXDimension)
	fmt.Println(PixelYDmension)
	fmt.Println(ImageWidth)
	fmt.Println(ImageLength)
}

The output from above program is:

NIKON XXXXX <nil>
"300/1"
"300/1"
2
<nil>
<nil>
160
120

While it's correct dimension is 4608 x 3072.

Screenshot from 2023-10-14 19-50-57

@llanc
Copy link
Contributor Author

llanc commented Oct 15, 2023

I saw a library from https://github.com/gavinwade12/nef2jpeg that can convert NEF to JPG normally: https://github.com/jeremytorres/rawparser

My test results:
NEF
image

JPG
image
image

@llanc
Copy link
Contributor Author

llanc commented Oct 30, 2023

#284

@llanc llanc closed this as completed Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion This topic needs some discussion.
Projects
None yet
Development

No branches or pull requests

3 participants