Skip to main content

Module media

Module media 

Source
Expand description

A file that is to be attached to a note, before it goes anywhere: what kind of file it is, how large a picture it is, and the picture without what it says of where, when, with what and by whom it was made.

A photograph says a good deal more than what it shows: where it was taken, when, with which camera, what it was edited with, who it is credited to, and sometimes a smaller copy of what it showed before it was cropped. None of that is for a media server, or for whoever looks at the note. So a JPEG, a PNG or a WebP is sent as the picture and no more: of what the file is made of, only what the picture needs to look as it did is kept, and everything else is left out, whatever it is.

FormatKeptLeft out
JPEGThe tables, frames and scans; of the application segments, the JFIF header, the colour profile (ICC) and Adobe’s colour markerEvery other application segment (EXIF, XMP, IPTC, MPF, content credentials, makers’ own), the comments, and whatever follows the end of the picture
PNGThe header, the palette, the picture data, transparency, colour (gamma, chromaticities, sRGB, ICC, HDR), pixel size, background, animationEvery other chunk (text, EXIF, the time it was changed, content credentials, makers’ own), and whatever follows the end
WebPThe picture data, alpha, the colour profile, animationEXIF, XMP, and every chunk that is none of those

This is done to the bytes of the file, and the picture data is copied as it is: nothing is decoded and encoded again, so nothing of the picture is lost.

One thing is put back. A camera held sideways writes the picture as its sensor saw it and says in the EXIF which way is up; without that the picture lies on its side. Which way is up says nothing of where or with what, so a picture that is not upright as written gets an EXIF block that says that and nothing else.

What comes out is then decoded, to make sure it is still a picture. If it is not, while the file as it was is, the file is refused (MediaError::Damaged) rather than sent as it was: what was to be left out is still in it.

Other files go as they are: a GIF, a video, a sound. A video may say where it was taken, and that is not taken out of it here.

Structs§

Bare 🔒
A picture’s file with nothing in it but the picture, and which way up the file it was made from said the picture is: 1 to 8, as EXIF counts them, where 1 is as written.
Media
A file ready to be sent to a media server.

Enums§

MediaError
Why a file is not attached.

Constants§

ANY 🔒
What a file that is not known to be anything is called.
JPEG_EXIF 🔒
How a JPEG’s EXIF segment starts, before the EXIF block.
MAX_BYTES
The largest file that is attached. It is read into memory whole, to be hashed and sent.
ORIENTATION_TAG 🔒
The EXIF tag that says which way up a picture is.
PNG_KEPT 🔒
The chunks of a PNG that are part of the picture: its header, palette and data; transparency; what its colours are (gamma, chromaticities, sRGB, a profile, significant bits, and the three that say how bright and in which colour space); how large a pixel is; its background; suggested palettes; and animation.
PNG_SIGNATURE 🔒
How a PNG starts.
WEBP_HAS_EXIF 🔒
In the header of the extended format, the flags that say there is EXIF, and that there is XMP.
WEBP_HAS_XMP 🔒
WEBP_KEPT 🔒
The chunks of a WebP that are part of the picture: its data, lossy or lossless; the header of the extended format; alpha; the colour profile; and animation.

Functions§

bare_jpeg 🔒
The JPEG bytes as the picture and no more. None if it is not put together as a JPEG is.
bare_png 🔒
The PNG bytes as the picture and no more. None if it is not put together as a PNG is.
bare_webp 🔒
The WebP bytes as the picture and no more. None if it is not put together as a WebP is.
end_of_scan 🔒
Where the picture data that starts at from in the JPEG bytes ends: at the next marker that is none of its own, which are the stuffed zero, the restart markers and fill bytes.
jpeg_keeps 🔒
Whether the segment of a JPEG marked marker, which holds payload, is part of the picture. Everything is, but the application segments and the comments; and of the application segments the JFIF header, the colour profile, and Adobe’s marker, which says how the colours are written.
kind_of
What kind of file bytes are, by how they start; or, for what does not say, by what the name name ends in.
orientation_in 🔒
Which way up the EXIF block tiff says its picture is, if it says, and says one of the eight there are. An EXIF block is a TIFF file: a header that says which end its numbers start at and where its first directory is, and that directory, twelve bytes to an entry.
orientation_only 🔒
An EXIF block that says the picture is orientation way up, and nothing else: a directory of that one entry.
png_chunk 🔒
The PNG chunk called name that holds data.
png_crc 🔒
The checksum a PNG chunk ends in, of its name and what it holds, which are bytes: CRC-32.
prepare
The file called name that bytes are, ready to be sent: a JPEG, a PNG or a WebP as the picture and no more (see the module), and anything else as it is.
to_say 🔒
The orientation that is to be said again: one that is not as written.