Commit Graph

32 Commits

Author SHA1 Message Date
wm4 68ff8a0484 Move compat/ and bstr/ directory contents somewhere else
bstr.c doesn't really deserve its own directory, and compat had just
a few files, most of which may as well be in osdep. There isn't really
any justification for these extra directories, so get rid of them.

The compat/libav.h was empty - just delete it. We changed our approach
to API compatibility, and will likely not need it anymore.
2014-08-29 12:31:52 +02:00
Niklas Haas 17762a1919 video: Generate an accurate CMS matrix instead of hard-coding
This also avoids an extra matrix multiplication when using :srgb, making
that path both more efficient and also eliminating more hard-coded
values.

In addition, the previously hard-coded XYZ to RGB matrix will be
dynamically generated.
2014-06-22 19:02:06 +02:00
Niklas Haas 70f50ddc5e video: Add support for non-BT.709 primaries
This add support for reading primary information from lavc, categorized
into BT.601-525, BT.601-625, BT.709 and BT.2020; and passes it on to the
vo. In vo_opengl, we always generate the 3dlut against the wider BT.2020
and transform our source into this colorspace in the shader.
2014-06-22 19:00:38 +02:00
wm4 973c1fa570 gl_lcms: use thread-safe lcms API, require lcms2 2.6
The error log callback was not thread-safe and not library-safe. And
apparently there were some other details that made it not library-safe,
such as a global lcms plugin registry.

Switch the the thread-safe API provided by lcms2 starting with 2.6.
Remove our approximate thread-safety hacks.

Note that lcms basically provides 2 APIs now, the old functions, and
the thread-safe alternatives whose names end with THR. Some functions
don't change, because they already have a context of some sort. Care
must be taken not to accidentally use old APIs.
2014-06-16 18:02:52 +02:00
wm4 99f5fef0ea Add more const
While I'm not very fond of "const", it's important for declarations
(it decides whether a symbol is emitted in a read-only or read/write
section). Fix all these cases, so we have writeable global data only
when we really need.
2014-06-11 00:39:14 +02:00
Stefano Pigozzi aa77f5dd3c gl_lcms: properly expand the cache filename being written
This is needed to preserve the same path used when opening the cache file, and
correctly expands ~ when icc-cache is added to the mpv config file.
2014-04-05 18:13:00 +02:00
Stefano Pigozzi c2c9cb2bbf gl_lcms: fix build when lcms2 is not available
Was broken in b0ee9334e.
2014-03-31 22:31:24 +02:00
Stefano Pigozzi b0ee9334e3 vo_opengl, cocoa: allow to autoselect a color profile
This commit adds support for automatic selection of color profiles based on
the display where mpv is initialized, and automatically changes the color
profile when display is changed or the profile itself is changed from
System Preferences.

@UliZappe was responsible with the testing and implementation of a lot of this
commit, including the original implementation of `cocoa_get_icc_profile_path`
(See #594).

Fixes #594
2014-03-31 22:07:33 +02:00
Niklas Haas 6a833797db vo_opengl: Simplify and clarify color correction code
This commit:

- Changes some of the #define and variable names for clarification and
  adds comments where appropriate.
- Unifies :srgb and :icc-profile, making them fit into the same step of
  the decoding process and removing the weird interactions between both
  of them.
- Makes :icc-profile take precedence over :srgb (to significantly reduce
  the number of confusing and useless special cases)
- Moves BT709 decompanding (approximate or actual) to the shader in all
  cases, making it happen before upscaling (instead of the old 0.45
  gamma function). This is the simpler and more proper way to do it.
- Enables the approx gamma function to work with :srgb as well due to
  this (since they now share the gamma expansion code).
- Renames :icc-approx-gamma to :approx-gamma since it is no longer tied
  to the ICC options or LittleCMS.
- Uses gamma 2.4 as input space for the actual 3DLUT, this is now a
  pretty arbitrary factor but I picked 2.4 mainly because a higher pure
  power value here seems to produce visually better results with wide
  gamut profiles, rather then the previous 1.95 or BT.709.
- Adds the input gamma space to the 3dlut cache header in case we change
  it more in the future, or even make it user customizable (though I
  don't see why the latter would really be necessary).
- Fixes the OSD's gamma when using :srgb, which was previously still
  using the old (0.45) approximation in all cases.
- Updates documentation on :srgb, it was still mentioning the old
  behavior from circa a year ago.

This commit should serve to both open up and make the CMS/shader code much
more accessible and less confusing/error-prone and simultaneously also
improve the performance of 3DLUTs with wide gamut color spaces.

I would liked to have made it more modular but almost all of these
changes are interdependent, save for the documentation updates.

Note: Right now, the "3DLUT takes precedence over SRGB" logic is just
coded into gl_lcms.c's compile_shaders function. Ideally, this should be
done earlier, when parsing the options (by overriding the actual
opts.srgb flag) and output a warning to the user.

Note: I'm not sure how well this works together with real-world
subtitles that may need to be color corrected as well. I'm not sure
whether :approx-gamma needs to apply to subtitles as well. I'll need to
test this on proper files later.

Note: As of now, linear light scaling is still intrinsically tied to
either :srgb or :icc-profile. It would be thinkable to have this as an
extra option, :linear-scaling or similar, that could be used with or
without the two color management options.
2014-03-10 22:56:25 +01:00
Niklas Haas d5b5ed0b46 vo_opengl: Include :icc-approx-gamma option in the 3DLUT cache header
This makes sure the ICC cache is recomputed when the :icc-approx-gamma
option is changed, since it affects the output quite a lot.
2014-03-01 02:28:46 +01:00
Niklas Haas 6119cf13be vo_opengl: Change the default icc-intent to relative colorimetric
This used to be absolute colorimetric, but relative colorimetric is a
saner default due to the arguments presented in issue #595.

A short summary: In general it doesn't affect much because our eyes
adapt to the white point either way, but if running in windowed mode it
would make the whites seem inconsistent/tinted. For fullscreen
projection it's also undesirable since it reduces the dynamic range
without much benefit (again, since our eyes adapt either way) and it
also breaks calibration against ambient lighting.

This shouldn't change much, since most profile types that aren't 3DLUTs
aren't capable of either of those transforms, and most displays are
calibrated against D65 (same as BT.709 source) either way.
2014-02-26 23:05:20 +01:00
Niklas Haas 701c8c8254
vo_opengl: Add :icc-approx-gamma suboption to approximate BT.709 gamma
This uses the value of 1.95 as an approximation for the exact gamma
curve, which replicates the behavior of popular video software including
anything in the Apple ecosystem, as per issue #534.
2014-02-24 14:34:12 +01:00
nand 7d9fff9c6b vo_opengl: fix typo in gamma function's parameter
The correct value is 0.081, not 0.18. The scale factor also needed
slight adjustment due to the order of operations.
2014-02-10 22:11:13 +01:00
nand 257d9f1610 vo_opengl: use exactly the values defined by BT.709 for CMS
I could not see any difference whatsoever, but for usage with a 3DLUT
there's zero performance difference so we might as well follow the spec to
the letter.
2014-02-09 14:42:39 +01:00
wm4 a0e89daf49 gl_lcms: actually acquire mutex
Prevents race conditions (which can happen only in theory anyway).
2013-12-22 12:25:51 +01:00
wm4 eef36f03ea msg: rename mp_msg_log -> mp_msg
Same for companion functions.
2013-12-21 22:13:04 +01:00
wm4 ad2199128d path lookup functions: mp_msg conversions
There's a single mp_msg() in path.c, but all path lookup functions seem
to depend on it, so we get a rat-tail of stuff we have to change. This
is probably a good thing though, because we can have the path lookup
functions also access options, so we could allow overriding the default
config path, or ignore the MPV_HOME environment variable, and such
things.

Also take the chance to consistently add talloc_ctx parameters to the
path lookup functions.

Also, this change causes a big mess on configfiles.c. It's the same
issue: everything suddenly needs a (different) context argument. Make it
less wild by providing a mp_load_auto_profiles() function, which
isolates most of it to configfiles.c.
2013-12-21 21:43:17 +01:00
wm4 0335011f11 stream: mp_msg conversions
We also drop some slave mode stuff from stream_vcd.
2013-12-21 21:43:16 +01:00
wm4 9242c34fa2 m_option: add mp_log callback to OPT_STRING_VALIDATE options
And also convert a bunch of other code, especially ao_wasapi and
ao_portaudio.
2013-12-21 21:43:16 +01:00
wm4 212ce468d8 gl_lcms: use global lock to deal with crappy lcms2 message callback
lcms2 has a global message callback for error reporting. If you don't
set this, these error messages are silently thrown away. I think we
still want the error messages, so we have to do dumb stuff to avoid
clashes. This doesn't handle the case if another library in the same
process sets the message callback, but at least this should exclude
possible memory errors when running multiple instances of mpv.
2013-12-21 20:50:10 +01:00
wm4 c8268701d9 video/out: pass along global context
Will be needed for other parts (especially in gl_lcms.c).
2013-12-21 20:50:10 +01:00
wm4 0112143fda Split mpvcore/ into common/, misc/, bstr/ 2013-12-17 02:39:45 +01:00
wm4 eb15151705 Move options/config related files from mpvcore/ to options/
Since m_option.h and options.h are extremely often included, a lot of
files have to be changed.

Moving path.c/h to options/ is a bit questionable, but since this is
mainly about access to config files (which are also handled in
options/), it's probably ok.
2013-12-17 02:07:57 +01:00
wm4 683d7e88e4 Allow some options taking filenames to refer to mpv config dir
Add the mp_get_user_path() function, and make it expand special path
prefixes. Use it for some things in mpv which take filenames
(--input-config, --screenshot-template, opengl icc-profile suboption).

This allows accessing files in the mpv config dir without hardcoding the
config path by prefixing the path with ~~/. Details see manpage
additions.
2013-12-14 19:54:49 +01:00
Stefano Pigozzi 37388ebb0e configure: uniform the defines to #define HAVE_xxx (0|1)
The configure followed 5 different convetions of defines because the next guy
always wanted to introduce a new better way to uniform it[1]. For an
hypothetic feature 'hurr' you could have had:

  * #define HAVE_HURR 1   / #undef HAVE_DURR
  * #define HAVE_HURR     / #undef HAVE_DURR
  * #define CONFIG_HURR 1 / #undef CONFIG_DURR
  * #define HAVE_HURR 1   / #define HAVE_DURR 0
  * #define CONFIG_HURR 1 / #define CONFIG_DURR 0

All is now uniform and uses:
  * #define HAVE_HURR 1
  * #define HAVE_DURR 0

We like definining to 0 as opposed to `undef` bcause it can help spot typos
and is very helpful when doing big reorganizations in the code.

[1]: http://xkcd.com/927/ related
2013-11-03 21:59:54 +01:00
wm4 75e63ebb24 gl_lcms: mp_msg conversion
Have to deal with some dumb stuff in LittleCMS2's API: its error handler
is global.
2013-09-12 01:34:42 +02:00
Stefano Pigozzi 406241005e core: move contents to mpvcore (2/2)
Followup commit. Fixes all the files references.
2013-08-06 22:52:31 +02:00
wm4 e83cbde1a4 Fix some -Wshadow warnings
In general, this warning can hint to actual bugs. We don't enable it
yet, because it would conflict with some unmerged code, and we should
check with clang too (this commit was done by testing with gcc).
2013-07-23 00:45:23 +02:00
wm4 52c3eb6976 core: change open_stream and demux_open signature
This removes the dependency on DEMUXER_TYPE_* and the file_format
parameter from the stream open functions.

Remove some of the playlist handling code. It looks like this was
needed only for loading linked mov files with demux_mov (which was
removed long ago).

Delete a minor bit of dead network-related code from stream.c as well.
2013-07-12 21:56:40 +02:00
wm4 4f5e12136d stream: remove padding parameter from stream_read_complete()
Seems like a completely unnecessary complication. Instead, always add a
1 byte padding (could be extended if a caller needs it), and clear it.

Also add some documentation. There was some, but it was outdated and
incomplete.
2013-06-23 22:33:59 +02:00
wm4 624fe1736e gl_lcms: fix compilation when lcms2 is not available 2013-03-30 03:29:54 +01:00
wm4 6ef06aa145 vo_opengl: split into multiple files, convert to new option API
gl_video.c contains all rendering code, gl_lcms.c the .icc loader and
creation of 3D LUT (and all LittleCMS specific code). vo_opengl.c is
reduced to interfacing between the various parts.
2013-03-28 21:46:17 +01:00