Lines Matching +full:left +full:- +full:shift
47 #include "vnc-enc-tight.h"
48 #include "vnc-palette.h"
119 if (vs->tight->type != VNC_ENCODING_TIGHT_PNG) { in tight_can_send_png_rect()
123 if (surface_bytes_per_pixel(vs->vd->ds) == 1 || in tight_can_send_png_rect()
124 vs->client_pf.bytes_per_pixel == 1) { in tight_can_send_png_rect()
145 int pix, left[3]; in tight_detect_smooth_image24() local
147 unsigned char *buf = vs->tight->tight.buffer; in tight_detect_smooth_image24()
150 * If client is big-endian, color samples begin from the second in tight_detect_smooth_image24()
151 * byte (offset 1) of a 32-bit pixel value. in tight_detect_smooth_image24()
153 off = vs->client_endian == G_BIG_ENDIAN ? 1 : 0; in tight_detect_smooth_image24()
158 for (d = 0; d < h - y && d < w - x - VNC_TIGHT_DETECT_SUBROW_WIDTH; in tight_detect_smooth_image24()
161 left[c] = buf[((y+d)*w+x+d)*4+off+c] & 0xFF; in tight_detect_smooth_image24()
166 stats[abs(pix - left[c])]++; in tight_detect_smooth_image24()
167 left[c] = pix; in tight_detect_smooth_image24()
193 if (stats[c] == 0 || stats[c] > stats[c-1] * 2) { in tight_detect_smooth_image24()
200 errors /= (pixels * 3 - stats[0]); in tight_detect_smooth_image24()
211 int max[3], shift[3]; \
216 int sample, sum, left[3]; \
218 unsigned char *buf = vs->tight->tight.buffer; \
223 max[0] = vs->client_pf.rmax; \
224 max[1] = vs->client_pf.gmax; \
225 max[2] = vs->client_pf.bmax; \
226 shift[0] = vs->client_pf.rshift; \
227 shift[1] = vs->client_pf.gshift; \
228 shift[2] = vs->client_pf.bshift; \
234 for (d = 0; d < h - y && \
235 d < w - x - VNC_TIGHT_DETECT_SUBROW_WIDTH; d++) { \
241 left[c] = (int)(pix >> shift[c] & max[c]); \
251 sample = (int)(pix >> shift[c] & max[c]); \
252 sum += abs(sample - left[c]); \
253 left[c] = sample; \
280 if (stats[c] == 0 || stats[c] > stats[c-1] * 2) { \
287 errors /= (pixels - stats[0]); \
299 int compression = vs->tight->compression; in tight_detect_smooth_image()
300 int quality = vs->tight->quality; in tight_detect_smooth_image()
302 if (!vs->vd->lossy) { in tight_detect_smooth_image()
306 if (surface_bytes_per_pixel(vs->vd->ds) == 1 || in tight_detect_smooth_image()
307 vs->client_pf.bytes_per_pixel == 1 || in tight_detect_smooth_image()
312 if (vs->tight->quality != (uint8_t)-1) { in tight_detect_smooth_image()
322 if (vs->client_pf.bytes_per_pixel == 4) { in tight_detect_smooth_image()
323 if (vs->tight->pixel24) { in tight_detect_smooth_image()
325 if (vs->tight->quality != (uint8_t)-1) { in tight_detect_smooth_image()
335 if (quality != (uint8_t)-1) { in tight_detect_smooth_image()
355 data = (uint##bpp##_t *)vs->tight->tight.buffer; \
426 max = count / tight_conf[vs->tight->compression].idx_max_colors_divisor; in tight_fill_palette()
428 count >= tight_conf[vs->tight->compression].mono_min_rect_size) { in tight_fill_palette()
435 switch (vs->client_pf.bytes_per_pixel) { in tight_fill_palette()
475 if (idx == (uint8_t)-1) { \
480 rep--; \
499 aligned_width = w - w % 8; \
544 * ``Gradient'' filter for 24-bit color samples.
546 * Color components assumed to be byte-aligned.
554 int shift[3]; in tight_filter_gradient24() local
556 int here[3], upper[3], left[3], upperleft[3]; in tight_filter_gradient24() local
561 memset(vs->tight->gradient.buffer, 0, w * 3 * sizeof(int)); in tight_filter_gradient24()
564 shift[0] = vs->client_pf.rshift; in tight_filter_gradient24()
565 shift[1] = vs->client_pf.gshift; in tight_filter_gradient24()
566 shift[2] = vs->client_pf.bshift; in tight_filter_gradient24()
568 shift[0] = 24 - vs->client_pf.rshift; in tight_filter_gradient24()
569 shift[1] = 24 - vs->client_pf.gshift; in tight_filter_gradient24()
570 shift[2] = 24 - vs->client_pf.bshift; in tight_filter_gradient24()
578 prev = (int *)vs->tight->gradient.buffer; in tight_filter_gradient24()
583 left[c] = here[c]; in tight_filter_gradient24()
585 here[c] = (int)(pix32 >> shift[c] & 0xFF); in tight_filter_gradient24()
588 prediction = left[c] + upper[c] - upperleft[c]; in tight_filter_gradient24()
594 *buf++ = (char)(here[c] - prediction); in tight_filter_gradient24()
613 int max[3], shift[3]; \
614 int here[3], upper[3], left[3], upperleft[3]; \
618 memset(vs->tight->gradient.buffer, 0, w * 3 * sizeof(int)); \
622 max[0] = vs->client_pf.rmax; \
623 max[1] = vs->client_pf.gmax; \
624 max[2] = vs->client_pf.bmax; \
625 shift[0] = vs->client_pf.rshift; \
626 shift[1] = vs->client_pf.gshift; \
627 shift[2] = vs->client_pf.bshift; \
634 prev = (int *)vs->tight->gradient.buffer; \
643 left[c] = here[c]; \
645 here[c] = (int)(pix >> shift[c] & max[c]); \
648 prediction = left[c] + upper[c] - upperleft[c]; \
654 diff |= ((here[c] - prediction) & max[c]) \
655 << shift[c]; \
670 * set to non-zero, then also check that its color equals to the
679 VncDisplay *vd = vs->vd; in check_solid_tile32()
723 dh = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, y + h - dy); in find_best_solid_area()
731 dw = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, x + w_prev - dx); in find_best_solid_area()
739 w_prev = dx - x; in find_best_solid_area()
740 if (w_prev * (dy + dh - y) > w_best * h_best) { in find_best_solid_area()
742 h_best = dy + dh - y; in find_best_solid_area()
757 for ( cy = *y_ptr - 1; in extend_solid_area()
759 cy-- ); in extend_solid_area()
760 *h_ptr += *y_ptr - (cy + 1); in extend_solid_area()
768 *h_ptr += cy - (*y_ptr + *h_ptr); in extend_solid_area()
770 /* ... to the left. */ in extend_solid_area()
771 for ( cx = *x_ptr - 1; in extend_solid_area()
773 cx-- ); in extend_solid_area()
774 *w_ptr += *x_ptr - (cx + 1); in extend_solid_area()
782 *w_ptr += cx - (*x_ptr + *w_ptr); in extend_solid_area()
788 z_streamp zstream = &vs->tight->stream[stream_id]; in tight_init_stream()
790 if (zstream->opaque == NULL) { in tight_init_stream()
794 VNC_DEBUG("VNC: TIGHT: opaque = %p | vs = %p\n", zstream->opaque, vs); in tight_init_stream()
795 zstream->zalloc = vnc_zlib_zalloc; in tight_init_stream()
796 zstream->zfree = vnc_zlib_zfree; in tight_init_stream()
803 return -1; in tight_init_stream()
806 vs->tight->levels[stream_id] = level; in tight_init_stream()
807 zstream->opaque = vs; in tight_init_stream()
810 if (vs->tight->levels[stream_id] != level) { in tight_init_stream()
812 return -1; in tight_init_stream()
814 vs->tight->levels[stream_id] = level; in tight_init_stream()
827 buf[bytes-1] |= 0x80; in tight_send_compact_size()
830 buf[bytes-1] |= 0x80; in tight_send_compact_size()
842 z_streamp zstream = &vs->tight->stream[stream_id]; in tight_compress_data()
846 vnc_write(vs, vs->tight->tight.buffer, vs->tight->tight.offset); in tight_compress_data()
851 return -1; in tight_compress_data()
855 buffer_reserve(&vs->tight->zlib, bytes + 64); in tight_compress_data()
858 zstream->next_in = vs->tight->tight.buffer; in tight_compress_data()
859 zstream->avail_in = vs->tight->tight.offset; in tight_compress_data()
860 zstream->next_out = vs->tight->zlib.buffer + vs->tight->zlib.offset; in tight_compress_data()
861 zstream->avail_out = vs->tight->zlib.capacity - vs->tight->zlib.offset; in tight_compress_data()
862 previous_out = zstream->avail_out; in tight_compress_data()
863 zstream->data_type = Z_BINARY; in tight_compress_data()
868 return -1; in tight_compress_data()
871 vs->tight->zlib.offset = vs->tight->zlib.capacity - zstream->avail_out; in tight_compress_data()
873 bytes = previous_out - zstream->avail_out; in tight_compress_data()
876 vnc_write(vs, vs->tight->zlib.buffer, bytes); in tight_compress_data()
878 buffer_reset(&vs->tight->zlib); in tight_compress_data()
894 if (vs->client_endian == G_BYTE_ORDER) { in tight_pack24()
895 rshift = vs->client_pf.rshift; in tight_pack24()
896 gshift = vs->client_pf.gshift; in tight_pack24()
897 bshift = vs->client_pf.bshift; in tight_pack24()
899 rshift = 24 - vs->client_pf.rshift; in tight_pack24()
900 gshift = 24 - vs->client_pf.gshift; in tight_pack24()
901 bshift = 24 - vs->client_pf.bshift; in tight_pack24()
908 while (count--) { in tight_pack24()
930 if (vs->tight->pixel24) { in send_full_color_rect()
931 tight_pack24(vs, vs->tight->tight.buffer, w * h, in send_full_color_rect()
932 &vs->tight->tight.offset); in send_full_color_rect()
935 bytes = vs->client_pf.bytes_per_pixel; in send_full_color_rect()
939 tight_conf[vs->tight->compression].raw_zlib_level, in send_full_color_rect()
951 if (vs->tight->pixel24) { in send_solid_rect()
952 tight_pack24(vs, vs->tight->tight.buffer, 1, &vs->tight->tight.offset); in send_solid_rect()
955 bytes = vs->client_pf.bytes_per_pixel; in send_solid_rect()
958 vnc_write(vs, vs->tight->tight.buffer, bytes); in send_solid_rect()
967 int level = tight_conf[vs->tight->compression].mono_zlib_level; in send_mono_rect()
972 int bpp = vs->client_pf.bytes_per_pixel * 8; in send_mono_rect()
989 switch (vs->client_pf.bytes_per_pixel) { in send_mono_rect()
995 if (vs->tight->pixel24) { in send_mono_rect()
1000 tight_encode_mono_rect32(vs->tight->tight.buffer, w, h, bg, fg); in send_mono_rect()
1009 tight_encode_mono_rect16(vs->tight->tight.buffer, w, h, bg, fg); in send_mono_rect()
1018 tight_encode_mono_rect8(vs->tight->tight.buffer, w, h, bg, fg); in send_mono_rect()
1022 vs->tight->tight.offset = bytes; in send_mono_rect()
1039 VncState *vs = priv->vs; in write_palette()
1040 uint32_t bytes = vs->client_pf.bytes_per_pixel; in write_palette()
1043 ((uint32_t*)priv->header)[idx] = color; in write_palette()
1045 ((uint16_t*)priv->header)[idx] = color; in write_palette()
1052 int level = tight_conf[vs->tight->compression].gradient_zlib_level; in send_gradient_rect()
1055 if (vs->client_pf.bytes_per_pixel == 1) { in send_gradient_rect()
1062 buffer_reserve(&vs->tight->gradient, w * 3 * sizeof(int)); in send_gradient_rect()
1064 if (vs->tight->pixel24) { in send_gradient_rect()
1065 tight_filter_gradient24(vs, vs->tight->tight.buffer, w, h); in send_gradient_rect()
1067 } else if (vs->client_pf.bytes_per_pixel == 4) { in send_gradient_rect()
1068 tight_filter_gradient32(vs, (uint32_t *)vs->tight->tight.buffer, w, h); in send_gradient_rect()
1071 tight_filter_gradient16(vs, (uint16_t *)vs->tight->tight.buffer, w, h); in send_gradient_rect()
1075 buffer_reset(&vs->tight->gradient); in send_gradient_rect()
1078 vs->tight->tight.offset = bytes; in send_gradient_rect()
1089 int level = tight_conf[vs->tight->compression].idx_zlib_level; in send_palette_rect()
1103 vnc_write_u8(vs, colors - 1); in send_palette_rect()
1105 switch (vs->client_pf.bytes_per_pixel) { in send_palette_rect()
1112 old_offset = vs->output.offset; in send_palette_rect()
1116 if (vs->tight->pixel24) { in send_palette_rect()
1117 tight_pack24(vs, vs->output.buffer + old_offset, colors, &offset); in send_palette_rect()
1118 vs->output.offset = old_offset + offset; in send_palette_rect()
1121 tight_encode_indexed_rect32(vs->tight->tight.buffer, w * h, palette); in send_palette_rect()
1132 tight_encode_indexed_rect16(vs->tight->tight.buffer, w * h, palette); in send_palette_rect()
1136 return -1; /* No palette for 8bits colors */ in send_palette_rect()
1139 vs->tight->tight.offset = bytes; in send_palette_rect()
1157 VncState *vs = cinfo->client_data; in jpeg_init_destination()
1158 Buffer *buffer = &vs->tight->jpeg; in jpeg_init_destination()
1160 cinfo->dest->next_output_byte = (JOCTET *)buffer->buffer + buffer->offset; in jpeg_init_destination()
1161 cinfo->dest->free_in_buffer = (size_t)(buffer->capacity - buffer->offset); in jpeg_init_destination()
1167 VncState *vs = cinfo->client_data; in jpeg_empty_output_buffer()
1168 Buffer *buffer = &vs->tight->jpeg; in jpeg_empty_output_buffer()
1170 buffer->offset = buffer->capacity; in jpeg_empty_output_buffer()
1179 VncState *vs = cinfo->client_data; in jpeg_term_destination()
1180 Buffer *buffer = &vs->tight->jpeg; in jpeg_term_destination()
1182 buffer->offset = buffer->capacity - cinfo->dest->free_in_buffer; in jpeg_term_destination()
1195 if (surface_bytes_per_pixel(vs->vd->ds) == 1) { in send_jpeg_rect()
1199 buffer_reserve(&vs->tight->jpeg, 2048); in send_jpeg_rect()
1224 qemu_pixman_linebuf_fill(linebuf, vs->vd->server, w, x, y + dy); in send_jpeg_rect()
1234 tight_send_compact_size(vs, vs->tight->jpeg.offset); in send_jpeg_rect()
1235 vnc_write(vs, vs->tight->jpeg.buffer, vs->tight->jpeg.offset); in send_jpeg_rect()
1236 buffer_reset(&vs->tight->jpeg); in send_jpeg_rect()
1249 VncState *vs = priv->vs; in write_png_palette()
1250 png_colorp color = &priv->png_palette[idx]; in write_png_palette()
1252 if (vs->tight->pixel24) in write_png_palette()
1254 color->red = (pix >> vs->client_pf.rshift) & vs->client_pf.rmax; in write_png_palette()
1255 color->green = (pix >> vs->client_pf.gshift) & vs->client_pf.gmax; in write_png_palette()
1256 color->blue = (pix >> vs->client_pf.bshift) & vs->client_pf.bmax; in write_png_palette()
1262 red = (pix >> vs->client_pf.rshift) & vs->client_pf.rmax; in write_png_palette()
1263 green = (pix >> vs->client_pf.gshift) & vs->client_pf.gmax; in write_png_palette()
1264 blue = (pix >> vs->client_pf.bshift) & vs->client_pf.bmax; in write_png_palette()
1265 color->red = ((red * 255 + vs->client_pf.rmax / 2) / in write_png_palette()
1266 vs->client_pf.rmax); in write_png_palette()
1267 color->green = ((green * 255 + vs->client_pf.gmax / 2) / in write_png_palette()
1268 vs->client_pf.gmax); in write_png_palette()
1269 color->blue = ((blue * 255 + vs->client_pf.bmax / 2) / in write_png_palette()
1270 vs->client_pf.bmax); in write_png_palette()
1279 buffer_reserve(&vs->tight->png, vs->tight->png.offset + length); in png_write_data()
1280 memcpy(vs->tight->png.buffer + vs->tight->png.offset, data, length); in png_write_data()
1282 vs->tight->png.offset += length; in png_write_data()
1307 int level = tight_png_conf[vs->tight->compression].png_zlib_level; in send_png_rect()
1308 int filters = tight_png_conf[vs->tight->compression].png_filters; in send_png_rect()
1316 return -1; in send_png_rect()
1322 return -1; in send_png_rect()
1351 if (vs->client_pf.bytes_per_pixel == 4) { in send_png_rect()
1352 tight_encode_indexed_rect32(vs->tight->tight.buffer, w * h, in send_png_rect()
1355 tight_encode_indexed_rect16(vs->tight->tight.buffer, w * h, in send_png_rect()
1362 buffer_reserve(&vs->tight->png, 2048); in send_png_rect()
1368 memcpy(buf, vs->tight->tight.buffer + (dy * w), w); in send_png_rect()
1370 qemu_pixman_linebuf_fill(linebuf, vs->vd->server, w, x, y + dy); in send_png_rect()
1386 tight_send_compact_size(vs, vs->tight->png.offset); in send_png_rect()
1387 vnc_write(vs, vs->tight->png.buffer, vs->tight->png.offset); in send_png_rect()
1388 buffer_reset(&vs->tight->png); in send_png_rect()
1395 buffer_reset(&vs->tight->tight); in vnc_tight_start()
1398 vs->tight->tmp = vs->output; in vnc_tight_start()
1399 vs->output = vs->tight->tight; in vnc_tight_start()
1405 vs->tight->tight = vs->output; in vnc_tight_stop()
1406 vs->output = vs->tight->tmp; in vnc_tight_stop()
1440 if (force || (tight_jpeg_conf[vs->tight->quality].jpeg_full && in send_sub_rect_jpeg()
1442 int quality = tight_conf[vs->tight->quality].jpeg_quality; in send_sub_rect_jpeg()
1454 tight_jpeg_conf[vs->tight->quality].jpeg_idx && in send_sub_rect_jpeg()
1456 int quality = tight_conf[vs->tight->quality].jpeg_quality; in send_sub_rect_jpeg()
1494 vnc_framebuffer_update(vs, x, y, w, h, vs->tight->type); in send_sub_rect()
1501 if (!vs->vd->non_adaptive && vs->tight->quality != (uint8_t)-1) { in send_sub_rect()
1504 if (freq < tight_jpeg_conf[vs->tight->quality].jpeg_freq_min) { in send_sub_rect()
1507 if (freq >= tight_jpeg_conf[vs->tight->quality].jpeg_freq_threshold) { in send_sub_rect()
1517 if (allow_jpeg && vs->tight->quality != (uint8_t)-1) { in send_sub_rect()
1534 vnc_framebuffer_update(vs, x, y, w, h, vs->tight->type); in send_sub_rect_solid()
1552 max_size = tight_conf[vs->tight->compression].max_rect_size; in send_rect_simple()
1553 max_width = tight_conf[vs->tight->compression].max_rect_width; in send_rect_simple()
1561 rw = MIN(max_sub_width, w - dx); in send_rect_simple()
1562 rh = MIN(max_sub_height, h - dy); in send_rect_simple()
1579 /* Try to find large solid-color areas and send them separately. */ in find_large_solid_color_rect()
1585 if (dy - y >= max_rows) { in find_large_solid_color_rect()
1588 h -= max_rows; in find_large_solid_color_rect()
1591 dh = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (y + h - dy)); in find_large_solid_color_rect()
1597 dw = MIN(VNC_TIGHT_MAX_SPLIT_TILE_SIZE, (x + w - dx)); in find_large_solid_color_rect()
1603 /* Get dimensions of solid-color area. */ in find_large_solid_color_rect()
1605 find_best_solid_area(vs, dx, dy, w - (dx - x), h - (dy - y), in find_large_solid_color_rect()
1622 /* Send rectangles at top and left to solid-color area. */ in find_large_solid_color_rect()
1625 n += send_rect_simple(vs, x, y, w, y_best-y, true); in find_large_solid_color_rect()
1629 x_best-x, h_best); in find_large_solid_color_rect()
1632 /* Send solid-color rectangle. */ in find_large_solid_color_rect()
1640 w-(x_best-x)-w_best, in find_large_solid_color_rect()
1645 w, h-(y_best-y)-h_best); in find_large_solid_color_rect()
1660 if (vs->client_pf.bytes_per_pixel == 4 && vs->client_pf.rmax == 0xFF && in tight_send_framebuffer_update()
1661 vs->client_pf.bmax == 0xFF && vs->client_pf.gmax == 0xFF) { in tight_send_framebuffer_update()
1662 vs->tight->pixel24 = true; in tight_send_framebuffer_update()
1664 vs->tight->pixel24 = false; in tight_send_framebuffer_update()
1668 if (vs->tight->quality != (uint8_t)-1) { in tight_send_framebuffer_update()
1671 if (freq > tight_jpeg_conf[vs->tight->quality].jpeg_freq_threshold) { in tight_send_framebuffer_update()
1681 /* Calculate maximum number of rows in one non-solid rectangle. */ in tight_send_framebuffer_update()
1683 max_rows = tight_conf[vs->tight->compression].max_rect_size; in tight_send_framebuffer_update()
1684 max_rows /= MIN(tight_conf[vs->tight->compression].max_rect_width, w); in tight_send_framebuffer_update()
1692 vs->tight->type = VNC_ENCODING_TIGHT; in vnc_tight_send_framebuffer_update()
1699 vs->tight->type = VNC_ENCODING_TIGHT_PNG; in vnc_tight_png_send_framebuffer_update()
1706 for (i = 0; i < ARRAY_SIZE(vs->tight->stream); i++) { in vnc_tight_clear()
1707 if (vs->tight->stream[i].opaque) { in vnc_tight_clear()
1708 deflateEnd(&vs->tight->stream[i]); in vnc_tight_clear()
1712 buffer_free(&vs->tight->tight); in vnc_tight_clear()
1713 buffer_free(&vs->tight->zlib); in vnc_tight_clear()
1714 buffer_free(&vs->tight->gradient); in vnc_tight_clear()
1716 buffer_free(&vs->tight->jpeg); in vnc_tight_clear()
1719 buffer_free(&vs->tight->png); in vnc_tight_clear()