mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-25 07:30:14 +08:00
Fix ImageDecoder of JPEG format; fix #1610
This commit is contained in:
parent
ee78b5dbe5
commit
938e7eae57
@ -13,4 +13,5 @@
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
public fun Int.toLongUnsigned(): Long = this.toLong().and(0xFFFF_FFFF)
|
||||
public fun Short.toIntUnsigned(): Int = this.toUShort().toInt()
|
||||
public fun Short.toIntUnsigned(): Int = this.toUShort().toInt()
|
||||
public fun Byte.toIntUnsigned(): Int = toInt() and 0xFF
|
||||
|
@ -12,10 +12,7 @@ package net.mamoe.mirai.internal.message
|
||||
import kotlinx.io.core.*
|
||||
import kotlinx.io.streams.asInput
|
||||
import net.mamoe.mirai.message.data.ImageType
|
||||
import net.mamoe.mirai.utils.ExternalResource
|
||||
import net.mamoe.mirai.utils.readString
|
||||
import net.mamoe.mirai.utils.toUHexString
|
||||
import net.mamoe.mirai.utils.withUse
|
||||
import net.mamoe.mirai.utils.*
|
||||
import java.io.IOException
|
||||
|
||||
//SOF0-SOF3 SOF5-SOF7 SOF9-SOF11 SOF13-SOF15 Segment
|
||||
@ -27,6 +24,7 @@ private val JPG_SOF_RANGE = listOf(
|
||||
0xCD.toByte()..0xCF.toByte()
|
||||
)
|
||||
|
||||
// https://docs.fileformat.com/image/jpeg/
|
||||
private fun Input.getJPGImageInfo(): ImageInfo {
|
||||
require(readBytes(2).contentEquals(byteArrayOf(0xFF.toByte(), 0xD8.toByte()))) {
|
||||
"It's not a valid jpg file"
|
||||
@ -51,7 +49,7 @@ private fun Input.getJPGImageInfo(): ImageInfo {
|
||||
//Other segment, skip
|
||||
discardExact(
|
||||
//Skip size=segment length - 2 (length data itself)
|
||||
readShort().toInt() - 2
|
||||
readShort().toIntUnsigned() - 2
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user