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

Sharp converts 16bit pngs to 8bit #3809

Closed
3 tasks done
Siyer2 opened this issue Sep 26, 2023 · 7 comments
Closed
3 tasks done

Sharp converts 16bit pngs to 8bit #3809

Siyer2 opened this issue Sep 26, 2023 · 7 comments
Labels

Comments

@Siyer2
Copy link

Siyer2 commented Sep 26, 2023

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

If you cannot confirm both of these, please open an installation issue instead.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.

If you are using another package which depends on a version of sharp that is not the latest, please open an issue against that package instead.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

System:
    OS: macOS 13.4.1
    CPU: (12) arm64 Apple M2 Pro
    Memory: 47.88 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/.nvm/versions/node/v18.16.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  npmPackages:
    sharp: ^0.32.0 => 0.32.5

What are the steps to reproduce?

I have reproduced the issue in this minimal repo

  1. Take in a 16bit PNG
  2. Get the raw pixel values
  3. Log the pixels

What is the expected behaviour?

For a 256x256 image, I expect there to be an array of size 65536 where each pixel is between 0 and 65535. While I get the correct array size, the pixel values all seem to be 8bit range not 16bit range. I have included a similar operation with imageJs to indicate what I expect.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

Minimal repo here

Please provide sample image(s) that help explain this problem

Image is in repo

@Siyer2 Siyer2 added the triage label Sep 26, 2023
@lovell lovell added question and removed triage labels Sep 26, 2023
@lovell
Copy link
Owner

lovell commented Sep 26, 2023

Did you see the depth option?

https://sharp.pixelplumbing.com/api-output#raw

If you require Uint16Array that's equivalent to ushort.

- const rawOutput = await sharp(buffer).raw().toColorspace("grey16").toBuffer();
+ const rawOutput = await sharp(buffer).raw({ depth: "ushort" }).toColorspace("grey16").toBuffer();

@Siyer2
Copy link
Author

Siyer2 commented Sep 26, 2023

Just tried that (here) with no luck. It still seems to convert the pixels to 8bit range.

@jacobdong
Copy link

I also have a similar issue. In my experiment, I created an image of 256x256 pixels with grayscale values ranging from 0 to 65535. However, when I read the generated image again, the values I read are different from what I input. I don't know where the problem is.

I suspect that even though I used a Uint16Array to construct the Sharp object, the image is still being stored in an 8-bit format in terms of data storage.

I've conducted numerous tests and found that this issue exists.

const createStd16bit = async () => {
  const height = 256;
  const width = 256;
  const uint16rawArray = [];
  for (let i = 0; i < 65536; i++) {
    uint16rawArray.push(i)
    if (i % 256 === 0) {
      console.log(`put data ${i / 256}:${i}`)
    }
  }
  await sharp(Uint16Array.from(uint16rawArray), {
    raw: {
      width: width,
      height: height,
      channels: 1
    }
  })
    .png({progressive: false, force: true})
    .withMetadata({icc: 'p3'})
    .toFile('__local/16bit_std.png');
}

const assertStd16bit = async () => {
  const path = '__local/16bit_std.png'
  const target = await sharp(path);
  const metadata = await target.metadata();
  const {data, info} = await target
    .toColorspace('grey16')
    .raw({depth: 'ushort'})
    .toBuffer({resolveWithObject: true});

  console.log(info)
  console.log(`data.length ::: ${data.length}`)
  const {width, height} = info;
  for (let y = 0; y < height; y++) {
    for (let x = 0; x < width; x++) {
      if (x === 0 || x === 1) {
        const pixelIndex = (y * width + x) * info.channels * 2;
        const actual = data.readUint16BE(pixelIndex);
        const expect = pixelIndex / 2;
        console.log(`position x,y == (${x},${y}) == expect ${expect}  actual ==  ${actual} diff == ${Math.abs(actual - expect)}`)
      }
    }
  }
}

the logs is below

Details

position x,y == (0,0) == expect 0 actual == 0 diff == 0
position x,y == (1,0) == expect 1 actual == 0 diff == 1
position x,y == (0,1) == expect 256 actual == 257 diff == 1
position x,y == (1,1) == expect 257 actual == 257 diff == 0
position x,y == (0,2) == expect 512 actual == 514 diff == 2
position x,y == (1,2) == expect 513 actual == 514 diff == 1
position x,y == (0,3) == expect 768 actual == 771 diff == 3
position x,y == (1,3) == expect 769 actual == 771 diff == 2
position x,y == (0,4) == expect 1024 actual == 1028 diff == 4
position x,y == (1,4) == expect 1025 actual == 1028 diff == 3
position x,y == (0,5) == expect 1280 actual == 1285 diff == 5
position x,y == (1,5) == expect 1281 actual == 1285 diff == 4
position x,y == (0,6) == expect 1536 actual == 1542 diff == 6
position x,y == (1,6) == expect 1537 actual == 1542 diff == 5
position x,y == (0,7) == expect 1792 actual == 1799 diff == 7
position x,y == (1,7) == expect 1793 actual == 1799 diff == 6
position x,y == (0,8) == expect 2048 actual == 2056 diff == 8
position x,y == (1,8) == expect 2049 actual == 2056 diff == 7
position x,y == (0,9) == expect 2304 actual == 2313 diff == 9
position x,y == (1,9) == expect 2305 actual == 2313 diff == 8
position x,y == (0,10) == expect 2560 actual == 2570 diff == 10
position x,y == (1,10) == expect 2561 actual == 2570 diff == 9
position x,y == (0,11) == expect 2816 actual == 2827 diff == 11
position x,y == (1,11) == expect 2817 actual == 2827 diff == 10
position x,y == (0,12) == expect 3072 actual == 3084 diff == 12
position x,y == (1,12) == expect 3073 actual == 3084 diff == 11
position x,y == (0,13) == expect 3328 actual == 3341 diff == 13
position x,y == (1,13) == expect 3329 actual == 3341 diff == 12
position x,y == (0,14) == expect 3584 actual == 3598 diff == 14
position x,y == (1,14) == expect 3585 actual == 3598 diff == 13
position x,y == (0,15) == expect 3840 actual == 3855 diff == 15
position x,y == (1,15) == expect 3841 actual == 3855 diff == 14
position x,y == (0,16) == expect 4096 actual == 4112 diff == 16
position x,y == (1,16) == expect 4097 actual == 4112 diff == 15
position x,y == (0,17) == expect 4352 actual == 4369 diff == 17
position x,y == (1,17) == expect 4353 actual == 4369 diff == 16
position x,y == (0,18) == expect 4608 actual == 4626 diff == 18
position x,y == (1,18) == expect 4609 actual == 4626 diff == 17
position x,y == (0,19) == expect 4864 actual == 4883 diff == 19
position x,y == (1,19) == expect 4865 actual == 4883 diff == 18
position x,y == (0,20) == expect 5120 actual == 5140 diff == 20
position x,y == (1,20) == expect 5121 actual == 5140 diff == 19
position x,y == (0,21) == expect 5376 actual == 5397 diff == 21
position x,y == (1,21) == expect 5377 actual == 5397 diff == 20
position x,y == (0,22) == expect 5632 actual == 5654 diff == 22
position x,y == (1,22) == expect 5633 actual == 5654 diff == 21
position x,y == (0,23) == expect 5888 actual == 5911 diff == 23
position x,y == (1,23) == expect 5889 actual == 5911 diff == 22
position x,y == (0,24) == expect 6144 actual == 6168 diff == 24
position x,y == (1,24) == expect 6145 actual == 6168 diff == 23
position x,y == (0,25) == expect 6400 actual == 6425 diff == 25
position x,y == (1,25) == expect 6401 actual == 6425 diff == 24
position x,y == (0,26) == expect 6656 actual == 6682 diff == 26
position x,y == (1,26) == expect 6657 actual == 6682 diff == 25
position x,y == (0,27) == expect 6912 actual == 6939 diff == 27
position x,y == (1,27) == expect 6913 actual == 6939 diff == 26
position x,y == (0,28) == expect 7168 actual == 7196 diff == 28
position x,y == (1,28) == expect 7169 actual == 7196 diff == 27
position x,y == (0,29) == expect 7424 actual == 7453 diff == 29
position x,y == (1,29) == expect 7425 actual == 7453 diff == 28
position x,y == (0,30) == expect 7680 actual == 7710 diff == 30
position x,y == (1,30) == expect 7681 actual == 7710 diff == 29
position x,y == (0,31) == expect 7936 actual == 7967 diff == 31
position x,y == (1,31) == expect 7937 actual == 7967 diff == 30
position x,y == (0,32) == expect 8192 actual == 8224 diff == 32
position x,y == (1,32) == expect 8193 actual == 8224 diff == 31
position x,y == (0,33) == expect 8448 actual == 8481 diff == 33
position x,y == (1,33) == expect 8449 actual == 8481 diff == 32
position x,y == (0,34) == expect 8704 actual == 8738 diff == 34
position x,y == (1,34) == expect 8705 actual == 8738 diff == 33
position x,y == (0,35) == expect 8960 actual == 8995 diff == 35
position x,y == (1,35) == expect 8961 actual == 8995 diff == 34
position x,y == (0,36) == expect 9216 actual == 9252 diff == 36
position x,y == (1,36) == expect 9217 actual == 9252 diff == 35
position x,y == (0,37) == expect 9472 actual == 9509 diff == 37
position x,y == (1,37) == expect 9473 actual == 9509 diff == 36
position x,y == (0,38) == expect 9728 actual == 9766 diff == 38
position x,y == (1,38) == expect 9729 actual == 9766 diff == 37
position x,y == (0,39) == expect 9984 actual == 10023 diff == 39
position x,y == (1,39) == expect 9985 actual == 10023 diff == 38
position x,y == (0,40) == expect 10240 actual == 10280 diff == 40
position x,y == (1,40) == expect 10241 actual == 10280 diff == 39
position x,y == (0,41) == expect 10496 actual == 10537 diff == 41
position x,y == (1,41) == expect 10497 actual == 10537 diff == 40
position x,y == (0,42) == expect 10752 actual == 10794 diff == 42
position x,y == (1,42) == expect 10753 actual == 10794 diff == 41
position x,y == (0,43) == expect 11008 actual == 11051 diff == 43
position x,y == (1,43) == expect 11009 actual == 11051 diff == 42
position x,y == (0,44) == expect 11264 actual == 11308 diff == 44
position x,y == (1,44) == expect 11265 actual == 11308 diff == 43
position x,y == (0,45) == expect 11520 actual == 11565 diff == 45
position x,y == (1,45) == expect 11521 actual == 11565 diff == 44
position x,y == (0,46) == expect 11776 actual == 11822 diff == 46
position x,y == (1,46) == expect 11777 actual == 11822 diff == 45
position x,y == (0,47) == expect 12032 actual == 12079 diff == 47
position x,y == (1,47) == expect 12033 actual == 12079 diff == 46
position x,y == (0,48) == expect 12288 actual == 12336 diff == 48
position x,y == (1,48) == expect 12289 actual == 12336 diff == 47
position x,y == (0,49) == expect 12544 actual == 12593 diff == 49
position x,y == (1,49) == expect 12545 actual == 12593 diff == 48
position x,y == (0,50) == expect 12800 actual == 12850 diff == 50
position x,y == (1,50) == expect 12801 actual == 12850 diff == 49
position x,y == (0,51) == expect 13056 actual == 13107 diff == 51
position x,y == (1,51) == expect 13057 actual == 13107 diff == 50
position x,y == (0,52) == expect 13312 actual == 13364 diff == 52
position x,y == (1,52) == expect 13313 actual == 13364 diff == 51
position x,y == (0,53) == expect 13568 actual == 13621 diff == 53
position x,y == (1,53) == expect 13569 actual == 13621 diff == 52
position x,y == (0,54) == expect 13824 actual == 13878 diff == 54
position x,y == (1,54) == expect 13825 actual == 13878 diff == 53
position x,y == (0,55) == expect 14080 actual == 14135 diff == 55
position x,y == (1,55) == expect 14081 actual == 14135 diff == 54
position x,y == (0,56) == expect 14336 actual == 14392 diff == 56
position x,y == (1,56) == expect 14337 actual == 14392 diff == 55
position x,y == (0,57) == expect 14592 actual == 14649 diff == 57
position x,y == (1,57) == expect 14593 actual == 14649 diff == 56
position x,y == (0,58) == expect 14848 actual == 14906 diff == 58
position x,y == (1,58) == expect 14849 actual == 14906 diff == 57
position x,y == (0,59) == expect 15104 actual == 15163 diff == 59
position x,y == (1,59) == expect 15105 actual == 15163 diff == 58
position x,y == (0,60) == expect 15360 actual == 15420 diff == 60
position x,y == (1,60) == expect 15361 actual == 15420 diff == 59
position x,y == (0,61) == expect 15616 actual == 15677 diff == 61
position x,y == (1,61) == expect 15617 actual == 15677 diff == 60
position x,y == (0,62) == expect 15872 actual == 15934 diff == 62
position x,y == (1,62) == expect 15873 actual == 15934 diff == 61
position x,y == (0,63) == expect 16128 actual == 16191 diff == 63
position x,y == (1,63) == expect 16129 actual == 16191 diff == 62
position x,y == (0,64) == expect 16384 actual == 16448 diff == 64
position x,y == (1,64) == expect 16385 actual == 16448 diff == 63
position x,y == (0,65) == expect 16640 actual == 16705 diff == 65
position x,y == (1,65) == expect 16641 actual == 16705 diff == 64
position x,y == (0,66) == expect 16896 actual == 16962 diff == 66
position x,y == (1,66) == expect 16897 actual == 16962 diff == 65
position x,y == (0,67) == expect 17152 actual == 17219 diff == 67
position x,y == (1,67) == expect 17153 actual == 17219 diff == 66
position x,y == (0,68) == expect 17408 actual == 17476 diff == 68
position x,y == (1,68) == expect 17409 actual == 17476 diff == 67
position x,y == (0,69) == expect 17664 actual == 17733 diff == 69
position x,y == (1,69) == expect 17665 actual == 17733 diff == 68
position x,y == (0,70) == expect 17920 actual == 17990 diff == 70
position x,y == (1,70) == expect 17921 actual == 17990 diff == 69
position x,y == (0,71) == expect 18176 actual == 18247 diff == 71
position x,y == (1,71) == expect 18177 actual == 18247 diff == 70
position x,y == (0,72) == expect 18432 actual == 18504 diff == 72
position x,y == (1,72) == expect 18433 actual == 18504 diff == 71
position x,y == (0,73) == expect 18688 actual == 18761 diff == 73
position x,y == (1,73) == expect 18689 actual == 18761 diff == 72
position x,y == (0,74) == expect 18944 actual == 19018 diff == 74
position x,y == (1,74) == expect 18945 actual == 19018 diff == 73
position x,y == (0,75) == expect 19200 actual == 19275 diff == 75
position x,y == (1,75) == expect 19201 actual == 19275 diff == 74
position x,y == (0,76) == expect 19456 actual == 19532 diff == 76
position x,y == (1,76) == expect 19457 actual == 19532 diff == 75
position x,y == (0,77) == expect 19712 actual == 19789 diff == 77
position x,y == (1,77) == expect 19713 actual == 19789 diff == 76
position x,y == (0,78) == expect 19968 actual == 20046 diff == 78
position x,y == (1,78) == expect 19969 actual == 20046 diff == 77
position x,y == (0,79) == expect 20224 actual == 20303 diff == 79
position x,y == (1,79) == expect 20225 actual == 20303 diff == 78
position x,y == (0,80) == expect 20480 actual == 20560 diff == 80
position x,y == (1,80) == expect 20481 actual == 20560 diff == 79
position x,y == (0,81) == expect 20736 actual == 20817 diff == 81
position x,y == (1,81) == expect 20737 actual == 20817 diff == 80
position x,y == (0,82) == expect 20992 actual == 21074 diff == 82
position x,y == (1,82) == expect 20993 actual == 21074 diff == 81
position x,y == (0,83) == expect 21248 actual == 21331 diff == 83
position x,y == (1,83) == expect 21249 actual == 21331 diff == 82
position x,y == (0,84) == expect 21504 actual == 21588 diff == 84
position x,y == (1,84) == expect 21505 actual == 21588 diff == 83
position x,y == (0,85) == expect 21760 actual == 21845 diff == 85
position x,y == (1,85) == expect 21761 actual == 21845 diff == 84
position x,y == (0,86) == expect 22016 actual == 22102 diff == 86
position x,y == (1,86) == expect 22017 actual == 22102 diff == 85
position x,y == (0,87) == expect 22272 actual == 22359 diff == 87
position x,y == (1,87) == expect 22273 actual == 22359 diff == 86
position x,y == (0,88) == expect 22528 actual == 22616 diff == 88
position x,y == (1,88) == expect 22529 actual == 22616 diff == 87
position x,y == (0,89) == expect 22784 actual == 22873 diff == 89
position x,y == (1,89) == expect 22785 actual == 22873 diff == 88
position x,y == (0,90) == expect 23040 actual == 23130 diff == 90
position x,y == (1,90) == expect 23041 actual == 23130 diff == 89
position x,y == (0,91) == expect 23296 actual == 23387 diff == 91
position x,y == (1,91) == expect 23297 actual == 23387 diff == 90
position x,y == (0,92) == expect 23552 actual == 23644 diff == 92
position x,y == (1,92) == expect 23553 actual == 23644 diff == 91
position x,y == (0,93) == expect 23808 actual == 23901 diff == 93
position x,y == (1,93) == expect 23809 actual == 23901 diff == 92
position x,y == (0,94) == expect 24064 actual == 24158 diff == 94
position x,y == (1,94) == expect 24065 actual == 24158 diff == 93
position x,y == (0,95) == expect 24320 actual == 24415 diff == 95
position x,y == (1,95) == expect 24321 actual == 24415 diff == 94
position x,y == (0,96) == expect 24576 actual == 24672 diff == 96
position x,y == (1,96) == expect 24577 actual == 24672 diff == 95
position x,y == (0,97) == expect 24832 actual == 24929 diff == 97
position x,y == (1,97) == expect 24833 actual == 24929 diff == 96
position x,y == (0,98) == expect 25088 actual == 25186 diff == 98
position x,y == (1,98) == expect 25089 actual == 25186 diff == 97
position x,y == (0,99) == expect 25344 actual == 25443 diff == 99
position x,y == (1,99) == expect 25345 actual == 25443 diff == 98
position x,y == (0,100) == expect 25600 actual == 25700 diff == 100
position x,y == (1,100) == expect 25601 actual == 25700 diff == 99
position x,y == (0,101) == expect 25856 actual == 25957 diff == 101
position x,y == (1,101) == expect 25857 actual == 25957 diff == 100
position x,y == (0,102) == expect 26112 actual == 26214 diff == 102
position x,y == (1,102) == expect 26113 actual == 26214 diff == 101
position x,y == (0,103) == expect 26368 actual == 26471 diff == 103
position x,y == (1,103) == expect 26369 actual == 26471 diff == 102
position x,y == (0,104) == expect 26624 actual == 26728 diff == 104
position x,y == (1,104) == expect 26625 actual == 26728 diff == 103
position x,y == (0,105) == expect 26880 actual == 26985 diff == 105
position x,y == (1,105) == expect 26881 actual == 26985 diff == 104
position x,y == (0,106) == expect 27136 actual == 27242 diff == 106
position x,y == (1,106) == expect 27137 actual == 27242 diff == 105
position x,y == (0,107) == expect 27392 actual == 27499 diff == 107
position x,y == (1,107) == expect 27393 actual == 27499 diff == 106
position x,y == (0,108) == expect 27648 actual == 27756 diff == 108
position x,y == (1,108) == expect 27649 actual == 27756 diff == 107
position x,y == (0,109) == expect 27904 actual == 28013 diff == 109
position x,y == (1,109) == expect 27905 actual == 28013 diff == 108
position x,y == (0,110) == expect 28160 actual == 28270 diff == 110
position x,y == (1,110) == expect 28161 actual == 28270 diff == 109
position x,y == (0,111) == expect 28416 actual == 28527 diff == 111
position x,y == (1,111) == expect 28417 actual == 28527 diff == 110
position x,y == (0,112) == expect 28672 actual == 28784 diff == 112
position x,y == (1,112) == expect 28673 actual == 28784 diff == 111
position x,y == (0,113) == expect 28928 actual == 29041 diff == 113
position x,y == (1,113) == expect 28929 actual == 29041 diff == 112
position x,y == (0,114) == expect 29184 actual == 29298 diff == 114
position x,y == (1,114) == expect 29185 actual == 29298 diff == 113
position x,y == (0,115) == expect 29440 actual == 29555 diff == 115
position x,y == (1,115) == expect 29441 actual == 29555 diff == 114
position x,y == (0,116) == expect 29696 actual == 29812 diff == 116
position x,y == (1,116) == expect 29697 actual == 29812 diff == 115
position x,y == (0,117) == expect 29952 actual == 30069 diff == 117
position x,y == (1,117) == expect 29953 actual == 30069 diff == 116
position x,y == (0,118) == expect 30208 actual == 30326 diff == 118
position x,y == (1,118) == expect 30209 actual == 30326 diff == 117
position x,y == (0,119) == expect 30464 actual == 30583 diff == 119
position x,y == (1,119) == expect 30465 actual == 30583 diff == 118
position x,y == (0,120) == expect 30720 actual == 30840 diff == 120
position x,y == (1,120) == expect 30721 actual == 30840 diff == 119
position x,y == (0,121) == expect 30976 actual == 31097 diff == 121
position x,y == (1,121) == expect 30977 actual == 31097 diff == 120
position x,y == (0,122) == expect 31232 actual == 31354 diff == 122
position x,y == (1,122) == expect 31233 actual == 31354 diff == 121
position x,y == (0,123) == expect 31488 actual == 31611 diff == 123
position x,y == (1,123) == expect 31489 actual == 31611 diff == 122
position x,y == (0,124) == expect 31744 actual == 31868 diff == 124
position x,y == (1,124) == expect 31745 actual == 31868 diff == 123
position x,y == (0,125) == expect 32000 actual == 32125 diff == 125
position x,y == (1,125) == expect 32001 actual == 32125 diff == 124
position x,y == (0,126) == expect 32256 actual == 32382 diff == 126
position x,y == (1,126) == expect 32257 actual == 32382 diff == 125
position x,y == (0,127) == expect 32512 actual == 32639 diff == 127
position x,y == (1,127) == expect 32513 actual == 32639 diff == 126
position x,y == (0,128) == expect 32768 actual == 32896 diff == 128
position x,y == (1,128) == expect 32769 actual == 32896 diff == 127
position x,y == (0,129) == expect 33024 actual == 32896 diff == 128
position x,y == (1,129) == expect 33025 actual == 33153 diff == 128
position x,y == (0,130) == expect 33280 actual == 33153 diff == 127
position x,y == (1,130) == expect 33281 actual == 33153 diff == 128
position x,y == (0,131) == expect 33536 actual == 33410 diff == 126
position x,y == (1,131) == expect 33537 actual == 33410 diff == 127
position x,y == (0,132) == expect 33792 actual == 33667 diff == 125
position x,y == (1,132) == expect 33793 actual == 33667 diff == 126
position x,y == (0,133) == expect 34048 actual == 33924 diff == 124
position x,y == (1,133) == expect 34049 actual == 33924 diff == 125
position x,y == (0,134) == expect 34304 actual == 34181 diff == 123
position x,y == (1,134) == expect 34305 actual == 34181 diff == 124
position x,y == (0,135) == expect 34560 actual == 34438 diff == 122
position x,y == (1,135) == expect 34561 actual == 34438 diff == 123
position x,y == (0,136) == expect 34816 actual == 34695 diff == 121
position x,y == (1,136) == expect 34817 actual == 34695 diff == 122
position x,y == (0,137) == expect 35072 actual == 34952 diff == 120
position x,y == (1,137) == expect 35073 actual == 34952 diff == 121
position x,y == (0,138) == expect 35328 actual == 35209 diff == 119
position x,y == (1,138) == expect 35329 actual == 35209 diff == 120
position x,y == (0,139) == expect 35584 actual == 35466 diff == 118
position x,y == (1,139) == expect 35585 actual == 35466 diff == 119
position x,y == (0,140) == expect 35840 actual == 35723 diff == 117
position x,y == (1,140) == expect 35841 actual == 35723 diff == 118
position x,y == (0,141) == expect 36096 actual == 35980 diff == 116
position x,y == (1,141) == expect 36097 actual == 35980 diff == 117
position x,y == (0,142) == expect 36352 actual == 36237 diff == 115
position x,y == (1,142) == expect 36353 actual == 36237 diff == 116
position x,y == (0,143) == expect 36608 actual == 36494 diff == 114
position x,y == (1,143) == expect 36609 actual == 36494 diff == 115
position x,y == (0,144) == expect 36864 actual == 36751 diff == 113
position x,y == (1,144) == expect 36865 actual == 36751 diff == 114
position x,y == (0,145) == expect 37120 actual == 37008 diff == 112
position x,y == (1,145) == expect 37121 actual == 37008 diff == 113
position x,y == (0,146) == expect 37376 actual == 37265 diff == 111
position x,y == (1,146) == expect 37377 actual == 37265 diff == 112
position x,y == (0,147) == expect 37632 actual == 37522 diff == 110
position x,y == (1,147) == expect 37633 actual == 37522 diff == 111
position x,y == (0,148) == expect 37888 actual == 37779 diff == 109
position x,y == (1,148) == expect 37889 actual == 37779 diff == 110
position x,y == (0,149) == expect 38144 actual == 38036 diff == 108
position x,y == (1,149) == expect 38145 actual == 38036 diff == 109
position x,y == (0,150) == expect 38400 actual == 38293 diff == 107
position x,y == (1,150) == expect 38401 actual == 38293 diff == 108
position x,y == (0,151) == expect 38656 actual == 38550 diff == 106
position x,y == (1,151) == expect 38657 actual == 38550 diff == 107
position x,y == (0,152) == expect 38912 actual == 38807 diff == 105
position x,y == (1,152) == expect 38913 actual == 38807 diff == 106
position x,y == (0,153) == expect 39168 actual == 39064 diff == 104
position x,y == (1,153) == expect 39169 actual == 39064 diff == 105
position x,y == (0,154) == expect 39424 actual == 39321 diff == 103
position x,y == (1,154) == expect 39425 actual == 39321 diff == 104
position x,y == (0,155) == expect 39680 actual == 39578 diff == 102
position x,y == (1,155) == expect 39681 actual == 39578 diff == 103
position x,y == (0,156) == expect 39936 actual == 39835 diff == 101
position x,y == (1,156) == expect 39937 actual == 39835 diff == 102
position x,y == (0,157) == expect 40192 actual == 40092 diff == 100
position x,y == (1,157) == expect 40193 actual == 40092 diff == 101
position x,y == (0,158) == expect 40448 actual == 40349 diff == 99
position x,y == (1,158) == expect 40449 actual == 40349 diff == 100
position x,y == (0,159) == expect 40704 actual == 40606 diff == 98
position x,y == (1,159) == expect 40705 actual == 40606 diff == 99
position x,y == (0,160) == expect 40960 actual == 40863 diff == 97
position x,y == (1,160) == expect 40961 actual == 40863 diff == 98
position x,y == (0,161) == expect 41216 actual == 41120 diff == 96
position x,y == (1,161) == expect 41217 actual == 41120 diff == 97
position x,y == (0,162) == expect 41472 actual == 41377 diff == 95
position x,y == (1,162) == expect 41473 actual == 41377 diff == 96
position x,y == (0,163) == expect 41728 actual == 41634 diff == 94
position x,y == (1,163) == expect 41729 actual == 41634 diff == 95
position x,y == (0,164) == expect 41984 actual == 41891 diff == 93
position x,y == (1,164) == expect 41985 actual == 41891 diff == 94
position x,y == (0,165) == expect 42240 actual == 42148 diff == 92
position x,y == (1,165) == expect 42241 actual == 42148 diff == 93
position x,y == (0,166) == expect 42496 actual == 42405 diff == 91
position x,y == (1,166) == expect 42497 actual == 42405 diff == 92
position x,y == (0,167) == expect 42752 actual == 42662 diff == 90
position x,y == (1,167) == expect 42753 actual == 42662 diff == 91
position x,y == (0,168) == expect 43008 actual == 42919 diff == 89
position x,y == (1,168) == expect 43009 actual == 42919 diff == 90
position x,y == (0,169) == expect 43264 actual == 43176 diff == 88
position x,y == (1,169) == expect 43265 actual == 43176 diff == 89
position x,y == (0,170) == expect 43520 actual == 43433 diff == 87
position x,y == (1,170) == expect 43521 actual == 43433 diff == 88
position x,y == (0,171) == expect 43776 actual == 43690 diff == 86
position x,y == (1,171) == expect 43777 actual == 43690 diff == 87
position x,y == (0,172) == expect 44032 actual == 43947 diff == 85
position x,y == (1,172) == expect 44033 actual == 43947 diff == 86
position x,y == (0,173) == expect 44288 actual == 44204 diff == 84
position x,y == (1,173) == expect 44289 actual == 44204 diff == 85
position x,y == (0,174) == expect 44544 actual == 44461 diff == 83
position x,y == (1,174) == expect 44545 actual == 44461 diff == 84
position x,y == (0,175) == expect 44800 actual == 44718 diff == 82
position x,y == (1,175) == expect 44801 actual == 44718 diff == 83
position x,y == (0,176) == expect 45056 actual == 44975 diff == 81
position x,y == (1,176) == expect 45057 actual == 44975 diff == 82
position x,y == (0,177) == expect 45312 actual == 45232 diff == 80
position x,y == (1,177) == expect 45313 actual == 45232 diff == 81
position x,y == (0,178) == expect 45568 actual == 45489 diff == 79
position x,y == (1,178) == expect 45569 actual == 45489 diff == 80
position x,y == (0,179) == expect 45824 actual == 45746 diff == 78
position x,y == (1,179) == expect 45825 actual == 45746 diff == 79
position x,y == (0,180) == expect 46080 actual == 46003 diff == 77
position x,y == (1,180) == expect 46081 actual == 46003 diff == 78
position x,y == (0,181) == expect 46336 actual == 46260 diff == 76
position x,y == (1,181) == expect 46337 actual == 46260 diff == 77
position x,y == (0,182) == expect 46592 actual == 46517 diff == 75
position x,y == (1,182) == expect 46593 actual == 46517 diff == 76
position x,y == (0,183) == expect 46848 actual == 46774 diff == 74
position x,y == (1,183) == expect 46849 actual == 46774 diff == 75
position x,y == (0,184) == expect 47104 actual == 47031 diff == 73
position x,y == (1,184) == expect 47105 actual == 47031 diff == 74
position x,y == (0,185) == expect 47360 actual == 47288 diff == 72
position x,y == (1,185) == expect 47361 actual == 47288 diff == 73
position x,y == (0,186) == expect 47616 actual == 47545 diff == 71
position x,y == (1,186) == expect 47617 actual == 47545 diff == 72
position x,y == (0,187) == expect 47872 actual == 47802 diff == 70
position x,y == (1,187) == expect 47873 actual == 47802 diff == 71
position x,y == (0,188) == expect 48128 actual == 48059 diff == 69
position x,y == (1,188) == expect 48129 actual == 48059 diff == 70
position x,y == (0,189) == expect 48384 actual == 48316 diff == 68
position x,y == (1,189) == expect 48385 actual == 48316 diff == 69
position x,y == (0,190) == expect 48640 actual == 48573 diff == 67
position x,y == (1,190) == expect 48641 actual == 48573 diff == 68
position x,y == (0,191) == expect 48896 actual == 48830 diff == 66
position x,y == (1,191) == expect 48897 actual == 48830 diff == 67
position x,y == (0,192) == expect 49152 actual == 49087 diff == 65
position x,y == (1,192) == expect 49153 actual == 49087 diff == 66
position x,y == (0,193) == expect 49408 actual == 49344 diff == 64
position x,y == (1,193) == expect 49409 actual == 49344 diff == 65
position x,y == (0,194) == expect 49664 actual == 49601 diff == 63
position x,y == (1,194) == expect 49665 actual == 49601 diff == 64
position x,y == (0,195) == expect 49920 actual == 49858 diff == 62
position x,y == (1,195) == expect 49921 actual == 49858 diff == 63
position x,y == (0,196) == expect 50176 actual == 50115 diff == 61
position x,y == (1,196) == expect 50177 actual == 50115 diff == 62
position x,y == (0,197) == expect 50432 actual == 50372 diff == 60
position x,y == (1,197) == expect 50433 actual == 50372 diff == 61
position x,y == (0,198) == expect 50688 actual == 50629 diff == 59
position x,y == (1,198) == expect 50689 actual == 50629 diff == 60
position x,y == (0,199) == expect 50944 actual == 50886 diff == 58
position x,y == (1,199) == expect 50945 actual == 50886 diff == 59
position x,y == (0,200) == expect 51200 actual == 51143 diff == 57
position x,y == (1,200) == expect 51201 actual == 51143 diff == 58
position x,y == (0,201) == expect 51456 actual == 51400 diff == 56
position x,y == (1,201) == expect 51457 actual == 51400 diff == 57
position x,y == (0,202) == expect 51712 actual == 51657 diff == 55
position x,y == (1,202) == expect 51713 actual == 51657 diff == 56
position x,y == (0,203) == expect 51968 actual == 51914 diff == 54
position x,y == (1,203) == expect 51969 actual == 51914 diff == 55
position x,y == (0,204) == expect 52224 actual == 52171 diff == 53
position x,y == (1,204) == expect 52225 actual == 52171 diff == 54
position x,y == (0,205) == expect 52480 actual == 52428 diff == 52
position x,y == (1,205) == expect 52481 actual == 52428 diff == 53
position x,y == (0,206) == expect 52736 actual == 52685 diff == 51
position x,y == (1,206) == expect 52737 actual == 52685 diff == 52
position x,y == (0,207) == expect 52992 actual == 52942 diff == 50
position x,y == (1,207) == expect 52993 actual == 52942 diff == 51
position x,y == (0,208) == expect 53248 actual == 53199 diff == 49
position x,y == (1,208) == expect 53249 actual == 53199 diff == 50
position x,y == (0,209) == expect 53504 actual == 53456 diff == 48
position x,y == (1,209) == expect 53505 actual == 53456 diff == 49
position x,y == (0,210) == expect 53760 actual == 53713 diff == 47
position x,y == (1,210) == expect 53761 actual == 53713 diff == 48
position x,y == (0,211) == expect 54016 actual == 53970 diff == 46
position x,y == (1,211) == expect 54017 actual == 53970 diff == 47
position x,y == (0,212) == expect 54272 actual == 54227 diff == 45
position x,y == (1,212) == expect 54273 actual == 54227 diff == 46
position x,y == (0,213) == expect 54528 actual == 54484 diff == 44
position x,y == (1,213) == expect 54529 actual == 54484 diff == 45
position x,y == (0,214) == expect 54784 actual == 54741 diff == 43
position x,y == (1,214) == expect 54785 actual == 54741 diff == 44
position x,y == (0,215) == expect 55040 actual == 54998 diff == 42
position x,y == (1,215) == expect 55041 actual == 54998 diff == 43
position x,y == (0,216) == expect 55296 actual == 55255 diff == 41
position x,y == (1,216) == expect 55297 actual == 55255 diff == 42
position x,y == (0,217) == expect 55552 actual == 55512 diff == 40
position x,y == (1,217) == expect 55553 actual == 55512 diff == 41
position x,y == (0,218) == expect 55808 actual == 55769 diff == 39
position x,y == (1,218) == expect 55809 actual == 55769 diff == 40
position x,y == (0,219) == expect 56064 actual == 56026 diff == 38
position x,y == (1,219) == expect 56065 actual == 56026 diff == 39
position x,y == (0,220) == expect 56320 actual == 56283 diff == 37
position x,y == (1,220) == expect 56321 actual == 56283 diff == 38
position x,y == (0,221) == expect 56576 actual == 56540 diff == 36
position x,y == (1,221) == expect 56577 actual == 56540 diff == 37
position x,y == (0,222) == expect 56832 actual == 56797 diff == 35
position x,y == (1,222) == expect 56833 actual == 56797 diff == 36
position x,y == (0,223) == expect 57088 actual == 57054 diff == 34
position x,y == (1,223) == expect 57089 actual == 57054 diff == 35
position x,y == (0,224) == expect 57344 actual == 57311 diff == 33
position x,y == (1,224) == expect 57345 actual == 57311 diff == 34
position x,y == (0,225) == expect 57600 actual == 57568 diff == 32
position x,y == (1,225) == expect 57601 actual == 57568 diff == 33
position x,y == (0,226) == expect 57856 actual == 57825 diff == 31
position x,y == (1,226) == expect 57857 actual == 57825 diff == 32
position x,y == (0,227) == expect 58112 actual == 58082 diff == 30
position x,y == (1,227) == expect 58113 actual == 58082 diff == 31
position x,y == (0,228) == expect 58368 actual == 58339 diff == 29
position x,y == (1,228) == expect 58369 actual == 58339 diff == 30
position x,y == (0,229) == expect 58624 actual == 58596 diff == 28
position x,y == (1,229) == expect 58625 actual == 58596 diff == 29
position x,y == (0,230) == expect 58880 actual == 58853 diff == 27
position x,y == (1,230) == expect 58881 actual == 58853 diff == 28
position x,y == (0,231) == expect 59136 actual == 59110 diff == 26
position x,y == (1,231) == expect 59137 actual == 59110 diff == 27
position x,y == (0,232) == expect 59392 actual == 59367 diff == 25
position x,y == (1,232) == expect 59393 actual == 59367 diff == 26
position x,y == (0,233) == expect 59648 actual == 59624 diff == 24
position x,y == (1,233) == expect 59649 actual == 59624 diff == 25
position x,y == (0,234) == expect 59904 actual == 59881 diff == 23
position x,y == (1,234) == expect 59905 actual == 59881 diff == 24
position x,y == (0,235) == expect 60160 actual == 60138 diff == 22
position x,y == (1,235) == expect 60161 actual == 60138 diff == 23
position x,y == (0,236) == expect 60416 actual == 60395 diff == 21
position x,y == (1,236) == expect 60417 actual == 60395 diff == 22
position x,y == (0,237) == expect 60672 actual == 60652 diff == 20
position x,y == (1,237) == expect 60673 actual == 60652 diff == 21
position x,y == (0,238) == expect 60928 actual == 60909 diff == 19
position x,y == (1,238) == expect 60929 actual == 60909 diff == 20
position x,y == (0,239) == expect 61184 actual == 61166 diff == 18
position x,y == (1,239) == expect 61185 actual == 61166 diff == 19
position x,y == (0,240) == expect 61440 actual == 61423 diff == 17
position x,y == (1,240) == expect 61441 actual == 61423 diff == 18
position x,y == (0,241) == expect 61696 actual == 61680 diff == 16
position x,y == (1,241) == expect 61697 actual == 61680 diff == 17
position x,y == (0,242) == expect 61952 actual == 61937 diff == 15
position x,y == (1,242) == expect 61953 actual == 61937 diff == 16
position x,y == (0,243) == expect 62208 actual == 62194 diff == 14
position x,y == (1,243) == expect 62209 actual == 62194 diff == 15
position x,y == (0,244) == expect 62464 actual == 62451 diff == 13
position x,y == (1,244) == expect 62465 actual == 62451 diff == 14
position x,y == (0,245) == expect 62720 actual == 62708 diff == 12
position x,y == (1,245) == expect 62721 actual == 62708 diff == 13
position x,y == (0,246) == expect 62976 actual == 62965 diff == 11
position x,y == (1,246) == expect 62977 actual == 62965 diff == 12
position x,y == (0,247) == expect 63232 actual == 63222 diff == 10
position x,y == (1,247) == expect 63233 actual == 63222 diff == 11
position x,y == (0,248) == expect 63488 actual == 63479 diff == 9
position x,y == (1,248) == expect 63489 actual == 63479 diff == 10
position x,y == (0,249) == expect 63744 actual == 63736 diff == 8
position x,y == (1,249) == expect 63745 actual == 63736 diff == 9
position x,y == (0,250) == expect 64000 actual == 63993 diff == 7
position x,y == (1,250) == expect 64001 actual == 63993 diff == 8
position x,y == (0,251) == expect 64256 actual == 64250 diff == 6
position x,y == (1,251) == expect 64257 actual == 64250 diff == 7
position x,y == (0,252) == expect 64512 actual == 64507 diff == 5
position x,y == (1,252) == expect 64513 actual == 64507 diff == 6
position x,y == (0,253) == expect 64768 actual == 64764 diff == 4
position x,y == (1,253) == expect 64769 actual == 64764 diff == 5
position x,y == (0,254) == expect 65024 actual == 65021 diff == 3
position x,y == (1,254) == expect 65025 actual == 65021 diff == 4
position x,y == (0,255) == expect 65280 actual == 65278 diff == 2
position x,y == (1,255) == expect 65281 actual == 65278 diff == 3

When I use image-js load this pic
the Matrix info is

Matrix {
  [
    0        0        0        0        0        0        0        0        0        0       
    256      256      256      256      256      256      256      256      256      256     
    256      256      256      256      256      256      256      256      256      256     
    513      513      513      513      513      513      513      513      513      513     
    513      513      513      513      513      513      513      513      513      513     
    769      769      769      769      769      769      769      769      769      769     
    769      769      769      769      769      769      769      769      769      769     
    1026     1026     1026     1026     1026     1026     1026     1026     1026     1026    
    1026     1026     1026     1026     1026     1026     1026     1026     1026     1026    
    1282     1282     1282     1282     1282     1282     1282     1282     1282     1282    
    1282     1282     1282     1282     1282     1282     1282     1282     1282     1282    
    1538     1538     1538     1538     1538     1538     1538     1538     1538     1538    
    1538     1538     1538     1538     1538     1538     1538     1538     1538     1538    
    1795     1795     1795     1795     1795     1795     1795     1795     1795     1795    
    1795     1795     1795     1795     1795     1795     1795     1795     1795     1795     ... 246 more columns
    ... 241 more rows
  ]
  rows: 256
  columns: 256
}

@lovell
Copy link
Owner

lovell commented Sep 27, 2023

@jacobdong Are you referring to #3808 ? I'd prefer to track these as one issue if so.

@jacobdong
Copy link

@lovell
First of all, thank you very much for your response. Secondly, in my scenario, it encompasses the issue mentioned here, the problem I brought up in my issue. It involves two actions: writing and reading. The unit16Array I write and the data I read out are inconsistent

@lovell
Copy link
Owner

lovell commented Oct 4, 2023

@Siyer2 To build a Uint16Array from 16-bit data stored in an 8-bit Buffer, you'll need to access the underlying ArrayBuffer, something like the following:

-  return new Uint16Array(rawOutput);
+  return new Uint16Array(rawOutput.buffer, 0, rawOutput.length / 2);

@Siyer2
Copy link
Author

Siyer2 commented Oct 5, 2023

That worked for me, thanks @lovell !

@Siyer2 Siyer2 closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants