mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 08:32:11 +01:00
Add std/wbmp package
This commit is contained in:
1 parent
3128500e20
commit
b4ff1bfb7f
4 files changed
+569
No files matched your search
@@ -0,0 +1,77 @@
|
||||
// Copyright 2020 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub status "#bad header"
|
||||
|
||||
pub struct decoder?(
|
||||
width : base.u32,
|
||||
height : base.u32,
|
||||
)
|
||||
|
||||
pub func decoder.decode_image_config?(dst: nptr base.image_config, src: base.io_reader) {
|
||||
var c : base.u8
|
||||
var i : base.u32
|
||||
var x32 : base.u32
|
||||
var x64 : base.u64
|
||||
|
||||
// TypeField, FixHeaderField.
|
||||
i = 0
|
||||
while i < 2 {
|
||||
c = args.src.read_u8?()
|
||||
if c <> 0 {
|
||||
return "#bad header"
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
// Width, height.
|
||||
i = 0
|
||||
while i < 2 {
|
||||
x32 = 0
|
||||
|
||||
while true,
|
||||
inv i < 2,
|
||||
{
|
||||
c = args.src.read_u8?()
|
||||
x32 |= (c & 0x7F) as base.u32
|
||||
if (c >> 7) == 0 {
|
||||
break
|
||||
}
|
||||
x64 = (x32 as base.u64) << 7
|
||||
if x64 > 0xFFFFFFFF {
|
||||
return "#bad header"
|
||||
}
|
||||
x32 = x64 as base.u32
|
||||
}
|
||||
|
||||
if i == 0 {
|
||||
this.width = x32
|
||||
} else {
|
||||
this.height = x32
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
if args.dst <> nullptr {
|
||||
// TODO: a Wuffs (not just C) name for the
|
||||
// WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY magic pixfmt constant.
|
||||
args.dst.set!(
|
||||
pixfmt: 0x47040008,
|
||||
pixsub: 0,
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
first_frame_io_position: args.src.position(),
|
||||
first_frame_is_opaque: true)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user