summaryrefslogtreecommitdiff
path: root/lib/mesa/src
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2018-10-23 05:42:56 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2018-10-23 05:42:56 +0000
commite2eeaecd84000da1ea211aa982af33776ca8bd15 (patch)
tree4badb63badf951a4107fdc785185eb9d86dc2eb8 /lib/mesa/src
parent126e9cecc8d985ee575e5f800b412e2cd5ba4153 (diff)
Import Mesa 17.3.9
Diffstat (limited to 'lib/mesa/src')
-rw-r--r--lib/mesa/src/gallium/state_trackers/dri/dri_helpers.c266
-rw-r--r--lib/mesa/src/gallium/state_trackers/dri/dri_helpers.h32
-rw-r--r--lib/mesa/src/gallium/state_trackers/va/picture_mjpeg.c142
3 files changed, 18 insertions, 422 deletions
diff --git a/lib/mesa/src/gallium/state_trackers/dri/dri_helpers.c b/lib/mesa/src/gallium/state_trackers/dri/dri_helpers.c
index 90a8a392f..06309d8f0 100644
--- a/lib/mesa/src/gallium/state_trackers/dri/dri_helpers.c
+++ b/lib/mesa/src/gallium/state_trackers/dri/dri_helpers.c
@@ -21,7 +21,6 @@
*/
#include <dlfcn.h>
-#include "drm-uapi/drm_fourcc.h"
#include "util/u_memory.h"
#include "pipe/p_screen.h"
#include "state_tracker/st_texture.h"
@@ -91,13 +90,13 @@ static unsigned dri2_fence_get_caps(__DRIscreen *_screen)
static void *
dri2_create_fence(__DRIcontext *_ctx)
{
- struct st_context_iface *stapi = dri_context(_ctx)->st;
+ struct pipe_context *ctx = dri_context(_ctx)->st->pipe;
struct dri2_fence *fence = CALLOC_STRUCT(dri2_fence);
if (!fence)
return NULL;
- stapi->flush(stapi, 0, &fence->pipe_fence, NULL, NULL);
+ ctx->flush(ctx, &fence->pipe_fence, 0);
if (!fence->pipe_fence) {
FREE(fence);
@@ -111,16 +110,16 @@ dri2_create_fence(__DRIcontext *_ctx)
static void *
dri2_create_fence_fd(__DRIcontext *_ctx, int fd)
{
- struct st_context_iface *stapi = dri_context(_ctx)->st;
- struct pipe_context *ctx = stapi->pipe;
+ struct pipe_context *ctx = dri_context(_ctx)->st->pipe;
struct dri2_fence *fence = CALLOC_STRUCT(dri2_fence);
if (fd == -1) {
/* exporting driver created fence, flush: */
- stapi->flush(stapi, ST_FLUSH_FENCE_FD, &fence->pipe_fence, NULL, NULL);
+ ctx->flush(ctx, &fence->pipe_fence,
+ PIPE_FLUSH_DEFERRED | PIPE_FLUSH_FENCE_FD);
} else {
/* importing a foreign fence fd: */
- ctx->create_fence_fd(ctx, &fence->pipe_fence, fd, PIPE_FD_TYPE_NATIVE_SYNC);
+ ctx->create_fence_fd(ctx, &fence->pipe_fence, fd);
}
if (!fence->pipe_fence) {
FREE(fence);
@@ -215,12 +214,6 @@ dri2_server_wait_sync(__DRIcontext *_ctx, void *_fence, unsigned flags)
struct pipe_context *ctx = dri_context(_ctx)->st->pipe;
struct dri2_fence *fence = (struct dri2_fence*)_fence;
- /* We might be called here with a NULL fence as a result of WaitSyncKHR
- * on a EGL_KHR_reusable_sync fence. Nothing to do here in such case.
- */
- if (!fence)
- return;
-
if (ctx->fence_server_sync)
ctx->fence_server_sync(ctx, fence->pipe_fence);
}
@@ -297,6 +290,12 @@ dri2_create_image_from_renderbuffer2(__DRIcontext *context,
img->dri_format = driGLFormatToImageFormat(rb->Format);
img->loader_private = loaderPrivate;
+ if (img->dri_format == __DRI_IMAGE_FORMAT_NONE) {
+ *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
+ free(img);
+ return NULL;
+ }
+
pipe_resource_reference(&img->texture, tex);
*error = __DRI_IMAGE_ERROR_SUCCESS;
@@ -374,245 +373,16 @@ dri2_create_from_texture(__DRIcontext *context, int target, unsigned texture,
img->loader_private = loaderPrivate;
+ if (img->dri_format == __DRI_IMAGE_FORMAT_NONE) {
+ *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
+ free(img);
+ return NULL;
+ }
+
pipe_resource_reference(&img->texture, tex);
*error = __DRI_IMAGE_ERROR_SUCCESS;
return img;
}
-static const struct dri2_format_mapping dri2_format_table[] = {
- { DRM_FORMAT_ABGR16161616F, __DRI_IMAGE_FORMAT_ABGR16161616F,
- __DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_R16G16B16A16_FLOAT, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR16161616F, 4 } } },
- { DRM_FORMAT_XBGR16161616F, __DRI_IMAGE_FORMAT_XBGR16161616F,
- __DRI_IMAGE_COMPONENTS_RGB, PIPE_FORMAT_R16G16B16X16_FLOAT, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR16161616F, 4 } } },
- { DRM_FORMAT_ARGB2101010, __DRI_IMAGE_FORMAT_ARGB2101010,
- __DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_B10G10R10A2_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB2101010, 4 } } },
- { DRM_FORMAT_XRGB2101010, __DRI_IMAGE_FORMAT_XRGB2101010,
- __DRI_IMAGE_COMPONENTS_RGB, PIPE_FORMAT_B10G10R10X2_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB2101010, 4 } } },
- { DRM_FORMAT_ABGR2101010, __DRI_IMAGE_FORMAT_ABGR2101010,
- __DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_R10G10B10A2_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR2101010, 4 } } },
- { DRM_FORMAT_XBGR2101010, __DRI_IMAGE_FORMAT_XBGR2101010,
- __DRI_IMAGE_COMPONENTS_RGB, PIPE_FORMAT_R10G10B10X2_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR2101010, 4 } } },
- { DRM_FORMAT_ARGB8888, __DRI_IMAGE_FORMAT_ARGB8888,
- __DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_BGRA8888_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } },
- { DRM_FORMAT_ABGR8888, __DRI_IMAGE_FORMAT_ABGR8888,
- __DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_RGBA8888_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888, 4 } } },
- { __DRI_IMAGE_FOURCC_SARGB8888, __DRI_IMAGE_FORMAT_SARGB8,
- __DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_BGRA8888_SRGB, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8, 4 } } },
- { DRM_FORMAT_XRGB8888, __DRI_IMAGE_FORMAT_XRGB8888,
- __DRI_IMAGE_COMPONENTS_RGB, PIPE_FORMAT_BGRX8888_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB8888, 4 }, } },
- { DRM_FORMAT_XBGR8888, __DRI_IMAGE_FORMAT_XBGR8888,
- __DRI_IMAGE_COMPONENTS_RGB, PIPE_FORMAT_RGBX8888_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888, 4 }, } },
- { DRM_FORMAT_ARGB1555, __DRI_IMAGE_FORMAT_ARGB1555,
- __DRI_IMAGE_COMPONENTS_RGBA, PIPE_FORMAT_B5G5R5A1_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555, 2 } } },
- { DRM_FORMAT_RGB565, __DRI_IMAGE_FORMAT_RGB565,
- __DRI_IMAGE_COMPONENTS_RGB, PIPE_FORMAT_B5G6R5_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565, 2 } } },
- { DRM_FORMAT_R8, __DRI_IMAGE_FORMAT_R8,
- __DRI_IMAGE_COMPONENTS_R, PIPE_FORMAT_R8_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, } },
- { DRM_FORMAT_R16, __DRI_IMAGE_FORMAT_R16,
- __DRI_IMAGE_COMPONENTS_R, PIPE_FORMAT_R16_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16, 1 }, } },
- { DRM_FORMAT_GR88, __DRI_IMAGE_FORMAT_GR88,
- __DRI_IMAGE_COMPONENTS_RG, PIPE_FORMAT_RG88_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, } },
- { DRM_FORMAT_GR1616, __DRI_IMAGE_FORMAT_GR1616,
- __DRI_IMAGE_COMPONENTS_RG, PIPE_FORMAT_RG1616_UNORM, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616, 2 }, } },
-
- { DRM_FORMAT_YUV410, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
- { DRM_FORMAT_YUV411, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
- { DRM_FORMAT_YUV420, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
- { DRM_FORMAT_YUV422, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
- { DRM_FORMAT_YUV444, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
-
- { DRM_FORMAT_YVU410, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
- { DRM_FORMAT_YVU411, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
- { DRM_FORMAT_YVU420, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
- { DRM_FORMAT_YVU422, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
- { DRM_FORMAT_YVU444, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_U_V, PIPE_FORMAT_IYUV, 3,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
-
- { DRM_FORMAT_NV12, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_UV, PIPE_FORMAT_NV12, 2,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } },
-
- { DRM_FORMAT_P010, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_UV, PIPE_FORMAT_P016, 2,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16, 2 },
- { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616, 4 } } },
- { DRM_FORMAT_P012, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_UV, PIPE_FORMAT_P016, 2,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16, 2 },
- { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616, 4 } } },
- { DRM_FORMAT_P016, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_UV, PIPE_FORMAT_P016, 2,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16, 2 },
- { 1, 1, 1, __DRI_IMAGE_FORMAT_GR1616, 4 } } },
-
- { DRM_FORMAT_NV16, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_UV, PIPE_FORMAT_NV12, 2,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
- { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
-
- { DRM_FORMAT_AYUV, __DRI_IMAGE_FORMAT_ABGR8888,
- __DRI_IMAGE_COMPONENTS_AYUV, PIPE_FORMAT_AYUV, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR8888, 4 } } },
- { DRM_FORMAT_XYUV8888, __DRI_IMAGE_FORMAT_XBGR8888,
- __DRI_IMAGE_COMPONENTS_XYUV, PIPE_FORMAT_XYUV, 1,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR8888, 4 } } },
-
- /* For YUYV and UYVY buffers, we set up two overlapping DRI images
- * and treat them as planar buffers in the compositors.
- * Plane 0 is GR88 and samples YU or YV pairs and places Y into
- * the R component, while plane 1 is ARGB/ABGR and samples YUYV/UYVY
- * clusters and places pairs and places U into the G component and
- * V into A. This lets the texture sampler interpolate the Y
- * components correctly when sampling from plane 0, and interpolate
- * U and V correctly when sampling from plane 1. */
- { DRM_FORMAT_YUYV, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_XUXV, PIPE_FORMAT_YUYV, 2,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
- { 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } },
- { DRM_FORMAT_UYVY, __DRI_IMAGE_FORMAT_NONE,
- __DRI_IMAGE_COMPONENTS_Y_UXVX, PIPE_FORMAT_UYVY, 2,
- { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 },
- { 0, 1, 0, __DRI_IMAGE_FORMAT_ABGR8888, 4 } } }
-};
-
-const struct dri2_format_mapping *
-dri2_get_mapping_by_fourcc(int fourcc)
-{
- for (unsigned i = 0; i < ARRAY_SIZE(dri2_format_table); i++) {
- if (dri2_format_table[i].dri_fourcc == fourcc)
- return &dri2_format_table[i];
- }
-
- return NULL;
-}
-
-const struct dri2_format_mapping *
-dri2_get_mapping_by_format(int format)
-{
- for (unsigned i = 0; i < ARRAY_SIZE(dri2_format_table); i++) {
- if (dri2_format_table[i].dri_format == format)
- return &dri2_format_table[i];
- }
-
- return NULL;
-}
-
-enum pipe_format
-dri2_get_pipe_format_for_dri_format(int format)
-{
- for (unsigned i = 0; i < ARRAY_SIZE(dri2_format_table); i++) {
- if (dri2_format_table[i].dri_format == format)
- return dri2_format_table[i].pipe_format;
- }
-
- return PIPE_FORMAT_NONE;
-}
-
-boolean
-dri2_yuv_dma_buf_supported(struct dri_screen *screen,
- const struct dri2_format_mapping *map)
-{
- struct pipe_screen *pscreen = screen->base.screen;
-
- for (unsigned i = 0; i < map->nplanes; i++) {
- if (!pscreen->is_format_supported(pscreen,
- dri2_get_pipe_format_for_dri_format(map->planes[i].dri_format),
- screen->target, 0, 0, PIPE_BIND_SAMPLER_VIEW))
- return false;
- }
- return true;
-}
-
-boolean
-dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
- int *count)
-{
- struct dri_screen *screen = dri_screen(_screen);
- struct pipe_screen *pscreen = screen->base.screen;
- int i, j;
-
- for (i = 0, j = 0; (i < ARRAY_SIZE(dri2_format_table)) &&
- (j < max || max == 0); i++) {
- const struct dri2_format_mapping *map = &dri2_format_table[i];
-
- /* The sRGB format is not a real FourCC as defined by drm_fourcc.h, so we
- * must not leak it out to clients.
- */
- if (dri2_format_table[i].dri_fourcc == __DRI_IMAGE_FOURCC_SARGB8888)
- continue;
-
- if (pscreen->is_format_supported(pscreen, map->pipe_format,
- screen->target, 0, 0,
- PIPE_BIND_RENDER_TARGET) ||
- pscreen->is_format_supported(pscreen, map->pipe_format,
- screen->target, 0, 0,
- PIPE_BIND_SAMPLER_VIEW) ||
- dri2_yuv_dma_buf_supported(screen, map)) {
- if (j < max)
- formats[j] = map->dri_fourcc;
- j++;
- }
- }
- *count = j;
- return true;
-}
-
/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/lib/mesa/src/gallium/state_trackers/dri/dri_helpers.h b/lib/mesa/src/gallium/state_trackers/dri/dri_helpers.h
index 0393a48a8..76f024fd6 100644
--- a/lib/mesa/src/gallium/state_trackers/dri/dri_helpers.h
+++ b/lib/mesa/src/gallium/state_trackers/dri/dri_helpers.h
@@ -26,40 +26,8 @@
#include "dri_context.h"
#include "dri_screen.h"
-
-struct dri2_format_mapping {
- int dri_fourcc;
- int dri_format; /* image format */
- int dri_components;
- enum pipe_format pipe_format;
- int nplanes;
- struct {
- int buffer_index;
- int width_shift;
- int height_shift;
- uint32_t dri_format; /* plane format */
- int cpp;
- } planes[3];
-};
-
extern const __DRI2fenceExtension dri2FenceExtension;
-const struct dri2_format_mapping *
-dri2_get_mapping_by_fourcc(int fourcc);
-
-const struct dri2_format_mapping *
-dri2_get_mapping_by_format(int format);
-
-enum pipe_format
-dri2_get_pipe_format_for_dri_format(int format);
-
-boolean
-dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
- int *count);
-boolean
-dri2_yuv_dma_buf_supported(struct dri_screen *screen,
- const struct dri2_format_mapping *map);
-
__DRIimage *
dri2_lookup_egl_image(struct dri_screen *screen, void *handle);
diff --git a/lib/mesa/src/gallium/state_trackers/va/picture_mjpeg.c b/lib/mesa/src/gallium/state_trackers/va/picture_mjpeg.c
index defb0b546..396b74344 100644
--- a/lib/mesa/src/gallium/state_trackers/va/picture_mjpeg.c
+++ b/lib/mesa/src/gallium/state_trackers/va/picture_mjpeg.c
@@ -114,145 +114,3 @@ void vlVaHandleSliceParameterBufferMJPEG(vlVaContext *context, vlVaBuffer *buf)
context->desc.mjpeg.slice_parameter.restart_interval = mjpeg->restart_interval;
context->desc.mjpeg.slice_parameter.num_mcus = mjpeg->num_mcus;
}
-
-void vlVaGetJpegSliceHeader(vlVaContext *context)
-{
- int size = 0, saved_size, len_pos, i;
- uint16_t *bs;
- uint8_t *p = context->mjpeg.slice_header;
-
- /* SOI */
- p[size++] = 0xff;
- p[size++] = 0xd8;
-
- /* DQT */
- p[size++] = 0xff;
- p[size++] = 0xdb;
-
- len_pos = size++;
- size++;
-
- for (i = 0; i < 4; ++i) {
- if (context->desc.mjpeg.quantization_table.load_quantiser_table[i] == 0)
- continue;
-
- p[size++] = i;
- memcpy((p + size), &context->desc.mjpeg.quantization_table.quantiser_table[i], 64);
- size += 64;
- }
-
- bs = (uint16_t*)&p[len_pos];
- *bs = util_bswap16(size - 4);
-
- saved_size = size;
-
- /* DHT */
- p[size++] = 0xff;
- p[size++] = 0xc4;
-
- len_pos = size++;
- size++;
-
- for (i = 0; i < 2; ++i) {
- int num = 0, j;
-
- if (context->desc.mjpeg.huffman_table.load_huffman_table[i] == 0)
- continue;
-
- p[size++] = 0x00 | i;
- memcpy((p + size), &context->desc.mjpeg.huffman_table.table[i].num_dc_codes, 16);
- size += 16;
- for (j = 0; j < 16; ++j)
- num += context->desc.mjpeg.huffman_table.table[i].num_dc_codes[j];
- assert(num <= 12);
- memcpy((p + size), &context->desc.mjpeg.huffman_table.table[i].dc_values, num);
- size += num;
- }
-
- for (i = 0; i < 2; ++i) {
- int num = 0, j;
-
- if (context->desc.mjpeg.huffman_table.load_huffman_table[i] == 0)
- continue;
-
- p[size++] = 0x10 | i;
- memcpy((p + size), &context->desc.mjpeg.huffman_table.table[i].num_ac_codes, 16);
- size += 16;
- for (j = 0; j < 16; ++j)
- num += context->desc.mjpeg.huffman_table.table[i].num_ac_codes[j];
- assert(num <= 162);
- memcpy((p + size), &context->desc.mjpeg.huffman_table.table[i].ac_values, num);
- size += num;
- }
-
- bs = (uint16_t*)&p[len_pos];
- *bs = util_bswap16(size - saved_size - 2);
-
- saved_size = size;
-
- /* DRI */
- if (context->desc.mjpeg.slice_parameter.restart_interval) {
- p[size++] = 0xff;
- p[size++] = 0xdd;
- p[size++] = 0x00;
- p[size++] = 0x04;
- bs = (uint16_t*)&p[size++];
- *bs = util_bswap16(context->desc.mjpeg.slice_parameter.restart_interval);
- saved_size = ++size;
- }
-
- /* SOF */
- p[size++] = 0xff;
- p[size++] = 0xc0;
-
- len_pos = size++;
- size++;
-
- p[size++] = 0x08;
-
- bs = (uint16_t*)&p[size++];
- *bs = util_bswap16(context->desc.mjpeg.picture_parameter.picture_height);
- size++;
-
- bs = (uint16_t*)&p[size++];
- *bs = util_bswap16(context->desc.mjpeg.picture_parameter.picture_width);
- size++;
-
- p[size++] = context->desc.mjpeg.picture_parameter.num_components;
-
- for (i = 0; i < context->desc.mjpeg.picture_parameter.num_components; ++i) {
- p[size++] = context->desc.mjpeg.picture_parameter.components[i].component_id;
- p[size++] = context->desc.mjpeg.picture_parameter.components[i].h_sampling_factor << 4 |
- context->desc.mjpeg.picture_parameter.components[i].v_sampling_factor;
- p[size++] = context->desc.mjpeg.picture_parameter.components[i].quantiser_table_selector;
- }
-
- bs = (uint16_t*)&p[len_pos];
- *bs = util_bswap16(size - saved_size - 2);
-
- saved_size = size;
-
- /* SOS */
- p[size++] = 0xff;
- p[size++] = 0xda;
-
- len_pos = size++;
- size++;
-
- p[size++] = context->desc.mjpeg.slice_parameter.num_components;
-
- for (i = 0; i < context->desc.mjpeg.slice_parameter.num_components; ++i) {
- p[size++] = context->desc.mjpeg.slice_parameter.components[i].component_selector;
- p[size++] = context->desc.mjpeg.slice_parameter.components[i].dc_table_selector << 4 |
- context->desc.mjpeg.slice_parameter.components[i].ac_table_selector;
- }
-
- p[size++] = 0x00;
- p[size++] = 0x3f;
- p[size++] = 0x00;
-
- bs = (uint16_t*)&p[len_pos];
- *bs = util_bswap16(size - saved_size - 2);
-
- context->mjpeg.slice_header_size = size;
-}