📄 pixops.c
字号:
r += ta * q[0]; g += ta * q[1]; b += ta * q[2]; a += ta; q += src_bytes_per_pixel; } } if (dest_has_alpha) { unsigned int w0 = a - (a >> 8); unsigned int w1 = ((0xff0000 - a) >> 8) * dest[3]; unsigned int w = w0 + w1; if (w != 0) { dest[0] = (r - (r >> 8) + w1 * dest[0]) / w; dest[1] = (g - (g >> 8) + w1 * dest[1]) / w; dest[2] = (b - (b >> 8) + w1 * dest[2]) / w; dest[3] = w / 0xff00; } else { dest[0] = 0; dest[1] = 0; dest[2] = 0; dest[3] = 0; } } else { dest[0] = (r + (0xff0000 - a) * dest[0]) / 0xff0000; dest[1] = (g + (0xff0000 - a) * dest[1]) / 0xff0000; dest[2] = (b + (0xff0000 - a) * dest[2]) / 0xff0000; } dest += dest_bytes_per_pixel; x += x_step; } return dest;}static uint8 *composite_line_22_4a4 (int *weights, int n_x, int n_y, uint8 *dest, int dest_x, uint8 *dest_end, int dest_bytes_per_pixel, int dest_depth, int dest_has_alpha, uint8 **src, int src_bytes_per_pixel, int src_depth, uint32 *src_colormap, boolean src_has_alpha, int x_init, int x_step, int src_width, int check_size, uint32 color1, uint32 color2){ int x = x_init; uint8 *src0 = src[0]; uint8 *src1 = src[1]; return_val_if_fail (src_bytes_per_pixel != 3, dest); return_val_if_fail (src_has_alpha, dest); while (dest < dest_end) { int x_scaled = x >> SCALE_SHIFT; unsigned int r, g, b, a, ta; int *pixel_weights; uint8 *q0, *q1; int w1, w2, w3, w4; q0 = src0 + x_scaled * 4; q1 = src1 + x_scaled * 4; pixel_weights = (int *)((char *)weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS - 4)) & (SUBSAMPLE_MASK << 4))); w1 = pixel_weights[0]; w2 = pixel_weights[1]; w3 = pixel_weights[2]; w4 = pixel_weights[3]; a = w1 * q0[3]; r = a * q0[0]; g = a * q0[1]; b = a * q0[2]; ta = w2 * q0[7]; r += ta * q0[4]; g += ta * q0[5]; b += ta * q0[6]; a += ta; ta = w3 * q1[3]; r += ta * q1[0]; g += ta * q1[1]; b += ta * q1[2]; a += ta; ta = w4 * q1[7]; r += ta * q1[4]; g += ta * q1[5]; b += ta * q1[6]; a += ta; dest[0] = ((0xff0000 - a) * dest[0] + r) >> 24; dest[1] = ((0xff0000 - a) * dest[1] + g) >> 24; dest[2] = ((0xff0000 - a) * dest[2] + b) >> 24; dest[3] = a >> 16; dest += 4; x += x_step; } return dest;}#ifdef USE_MMXstatic uint8 *composite_line_22_4a4_mmx_stub (int *weights, int n_x, int n_y, uint8 *dest, int dest_x, uint8 *dest_end, int dest_bytes_per_pixel, int dest_depth, int dest_has_alpha, uint8 **src, int src_bytes_per_pixel, int src_depth, uint32 *src_colormap, boolean src_has_alpha, int x_init, int x_step, int src_width, int check_size, uint32 color1, uint32 color2){ uint32 mmx_weights[16][8]; int j; for (j=0; j<16; j++) { mmx_weights[j][0] = 0x00010001 * (weights[4*j] >> 8); mmx_weights[j][1] = 0x00010001 * (weights[4*j] >> 8); mmx_weights[j][2] = 0x00010001 * (weights[4*j + 1] >> 8); mmx_weights[j][3] = 0x00010001 * (weights[4*j + 1] >> 8); mmx_weights[j][4] = 0x00010001 * (weights[4*j + 2] >> 8); mmx_weights[j][5] = 0x00010001 * (weights[4*j + 2] >> 8); mmx_weights[j][6] = 0x00010001 * (weights[4*j + 3] >> 8); mmx_weights[j][7] = 0x00010001 * (weights[4*j + 3] >> 8); } return pixops_composite_line_22_4a4_mmx (mmx_weights, dest, src[0], src[1], x_step, dest_end, x_init);}#endif /* USE_MMX */static voidcomposite_pixel_color (uint8 *dest, int dest_x, int dest_bytes_per_pixel, int dest_depth, int dest_has_alpha, int src_has_alpha, int check_size, uint32 color1, uint32 color2, uint r, uint g, uint b, uint a){ int dest_r, dest_g, dest_b; int check_shift = get_check_shift (check_size); if ((dest_x >> check_shift) & 1) { dest_r = (color2 & 0xff0000) >> 16; dest_g = (color2 & 0xff00) >> 8; dest_b = color2 & 0xff; } else { dest_r = (color1 & 0xff0000) >> 16; dest_g = (color1 & 0xff00) >> 8; dest_b = color1 & 0xff; } dest[0] = ((0xff0000 - a) * dest_r + r) >> 24; dest[1] = ((0xff0000 - a) * dest_g + g) >> 24; dest[2] = ((0xff0000 - a) * dest_b + b) >> 24; if (dest_has_alpha) dest[3] = 0xff; else if (dest_bytes_per_pixel == 4) dest[3] = a >> 16;}static uint8 *composite_line_color (int *weights, int n_x, int n_y, uint8 *dest, int dest_x, uint8 *dest_end, int dest_bytes_per_pixel, int dest_depth, int dest_has_alpha, uint8 **src, int src_bytes_per_pixel, int src_depth, uint32 *src_colormap, boolean src_has_alpha, int x_init, int x_step, int src_width, int check_size, uint32 color1, uint32 color2){ int x = x_init; int i, j; int check_shift = get_check_shift (check_size); int dest_r1, dest_g1, dest_b1; int dest_r2, dest_g2, dest_b2; return_val_if_fail (check_size != 0, dest); dest_r1 = (color1 & 0xff0000) >> 16; dest_g1 = (color1 & 0xff00) >> 8; dest_b1 = color1 & 0xff; dest_r2 = (color2 & 0xff0000) >> 16; dest_g2 = (color2 & 0xff00) >> 8; dest_b2 = color2 & 0xff; while (dest < dest_end) { int x_scaled = x >> SCALE_SHIFT; unsigned int r = 0, g = 0, b = 0, a = 0; int *pixel_weights; pixel_weights = weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * n_x * n_y; for (i=0; i<n_y; i++) { uint8 *q = src[i] + x_scaled * src_bytes_per_pixel; int *line_weights = pixel_weights + n_x * i; for (j=0; j<n_x; j++) { unsigned int ta; if (src_has_alpha) ta = q[3] * line_weights[j]; else ta = 0xff * line_weights[j]; r += ta * q[0]; g += ta * q[1]; b += ta * q[2]; a += ta; q += src_bytes_per_pixel; } } if ((dest_x >> check_shift) & 1) { dest[0] = ((0xff0000 - a) * dest_r2 + r) >> 24; dest[1] = ((0xff0000 - a) * dest_g2 + g) >> 24; dest[2] = ((0xff0000 - a) * dest_b2 + b) >> 24; } else { dest[0] = ((0xff0000 - a) * dest_r1 + r) >> 24; dest[1] = ((0xff0000 - a) * dest_g1 + g) >> 24; dest[2] = ((0xff0000 - a) * dest_b1 + b) >> 24; } if (dest_has_alpha) dest[3] = 0xff; else if (dest_bytes_per_pixel == 4) dest[3] = a >> 16; dest += dest_bytes_per_pixel; x += x_step; dest_x++; } return dest;}#ifdef USE_MMXstatic uint8 *composite_line_color_22_4a4_mmx_stub (int *weights, int n_x, int n_y, uint8 *dest, int dest_x, uint8 *dest_end, int dest_bytes_per_pixel, int dest_depth, int dest_has_alpha, uint8 **src, int src_bytes_per_pixel, int src_depth, uint32 *src_colormap, boolean src_has_alpha, int x_init, int x_step, int src_width, int check_size, uint32 color1, uint32 color2){ uint32 mmx_weights[16][8]; int check_shift = get_check_shift (check_size); int colors[4]; int j; for (j=0; j<16; j++) { mmx_weights[j][0] = 0x00010001 * (weights[4*j] >> 8); mmx_weights[j][1] = 0x00010001 * (weights[4*j] >> 8); mmx_weights[j][2] = 0x00010001 * (weights[4*j + 1] >> 8); mmx_weights[j][3] = 0x00010001 * (weights[4*j + 1] >> 8); mmx_weights[j][4] = 0x00010001 * (weights[4*j + 2] >> 8); mmx_weights[j][5] = 0x00010001 * (weights[4*j + 2] >> 8); mmx_weights[j][6] = 0x00010001 * (weights[4*j + 3] >> 8); mmx_weights[j][7] = 0x00010001 * (weights[4*j + 3] >> 8); } colors[0] = (color1 & 0xff00) << 8 | (color1 & 0xff); colors[1] = (color1 & 0xff0000) >> 16; colors[2] = (color2 & 0xff00) << 8 | (color2 & 0xff); colors[3] = (color2 & 0xff0000) >> 16; return pixops_composite_line_color_22_4a4_mmx (mmx_weights, dest, src[0], src[1], x_step, dest_end, x_init, dest_x, check_shift, colors);}#endif /* USE_MMX */static voidscale_pixel (uint8 *dest, int dest_x, int dest_bytes_per_pixel, int dest_depth, int dest_has_alpha, int src_has_alpha, int check_size, uint32 color1, uint32 color2, uint r, uint g, uint b, uint a){ uint32 p; if (src_has_alpha) { if (a) { ((uint8 *) &p)[0] = r / a; ((uint8 *) &p)[1] = g / a; ((uint8 *) &p)[2] = b / a; ((uint8 *) &p)[3] = a >> 16; } else { ((uint8 *) &p)[0] = 0; ((uint8 *) &p)[1] = 0; ((uint8 *) &p)[2] = 0; ((uint8 *) &p)[3] = 0; } } else { ((uint8 *) &p)[0] = (r + 0xffffff) >> 24; ((uint8 *) &p)[1] = (g + 0xffffff) >> 24; ((uint8 *) &p)[2] = (b + 0xffffff) >> 24; if (dest_has_alpha) ((uint8 *) &p)[3] = 0xff; } store_pixel (dest, dest_bytes_per_pixel, dest_depth, p);}static uint8 *scale_line (int *weights, int n_x, int n_y, uint8 *dest, int dest_x, uint8 *dest_end, int dest_bytes_per_pixel, int dest_depth, int dest_has_alpha, uint8 **src, int src_bytes_per_pixel, int src_depth, uint32 *src_colormap, boolean src_has_alpha, int x_init, int x_step, int src_width, int check_size, uint32 color1, uint32 color2){ int x = x_init; int i, j; int src_bppdepth = BPPDEPTH(src_bytes_per_pixel << 3, src_depth); while (dest < dest_end) { int x_scaled = x >> SCALE_SHIFT; int *pixel_weights; uint32 p; pixel_weights = weights + ((x >> (SCALE_SHIFT - SUBSAMPLE_BITS)) & SUBSAMPLE_MASK) * n_x * n_y; if (src_has_alpha) { unsigned int r = 0, g = 0, b = 0, a = 0; for (i=0; i<n_y; i++) { uint8 *q = src[i] + x_scaled * src_bytes_per_pixel; int *line_weights = pixel_weights + n_x * i; for (j=0; j<n_x; j++) { unsigned int ta; ta = q[3] * line_weights[j]; r += ta * q[0]; g += ta * q[1]; b += ta * q[2]; a += ta; q += src_bytes_per_pixel; } } if (a) { ((uint8 *) &p)[0] = r / a; ((uint8 *) &p)[1] = g / a; ((uint8 *) &p)[2] = b / a; ((uint8 *) &p)[3] = a >> 16; } else { ((uint8 *) &p)[0] = 0; ((uint8 *) &p)[1] = 0; ((uint8 *) &p)[2] = 0; ((uint8 *) &p)[3] = 0; } } else { unsigned int r = 0, g = 0, b = 0; for (i=0; i<n_y; i++) { uint8 *q = src[i] + x_scaled * src_bytes_per_pixel; int *line_weights = pixel_weights + n_x * i; for (j=0; j<n_x; j++) { unsigned int ta = line_weights[j]; uint32 tp; tp = load_pixel (q, src_bytes_per_pixel, src_depth, src_colormap); r += ta * ((uint8 *) &tp)[0]; g += ta * ((uint8 *) &tp)[1]; b += ta * ((uint8 *) &tp)[2]; q += src_bytes_per_pixel; } } ((uint8 *) &p)[0] = (r + 0xffff) >> 16; ((uint8 *) &p)[1] = (g + 0xffff) >> 16; ((uint8 *) &p)[2] = (b + 0xffff) >> 16; if (dest_has_alpha) ((uint8 *) &p)[3] = 0xff; } store_pixel (dest, dest_bytes_per_pixel, dest_depth, p); dest += dest_bytes_per_pixel; x += x_step; } return dest;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -