mtk_rect.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2016 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
  12. */
  13. #include "mtk_rect.h"
  14. #include "mtk_log.h"
  15. void mtk_rect_make(struct mtk_rect *in, int left, int top, int width,
  16. int height)
  17. {
  18. in->x = left;
  19. in->y = top;
  20. in->width = width;
  21. in->height = height;
  22. }
  23. void mtk_rect_set(struct mtk_rect *in, int left, int top, int right, int bottom)
  24. {
  25. in->x = left;
  26. in->y = top;
  27. in->width = right - left + 1;
  28. in->height = bottom - top + 1;
  29. }
  30. void mtk_rect_join(const struct mtk_rect *in1, const struct mtk_rect *in2,
  31. struct mtk_rect *out)
  32. {
  33. int left = in1->x;
  34. int top = in1->y;
  35. int right = in1->x + in1->width - 1;
  36. int bottom = in1->y + in1->height - 1;
  37. int fLeft = in2->x;
  38. int fTop = in2->y;
  39. int fRight = in2->x + in2->width - 1;
  40. int fBottom = in2->y + in2->height - 1;
  41. int in2_x = in2->x;
  42. int in2_y = in2->y;
  43. int in2_w = in2->width;
  44. int in2_h = in2->height;
  45. /* do nothing if the params are empty */
  46. if (left > right || top > bottom) {
  47. mtk_rect_set(out, fLeft, fTop, fRight, fBottom);
  48. } else if (fLeft > fRight || fTop > fBottom) {
  49. /* if we are empty, just assign */
  50. mtk_rect_set(out, left, top, right, bottom);
  51. } else {
  52. if (left < fLeft)
  53. fLeft = left;
  54. if (top < fTop)
  55. fTop = top;
  56. if (right > fRight)
  57. fRight = right;
  58. if (bottom > fBottom)
  59. fBottom = bottom;
  60. mtk_rect_set(out, fLeft, fTop, fRight, fBottom);
  61. }
  62. DDPDBG("%s (%d,%d,%d,%d) & (%d,%d,%d,%d) to (%d,%d,%d,%d)\n", __func__,
  63. in1->x, in1->y, in1->width, in1->height, in2_x, in2_y, in2_w,
  64. in2_h, in2->x, in2->y, in2->width, in2->height);
  65. }