summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorkabeer khan <kabeer.khan@samsung.com>2015-02-11 17:30:49 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-02-11 17:30:54 +0100
commit46b9b23144ba6a95d619b1aa21ec326ea92303b6 (patch)
tree1fb951df8d0f01d8477352f42438c003326be1fe /src/modules
parent566eefd7d0e4ac70dca3f12b6ce99ae12bec7102 (diff)
evas: add image orient set/get API in software backend for now.
Summary: Added API's to rotate(0, 90, 180, 270), flip(horizontal, vertical, transpose, transverse) evas image object. Also added example to demonstrate this. Signed-off-by: kabeer khan <kabeer.khan@samsung.com> Reviewers: raster, stephenmhouston, cedric Subscribers: stephenmhouston, cedric Differential Revision: https://phab.enlightenment.org/D1950 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/evas/engines/software_generic/evas_engine.c341
1 files changed, 341 insertions, 0 deletions
diff --git a/src/modules/evas/engines/software_generic/evas_engine.c b/src/modules/evas/engines/software_generic/evas_engine.c
index a3b15b4dcc..58cbb23a60 100644
--- a/src/modules/evas/engines/software_generic/evas_engine.c
+++ b/src/modules/evas/engines/software_generic/evas_engine.c
@@ -57,6 +57,9 @@
57#define OSMESA_MAX_WIDTH 0x24 /* new in 4.0 */ 57#define OSMESA_MAX_WIDTH 0x24 /* new in 4.0 */
58#define OSMESA_MAX_HEIGHT 0x25 /* new in 4.0 */ 58#define OSMESA_MAX_HEIGHT 0x25 /* new in 4.0 */
59 59
60/* Required for orient */
61#define TILE 32
62
60 63
61typedef void (*OSMESAproc)(); 64typedef void (*OSMESAproc)();
62typedef struct osmesa_context *OSMesaContext; 65typedef struct osmesa_context *OSMesaContext;
@@ -1291,6 +1294,342 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data)
1291 return im; 1294 return im;
1292} 1295}
1293 1296
1297static void *
1298_image_flip_horizontal(void *data, Image_Entry *im)
1299{
1300 unsigned int *p1, *p2, tmp;
1301 DATA32 *image_data;
1302 int x, y, iw, ih;
1303 Image_Entry *im2;
1304
1305 iw = im->w;
1306 ih = im->h;
1307 image_data = evas_cache_image_pixels(im);
1308 for (y = 0; y < ih; y++)
1309 {
1310 p1 = image_data + (y * iw);
1311 p2 = image_data + ((y + 1) * iw) - 1;
1312 for (x = 0; x < (iw >> 1); x++)
1313 {
1314 tmp = *p1;
1315 *p1 = *p2;
1316 *p2 = tmp;
1317 p1++;
1318 p2--;
1319 }
1320 }
1321 im2 = eng_image_new_from_data(data, iw, ih, image_data,
1322 eng_image_alpha_get(data, im),
1323 eng_image_colorspace_get(data, im));
1324 return im2;
1325}
1326
1327static void *
1328_image_flip_vertical(void *data, Image_Entry *im)
1329{
1330 unsigned int *p1, *p2, tmp;
1331 DATA32 *image_data;
1332 int x, y, iw, ih;
1333 Image_Entry *im2;
1334
1335 iw = im->w;
1336 ih = im->h;
1337 image_data = evas_cache_image_pixels(im);
1338 for (y = 0; y < (ih >> 1); y++)
1339 {
1340 p1 = image_data + (y * iw);
1341 p2 = image_data + ((ih - 1 - y) * iw);
1342 for (x = 0; x < iw; x++)
1343 {
1344 tmp = *p1;
1345 *p1 = *p2;
1346 *p2 = tmp;
1347 p1++;
1348 p2++;
1349 }
1350 }
1351 im2 = eng_image_new_from_data(data, iw, ih, image_data,
1352 eng_image_alpha_get(data, im),
1353 eng_image_colorspace_get(data, im));
1354 return im2;
1355}
1356
1357static void *
1358_image_rotate_180(void *data, Image_Entry *im)
1359{
1360 unsigned int *p1, *p2, tmp;
1361 DATA32 *image_data;
1362 int x, hw, iw, ih;
1363 Image_Entry *im2;
1364
1365 iw = im->w;
1366 ih = im->h;
1367 image_data = evas_cache_image_pixels(im);
1368 if(!image_data) return im;
1369 hw = iw * ih;
1370 x = (hw / 2);
1371 p1 = image_data;
1372 p2 = image_data + hw - 1;
1373 for (; --x > 0; )
1374 {
1375 tmp = *p1;
1376 *p1 = *p2;
1377 *p2 = tmp;
1378 p1++;
1379 p2--;
1380 }
1381 im2 = eng_image_new_from_data(data, iw, ih, image_data,
1382 eng_image_alpha_get(data, im),
1383 eng_image_colorspace_get(data, im));
1384 return im2;
1385}
1386
1387# define GETDAT(neww, newh) \
1388 DATA32 *image_data, *image_data2; \
1389 int iw, ih, w, h; \
1390 Image_Entry *im2; \
1391 iw = im->w; \
1392 ih = im->h; \
1393 image_data = evas_cache_image_pixels(im); \
1394 if (!image_data) return im; \
1395 image_data2 = malloc(iw * ih * sizeof(int)); \
1396 if (!image_data2) { \
1397 return im; \
1398 } \
1399 memcpy(image_data2, image_data, iw * ih * sizeof(int)); \
1400 im = eng_image_new_from_data(data, iw, ih, image_data, \
1401 eng_image_alpha_get(data, im), \
1402 eng_image_colorspace_get(data, im)); \
1403 w = neww; h = newh; \
1404 image_data = evas_cache_image_pixels(im); \
1405
1406# define PUTDAT \
1407 im2 = eng_image_new_from_data(data, w, h, image_data, \
1408 eng_image_alpha_get(data, im), \
1409 eng_image_colorspace_get(data, im)); \
1410 im2 = eng_image_size_set(data, im2, w, h); \
1411 free(image_data2); \
1412 return im2; \
1413
1414static void *
1415_image_rotate_90(void *data, Image_Entry *im)
1416{
1417 GETDAT(ih, iw);
1418 int x, y, xx, yy, xx2, yy2;
1419 unsigned int *src, *dst;
1420
1421 for (y = 0; y < ih; y += TILE)
1422 {
1423 yy2 = y + TILE;
1424 if (yy2 > ih) yy2 = ih;
1425 for (x = 0; x < iw; x += TILE)
1426 {
1427 xx2 = x + TILE;
1428 if (xx2 > iw) xx2 = iw;
1429 for (yy = y; yy < yy2; yy++)
1430 {
1431 src = image_data2 + (yy * iw) + x;
1432 dst = image_data + (x * w) + (w - yy - 1);
1433 for (xx = x; xx < xx2; xx++)
1434 {
1435 *dst = *src;
1436 src++;
1437 dst += w;
1438 }
1439 }
1440 }
1441 }
1442 PUTDAT;
1443}
1444
1445static void *
1446_image_rotate_270(void *data, Image_Entry *im)
1447{
1448 GETDAT(ih, iw);
1449 int x, y, xx, yy, xx2, yy2;
1450 unsigned int *src, *dst;
1451
1452 for (y = 0; y < ih; y += TILE)
1453 {
1454 yy2 = y + TILE;
1455 if (yy2 > ih) yy2 = ih;
1456 for (x = 0; x < iw; x += TILE)
1457 {
1458 xx2 = x + TILE;
1459 if (xx2 > iw) xx2 = iw;
1460 for (yy = y; yy < yy2; yy++)
1461 {
1462 src = image_data2 + (yy * iw) + x;
1463 dst = image_data + ((h - x - 1) * w) + yy;
1464 for (xx = x; xx < xx2; xx++)
1465 {
1466 *dst = *src;
1467 src++;
1468 dst -= w;
1469 }
1470 }
1471 }
1472 }
1473 PUTDAT;
1474}
1475
1476static void *
1477_image_flip_transverse(void *data, Image_Entry *im)
1478{
1479 GETDAT(ih, iw);
1480 int x, y;
1481 unsigned int *src, *dst;
1482
1483 src = image_data2;
1484 for (y = 0; y < ih; y++)
1485 {
1486 dst = image_data + y;
1487 for (x = 0; x < iw; x++)
1488 {
1489 *dst = *src;
1490 src++;
1491 dst += w;
1492 }
1493 }
1494 PUTDAT;
1495}
1496
1497static void *
1498_image_flip_transpose(void *data, Image_Entry *im)
1499{
1500 GETDAT(ih, iw);
1501 int x, y;
1502 unsigned int *src, *dst;
1503
1504 src = image_data2 + (iw * ih) - 1;
1505 for (y = 0; y < ih; y++)
1506 {
1507 dst = image_data + y;
1508 for (x = 0; x < iw; x++)
1509 {
1510 *dst = *src;
1511 src--;
1512 dst += w;
1513 }
1514 }
1515 PUTDAT;
1516}
1517
1518#undef GETDAT
1519#undef PUTDAT
1520
1521static void *
1522eng_image_orient_set(void *data, void *image, Evas_Image_Orient orient)
1523{
1524 Image_Entry *im;
1525
1526 if (!image) return NULL;
1527 im = image;
1528 if (im->orient == orient) return im;
1529
1530 if ((im->orient >= EVAS_IMAGE_ORIENT_0) &&
1531 (im->orient <= EVAS_IMAGE_ORIENT_270) &&
1532 (orient >= EVAS_IMAGE_ORIENT_0) &&
1533 (orient <= EVAS_IMAGE_ORIENT_270))
1534 {
1535 // we are rotating from one anglee to another, so figure out delta
1536 // and apply that delta
1537 Evas_Image_Orient rot_delta = (4 + orient - im->orient) % 4;
1538 switch (rot_delta)
1539 {
1540 case EVAS_IMAGE_ORIENT_0:
1541 ERR("You shouldn't get this message, wrong orient value");
1542 break;
1543 case EVAS_IMAGE_ORIENT_90:
1544 im = _image_rotate_90(data, im);
1545 im->orient = orient;
1546 break;
1547 case EVAS_IMAGE_ORIENT_180:
1548 im = _image_rotate_180(data, im);
1549 im->orient = orient;
1550 break;
1551 case EVAS_IMAGE_ORIENT_270:
1552 im = _image_rotate_270(data, im);
1553 im->orient = orient;
1554 break;
1555 default:
1556 ERR("Wrong orient value");
1557 break;
1558 }
1559 }
1560 else if (((im->orient == EVAS_IMAGE_ORIENT_NONE) &&
1561 (orient == EVAS_IMAGE_FLIP_HORIZONTAL)) ||
1562 ((im->orient == EVAS_IMAGE_FLIP_HORIZONTAL) &&
1563 (orient == EVAS_IMAGE_ORIENT_NONE)))
1564 {
1565 // flip horizontally to get the new orientation
1566 im = _image_flip_horizontal(data, im);
1567 im->orient = orient;
1568 }
1569 else if (((im->orient == EVAS_IMAGE_ORIENT_NONE) &&
1570 (orient == EVAS_IMAGE_FLIP_VERTICAL)) ||
1571 ((im->orient == EVAS_IMAGE_FLIP_VERTICAL) &&
1572 (orient == EVAS_IMAGE_ORIENT_NONE)))
1573 {
1574 // flip vertically to get the new orientation
1575 im = _image_flip_vertical(data, im);
1576 im->orient = orient;
1577 }
1578 else
1579 {
1580 // generic solution - undo the previous orientation and then apply the
1581 // new one after that
1582 int i;
1583
1584 for (i = 0; i < 2; i++)
1585 {
1586 switch (im->orient)
1587 {
1588 case EVAS_IMAGE_ORIENT_0:
1589 break;
1590 case EVAS_IMAGE_ORIENT_90:
1591 if(i == 1) im = _image_rotate_90(data, im);
1592 else im = _image_rotate_270(data, im);
1593 break;
1594 case EVAS_IMAGE_ORIENT_180:
1595 im = _image_rotate_180(data, im);
1596 break;
1597 case EVAS_IMAGE_ORIENT_270:
1598 if(i == 1) im = _image_rotate_270(data, im);
1599 else im = _image_rotate_90(data, im);
1600 break;
1601 case EVAS_IMAGE_FLIP_HORIZONTAL:
1602 im = _image_flip_horizontal(data, im);
1603 break;
1604 case EVAS_IMAGE_FLIP_VERTICAL:
1605 im = _image_flip_vertical(data, im);
1606 break;
1607 case EVAS_IMAGE_FLIP_TRANSPOSE:
1608 im = _image_flip_transpose(data, im);
1609 break;
1610 case EVAS_IMAGE_FLIP_TRANSVERSE:
1611 im = _image_flip_transverse(data, im);
1612 break;
1613 default:
1614 ERR("Wrong orient value");
1615 break;
1616 }
1617 im->orient = orient;
1618 }
1619 }
1620 return im;
1621}
1622
1623static Evas_Image_Orient
1624eng_image_orient_get(void *data EINA_UNUSED, void *image)
1625{
1626 Image_Entry *im;
1627
1628 if (!image) return EVAS_IMAGE_ORIENT_NONE;
1629 im = image;
1630 return im->orient;
1631}
1632
1294static void 1633static void
1295eng_image_data_preload_request(void *data EINA_UNUSED, void *image, const Eo *target) 1634eng_image_data_preload_request(void *data EINA_UNUSED, void *image, const Eo *target)
1296{ 1635{
@@ -3158,6 +3497,8 @@ static Evas_Func func =
3158 eng_image_data_preload_cancel, 3497 eng_image_data_preload_cancel,
3159 eng_image_alpha_set, 3498 eng_image_alpha_set,
3160 eng_image_alpha_get, 3499 eng_image_alpha_get,
3500 eng_image_orient_set,
3501 eng_image_orient_get,
3161 eng_image_border_set, 3502 eng_image_border_set,
3162 eng_image_border_get, 3503 eng_image_border_get,
3163 eng_image_draw, 3504 eng_image_draw,