# ThorVG: Saver

Saverfinal
ThorVG

A class for exporting a paint object into a specified file, from which to recover the paint data later. More...

## Public Member Functions

Result | background (std::unique_ptr< Paint > paint) noexcept
| Sets the base background content for the saved image. More...
Result | save (std::unique_ptr< Paint > paint, const std::string &path, bool compress=true) noexcept
| Exports the given `paint` data to the given `path`. More...
Result | save (std::unique_ptr< Animation > animation, const std::string &path, uint32_t quality=100, uint32_t fps=0) noexcept
| Export the provided animation data to the specified file path. More...
Result | sync () noexcept
| Guarantees that the saving task is finished. More...

## Static Public Member Functions

static std::unique_ptr< Saver > | gen () noexcept
| Creates a new Saver object. More...

## Detailed Description

A class for exporting a paint object into a specified file, from which to recover the paint data later.

ThorVG provides a feature for exporting & importing paint data. The Saver role is to export the paint data to a file. It's useful when you need to save the composed scene or image from a paint object and recreate it later.

The file format is decided by the extension name(i.e. "*.tvg") while the supported formats depend on the TVG packaging environment. If it doesn't support the file format, the save() method returns the `Result::NonSupport` result.

Once you export a paint to the file successfully, you can recreate it using the Picture class.

See also
  Picture::load()

Since
  0.5

## Member Function Documentation

## background()

Result background | ( | std::unique_ptr< Paint > | paint | ) |

noexcept

Sets the base background content for the saved image.

Parameters

  [in] | paint | The paint to be drawn as the background image for the saving paint.

Note
  Experimental API

## gen()

static std::unique_ptr<Saver> gen | ( |  | ) |

staticnoexcept

Creates a new Saver object.

Returns
  A new Saver object.

Since
  0.5

## save() [1/2]

Result save | ( | std::unique_ptr< Animation > | animation,
|  | const std::string & | path,
|  | uint32_t | quality = `100`,
|  | uint32_t | fps = `0`
| ) |  |

noexcept

Export the provided animation data to the specified file path.

This function exports the given animation data to the provided file path. You can also specify the desired frame rate in frames per second (FPS) by providing the fps parameter.

Parameters

  [in] | animation | The animation to be saved, including all associated properties.
  [in] | path | The path to the file where the animation will be saved.
  [in] | quality | The encoded quality level. `0` is the minimum, `100` is the maximum value(recommended).
  [in] | fps | The desired frames per second (FPS). For example, to encode data at 60 FPS, pass 60. Pass 0 to keep the original frame data.

Return values

  Result::InsufficientCondition | if there are ongoing resource-saving operations.
  Result::NonSupport | if an attempt is made to save the file with an unknown extension or in an unsupported format.
  Result::Unknown | if attempting to save an empty paint.

Note
  A higher frames per second (FPS) would result in a larger file size. It is recommended to use the default value.
  Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards.

See also
  Saver::sync()

Note
  Experimental API

## save() [2/2]

Result save | ( | std::unique_ptr< Paint > | paint,
|  | const std::string & | path,
|  | bool | compress = `true`
| ) |  |

noexcept

Exports the given `paint` data to the given `path`.

If the saver module supports any compression mechanism, it will optimize the data size. This might affect the encoding/decoding time in some cases. You can turn off the compression if you wish to optimize for speed.

Parameters

  [in] | paint | The paint to be saved with all its associated properties.
  [in] | path | A path to the file, in which the paint data is to be saved.
  [in] | compress | If `true` then compress data if possible.

Return values

  Result::InsufficientCondition | If currently saving other resources.
  Result::NonSupport | When trying to save a file with an unknown extension or in an unsupported format.
  Result::Unknown | In case an empty paint is to be saved.

Note
  Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call sync() afterwards.

See also
  Saver::sync()

Since
  0.5

## sync()

Result sync | ( |  | ) |

noexcept

Guarantees that the saving task is finished.

The behavior of the Saver works on a sync/async basis, depending on the threading setting of the Initializer. Thus, if you wish to have a benefit of it, you must call sync() after the save() in the proper delayed time. Otherwise, you can call sync() immediately.

Note
  The asynchronous tasking is dependent on the Saver module implementation.

See also
  Saver::save()

Since
  0.5