123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /*
- * Copyright (C) 2016 MediaTek Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See http://www.gnu.org/licenses/gpl-2.0.html for more details.
- */
- #include "mtk_rect.h"
- #include "mtk_log.h"
- void mtk_rect_make(struct mtk_rect *in, int left, int top, int width,
- int height)
- {
- in->x = left;
- in->y = top;
- in->width = width;
- in->height = height;
- }
- void mtk_rect_set(struct mtk_rect *in, int left, int top, int right, int bottom)
- {
- in->x = left;
- in->y = top;
- in->width = right - left + 1;
- in->height = bottom - top + 1;
- }
- void mtk_rect_join(const struct mtk_rect *in1, const struct mtk_rect *in2,
- struct mtk_rect *out)
- {
- int left = in1->x;
- int top = in1->y;
- int right = in1->x + in1->width - 1;
- int bottom = in1->y + in1->height - 1;
- int fLeft = in2->x;
- int fTop = in2->y;
- int fRight = in2->x + in2->width - 1;
- int fBottom = in2->y + in2->height - 1;
- int in2_x = in2->x;
- int in2_y = in2->y;
- int in2_w = in2->width;
- int in2_h = in2->height;
- /* do nothing if the params are empty */
- if (left > right || top > bottom) {
- mtk_rect_set(out, fLeft, fTop, fRight, fBottom);
- } else if (fLeft > fRight || fTop > fBottom) {
- /* if we are empty, just assign */
- mtk_rect_set(out, left, top, right, bottom);
- } else {
- if (left < fLeft)
- fLeft = left;
- if (top < fTop)
- fTop = top;
- if (right > fRight)
- fRight = right;
- if (bottom > fBottom)
- fBottom = bottom;
- mtk_rect_set(out, fLeft, fTop, fRight, fBottom);
- }
- DDPDBG("%s (%d,%d,%d,%d) & (%d,%d,%d,%d) to (%d,%d,%d,%d)\n", __func__,
- in1->x, in1->y, in1->width, in1->height, in2_x, in2_y, in2_w,
- in2_h, in2->x, in2->y, in2->width, in2->height);
- }
|