data_media_rotation.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "data/data_media_rotation.h"
  8. namespace Data {
  9. namespace {
  10. [[nodiscard]] int NormalizeRotation(int rotation) {
  11. const auto result = rotation
  12. - ((rotation / 360) - ((rotation < 0) ? 1 : 0)) * 360;
  13. Ensures(result >= 0 && result < 360);
  14. return result;
  15. }
  16. } // namespace
  17. void MediaRotation::set(not_null<PhotoData*> photo, int rotation) {
  18. if (rotation % 360) {
  19. _photoRotations[photo] = NormalizeRotation(rotation);
  20. } else {
  21. _photoRotations.remove(photo);
  22. }
  23. }
  24. int MediaRotation::get(not_null<PhotoData*> photo) const {
  25. const auto i = _photoRotations.find(photo);
  26. return (i != end(_photoRotations)) ? i->second : 0;
  27. }
  28. void MediaRotation::set(not_null<DocumentData*> document, int rotation) {
  29. if (rotation % 360) {
  30. _documentRotations[document] = NormalizeRotation(rotation);
  31. } else {
  32. _documentRotations.remove(document);
  33. }
  34. }
  35. int MediaRotation::get(not_null<DocumentData*> document) const {
  36. const auto i = _documentRotations.find(document);
  37. return (i != end(_documentRotations)) ? i->second : 0;
  38. }
  39. } // namespace Data