540 else if (!dst->format.premultiplied && src->format.premultiplied) |
539 else if (!dst->format.premultiplied && src->format.premultiplied) |
541 { |
540 { |
542 OWF_Image_UnpremultiplyAlpha(src); |
541 OWF_Image_UnpremultiplyAlpha(src); |
543 } |
542 } |
544 |
543 |
545 destination = (OWFuint8*) dst->data; |
|
546 #ifndef OWF_IMAGE_INTERNAL_PIXEL_IS_FLOAT |
544 #ifndef OWF_IMAGE_INTERNAL_PIXEL_IS_FLOAT |
547 widthBytes = OWF_Image_GetStride(src->width, &src->format, 0); |
545 widthBytes = OWF_Image_GetStride(src->width, &src->format, 0); |
548 #endif |
546 #endif |
549 |
547 |
550 for (countY = 0; countY < src->height; countY++) |
548 for (countY = 0; countY < src->height; countY++) |
551 { |
549 { |
|
550 OWFuint8* destination = (OWFuint8*) dst->data; |
|
551 destination += countY*dst->stride; |
552 dstPtr = (OWFuint32*) destination; |
552 dstPtr = (OWFuint32*) destination; |
553 destination += dst->stride; |
|
554 |
553 |
555 switch (dst->format.pixelFormat) |
554 switch (dst->format.pixelFormat) |
556 { |
555 { |
557 case OWF_IMAGE_ARGB8888: |
556 case OWF_IMAGE_ARGB8888: |
558 { |
557 { |
981 OWF_RECTANGLE* dstRect, |
980 OWF_RECTANGLE* dstRect, |
982 OWF_IMAGE* src, |
981 OWF_IMAGE* src, |
983 OWFfloat* srcRect) |
982 OWFfloat* srcRect) |
984 { |
983 { |
985 OWFint ox = 0, oy = 0; |
984 OWFint ox = 0, oy = 0; |
986 OWFfloat dx = 0.f, dy = 0.f; |
|
987 OWFint x, y; |
985 OWFint x, y; |
988 |
986 |
989 /* images must be valid */ |
987 /* images must be valid */ |
990 if (!((src != NULL) && (src->data != NULL) && |
988 if (!((src != NULL) && (src->data != NULL) && |
991 (dst != NULL) && (dst->data != NULL))) |
989 (dst != NULL) && (dst->data != NULL))) |
1007 if (src->pixelSize != dst->pixelSize) |
1005 if (src->pixelSize != dst->pixelSize) |
1008 { |
1006 { |
1009 return OWF_FALSE; |
1007 return OWF_FALSE; |
1010 } |
1008 } |
1011 |
1009 |
|
1010 #ifdef OWF_IMAGE_INTERNAL_PIXEL_IS_FLOAT |
|
1011 { |
|
1012 OWFfloat dx = 0.f, dy = 0.f; |
|
1013 |
1012 /* solve scaling ratios for image */ |
1014 /* solve scaling ratios for image */ |
1013 dx = (OWFfloat) srcRect[2] / (OWFfloat) dstRect->width; |
1015 dx = (OWFfloat) srcRect[2] / (OWFfloat) dstRect->width; |
1014 dy = (OWFfloat) srcRect[3] / (OWFfloat) dstRect->height; |
1016 dy = (OWFfloat) srcRect[3] / (OWFfloat) dstRect->height; |
1015 |
1017 |
1016 for (y = 0; y < dstRect->height; y++) |
1018 for (y = 0; y < dstRect->height; y++) |
1034 OWF_Image_SetPixel(dst, |
1036 OWF_Image_SetPixel(dst, |
1035 dstRect->x + x, |
1037 dstRect->x + x, |
1036 dstRect->y + y, |
1038 dstRect->y + y, |
1037 pixel); |
1039 pixel); |
1038 |
1040 |
1039 } |
1041 } |
1040 } |
1042 } |
|
1043 } |
|
1044 #else |
|
1045 if (srcRect[0] < 0 || (srcRect[0] + srcRect[2]) > src->width || |
|
1046 srcRect[1] < 0 || (srcRect[1] + srcRect[3]) > src->height) |
|
1047 { |
|
1048 /* Source rectangle out of bounds */ |
|
1049 return OWF_FALSE; |
|
1050 } |
|
1051 |
|
1052 if (dstRect->x < 0 || (dstRect->x + dstRect->width) > dst->width || |
|
1053 dstRect->y < 0 || (dstRect->y + dstRect->height) > dst->height) |
|
1054 { |
|
1055 /* Destination rectangle out of bounds */ |
|
1056 return OWF_FALSE; |
|
1057 } |
|
1058 |
|
1059 { |
|
1060 OWFint dxFix, dyFix; |
|
1061 OWFint xFixStart, yFix; |
|
1062 OWFuint32 *dstPtr, *srcLinePtr; |
|
1063 |
|
1064 /* Integer <-> 16.16 fixed point conversion macros */ |
|
1065 #define INT_TO_FIXED_PT(X) ((X) << 16) |
|
1066 #define FIXED_PT_TO_INT(X) ((X) >> 16) |
|
1067 |
|
1068 /* Calculate scaling factors in fixed point (with rounding). */ |
|
1069 dxFix = (OWFint)((srcRect[2] * INT_TO_FIXED_PT(1) + (dstRect->width >> 1)) / dstRect->width); |
|
1070 dyFix = (OWFint)((srcRect[3] * INT_TO_FIXED_PT(1) + (dstRect->height >> 1)) / dstRect->height); |
|
1071 |
|
1072 /* Calculate fixed point location in source, with half-pixel offset */ |
|
1073 xFixStart = (OWFint)(srcRect[0] * INT_TO_FIXED_PT(1) + (dxFix >> 1)); |
|
1074 yFix = (OWFint)(srcRect[1] * INT_TO_FIXED_PT(1) + (dyFix >> 1)); |
|
1075 |
|
1076 /* Initial target address. */ |
|
1077 dstPtr = (OWFuint32*)dst->data + dstRect->y * dst->width + dstRect->x; |
|
1078 |
|
1079 for (y = 0; y < dstRect->height; y++) |
|
1080 { |
|
1081 OWFint xFix = xFixStart; |
|
1082 |
|
1083 oy = FIXED_PT_TO_INT(yFix); |
|
1084 srcLinePtr = (OWFuint32*)src->data + oy * src->width; |
|
1085 |
|
1086 for (x = 0; x < dstRect->width; x++) |
|
1087 { |
|
1088 ox = FIXED_PT_TO_INT(xFix); |
|
1089 dstPtr[x] = srcLinePtr[ox]; |
|
1090 xFix += dxFix; |
|
1091 } |
|
1092 |
|
1093 dstPtr += dst->width; |
|
1094 yFix += dyFix; |
|
1095 } |
|
1096 } |
|
1097 #endif |
1041 return OWF_TRUE; |
1098 return OWF_TRUE; |
1042 } |
1099 } |
1043 |
1100 |
1044 /*----------------------------------------------------------------------------*/ |
1101 /*----------------------------------------------------------------------------*/ |
1045 OWF_API_CALL OWFboolean |
1102 OWF_API_CALL OWFboolean |
1647 /* inner loops */ |
1704 /* inner loops */ |
1648 switch (transparency) |
1705 switch (transparency) |
1649 { |
1706 { |
1650 case OWF_TRANSPARENCY_NONE: |
1707 case OWF_TRANSPARENCY_NONE: |
1651 { |
1708 { |
1652 #ifdef SLOW_CODE |
|
1653 /* |
1709 /* |
1654 rgb = src.rgb |
1710 rgb = src.rgb |
1655 alpha = 1 |
1711 alpha = 1 |
1656 */ |
1712 */ |
1657 BLENDER_INNER_LOOP_BEGIN; |
1713 BLENDER_INNER_LOOP_BEGIN; |
|
1714 #ifdef OWF_IMAGE_INTERNAL_PIXEL_IS_FLOAT |
1658 DR = SR; |
1715 DR = SR; |
1659 DG = SG; |
1716 DG = SG; |
1660 DB = SB; |
1717 DB = SB; |
1661 DA = OWF_FULLY_OPAQUE; |
1718 DA = OWF_FULLY_OPAQUE; |
|
1719 #else |
|
1720 *(OWFuint32*)dstPtr = *(OWFuint32*)srcPtr | ARGB8888_ALPHA_MASK; |
|
1721 #endif |
1662 BLENDER_INNER_LOOP_END_NO_MASK; |
1722 BLENDER_INNER_LOOP_END_NO_MASK; |
1663 #else |
|
1664 memcpy(dstPtr, srcPtr, drect.height*drect.width*4); |
|
1665 #endif |
|
1666 break; |
1723 break; |
1667 } |
1724 } |
1668 |
1725 |
1669 case OWF_TRANSPARENCY_GLOBAL_ALPHA: |
1726 case OWF_TRANSPARENCY_GLOBAL_ALPHA: |
1670 { |
1727 { |