2010-01-22 02:19:24 +00:00
|
|
|
/* GStreamer PNM encoder
|
|
|
|
* Copyright (C) 2009 Lutz Mueller <lutz@users.sourceforge.net>
|
2009-09-10 06:23:22 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-09-10 06:23:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-pnmenc
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: pnmenc
|
2009-09-10 06:23:22 +00:00
|
|
|
*
|
2009-09-16 06:22:19 +00:00
|
|
|
* Encodes pnm images. This plugin supports both raw and ASCII encoding.
|
|
|
|
* To enable ASCII encoding, set the parameter ascii to TRUE. If you omit
|
|
|
|
* the parameter or set it to FALSE, the output will be raw encoded.
|
2009-09-10 06:23:22 +00:00
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* ## Example launch line
|
2009-09-10 06:23:22 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 videotestsrc num_buffers=1 ! videoconvert ! "video/x-raw,format=GRAY8" ! pnmenc ascii=true ! filesink location=test.pnm
|
2009-09-16 06:22:19 +00:00
|
|
|
* ]| The above pipeline writes a test pnm file (ASCII encoding).
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2009-09-10 06:23:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstpnmenc.h"
|
|
|
|
#include "gstpnmutils.h"
|
|
|
|
|
|
|
|
#include <gst/gstutils.h>
|
2009-09-10 06:48:12 +00:00
|
|
|
#include <gst/video/video.h>
|
2014-07-22 07:12:36 +00:00
|
|
|
#include <gst/video/gstvideometa.h>
|
|
|
|
#include <stdio.h>
|
2009-09-10 06:23:22 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2009-09-16 06:22:19 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
GST_PNMENC_PROP_0,
|
|
|
|
GST_PNMENC_PROP_ASCII
|
|
|
|
/* Add here. */
|
|
|
|
};
|
|
|
|
|
2015-10-19 15:15:30 +00:00
|
|
|
|
|
|
|
|
2009-09-10 06:23:22 +00:00
|
|
|
static GstStaticPadTemplate sink_pad_template =
|
2015-10-19 15:15:30 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE
|
|
|
|
("{ RGB, GRAY8, GRAY16_BE, GRAY16_LE }")));
|
2012-09-12 22:34:03 +00:00
|
|
|
|
2009-09-10 06:23:22 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate src_pad_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (MIME_ALL));
|
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
G_DEFINE_TYPE (GstPnmenc, gst_pnmenc, GST_TYPE_VIDEO_ENCODER);
|
|
|
|
#define parent_class gst_pnmenc_parent_class
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_pnmenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame);
|
|
|
|
|
|
|
|
static void gst_pnmenc_finalize (GObject * object);
|
2010-03-22 11:02:16 +00:00
|
|
|
|
2009-09-16 06:22:19 +00:00
|
|
|
static void
|
|
|
|
gst_pnmenc_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPnmenc *s = GST_PNMENC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case GST_PNMENC_PROP_ASCII:
|
2014-07-22 07:12:36 +00:00
|
|
|
if (g_value_get_boolean (value)) {
|
2009-09-16 06:22:19 +00:00
|
|
|
s->info.encoding = GST_PNM_ENCODING_ASCII;
|
2014-07-22 07:12:36 +00:00
|
|
|
} else {
|
2009-09-16 06:22:19 +00:00
|
|
|
s->info.encoding = GST_PNM_ENCODING_RAW;
|
2014-07-22 07:12:36 +00:00
|
|
|
}
|
2009-09-16 06:22:19 +00:00
|
|
|
s->info.fields |= GST_PNM_INFO_FIELDS_ENCODING;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_pnmenc_get_property (GObject * object, guint prop_id, GValue * value,
|
|
|
|
GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstPnmenc *s = GST_PNMENC (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case GST_PNMENC_PROP_ASCII:
|
|
|
|
g_value_set_boolean (value, s->info.encoding == GST_PNM_ENCODING_ASCII);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
static void
|
|
|
|
gst_pnmenc_init (GstPnmenc * s)
|
2009-09-10 06:23:22 +00:00
|
|
|
{
|
2015-08-16 10:06:44 +00:00
|
|
|
GST_PAD_SET_ACCEPT_TEMPLATE (GST_VIDEO_ENCODER_SINK_PAD (s));
|
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
/* Set default encoding as RAW as ASCII takes up 4 time more bytes */
|
|
|
|
s->info.encoding = GST_PNM_ENCODING_RAW;
|
|
|
|
}
|
2009-09-10 06:48:12 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
static void
|
|
|
|
gst_pnmenc_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstPnmenc *pnmenc = GST_PNMENC (object);
|
|
|
|
if (pnmenc->input_state)
|
|
|
|
gst_video_codec_state_unref (pnmenc->input_state);
|
2014-05-06 08:48:58 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2009-09-10 06:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-07-22 07:12:36 +00:00
|
|
|
gst_pnmenc_set_format (GstVideoEncoder * encoder, GstVideoCodecState * state)
|
2009-09-10 06:23:22 +00:00
|
|
|
{
|
2014-07-22 07:12:36 +00:00
|
|
|
GstPnmenc *pnmenc;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
GstVideoInfo *info;
|
|
|
|
GstVideoCodecState *output_state;
|
2016-05-18 15:04:36 +00:00
|
|
|
const gchar *mime_type = NULL;
|
2009-09-13 17:13:24 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
pnmenc = GST_PNMENC (encoder);
|
|
|
|
info = &state->info;
|
2012-09-12 22:34:03 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
switch (GST_VIDEO_INFO_FORMAT (info)) {
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
2015-10-19 15:15:30 +00:00
|
|
|
pnmenc->info.max = 255;
|
2014-07-22 07:12:36 +00:00
|
|
|
pnmenc->info.type = GST_PNM_TYPE_PIXMAP;
|
2016-05-18 15:04:36 +00:00
|
|
|
mime_type = MIME_PM;
|
2014-07-22 07:12:36 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_GRAY8:
|
2015-10-19 15:15:30 +00:00
|
|
|
pnmenc->info.max = 255;
|
|
|
|
pnmenc->info.type = GST_PNM_TYPE_GRAYMAP;
|
2016-05-18 15:04:36 +00:00
|
|
|
mime_type = MIME_GM;
|
2015-10-19 15:15:30 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_BE:
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_LE:
|
|
|
|
pnmenc->info.max = 65535;
|
2014-07-22 07:12:36 +00:00
|
|
|
pnmenc->info.type = GST_PNM_TYPE_GRAYMAP;
|
2016-05-18 15:04:36 +00:00
|
|
|
mime_type = MIME_GM;
|
2014-07-22 07:12:36 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
2009-09-13 17:13:24 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
pnmenc->info.width = GST_VIDEO_INFO_WIDTH (info);
|
|
|
|
pnmenc->info.height = GST_VIDEO_INFO_HEIGHT (info);
|
2009-09-10 06:23:22 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
if (pnmenc->input_state)
|
|
|
|
gst_video_codec_state_unref (pnmenc->input_state);
|
|
|
|
pnmenc->input_state = gst_video_codec_state_ref (state);
|
2012-09-12 22:34:03 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
output_state =
|
|
|
|
gst_video_encoder_set_output_state (encoder,
|
2016-05-18 15:04:36 +00:00
|
|
|
gst_caps_new_empty_simple (mime_type), state);
|
2014-07-22 07:12:36 +00:00
|
|
|
gst_video_codec_state_unref (output_state);
|
2012-09-12 22:34:03 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|
2012-09-12 22:34:03 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_pnmenc_handle_frame (GstVideoEncoder * encoder, GstVideoCodecFrame * frame)
|
|
|
|
{
|
|
|
|
GstPnmenc *pnmenc;
|
2015-10-19 15:15:30 +00:00
|
|
|
guint size, pixels, bytesize;
|
2018-02-13 10:16:29 +00:00
|
|
|
GstMapInfo omap;
|
2015-12-16 00:05:42 +00:00
|
|
|
gchar *header = NULL;
|
2014-07-22 07:12:36 +00:00
|
|
|
GstVideoInfo *info;
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
guint i_rowstride, o_rowstride;
|
|
|
|
guint bytes = 0, index, head_size;
|
|
|
|
guint i, j;
|
2015-10-19 15:15:30 +00:00
|
|
|
guint maxbytes_per_pixel, str_len;
|
|
|
|
gchar format_str[4];
|
2018-02-13 10:16:29 +00:00
|
|
|
GstVideoFrame in_frame;
|
2014-07-22 07:12:36 +00:00
|
|
|
pnmenc = GST_PNMENC (encoder);
|
|
|
|
info = &pnmenc->input_state->info;
|
|
|
|
|
|
|
|
switch (GST_VIDEO_INFO_FORMAT (info)) {
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
pixels = size = pnmenc->info.width * pnmenc->info.height * 3;
|
2015-10-19 15:15:30 +00:00
|
|
|
bytesize = 1;
|
|
|
|
maxbytes_per_pixel = 4;
|
|
|
|
str_len = 3;
|
|
|
|
g_strlcpy (format_str, "%3i", 4);
|
2012-09-12 22:34:03 +00:00
|
|
|
break;
|
2014-07-22 07:12:36 +00:00
|
|
|
case GST_VIDEO_FORMAT_GRAY8:
|
|
|
|
pixels = size = pnmenc->info.width * pnmenc->info.height * 1;
|
2015-10-19 15:15:30 +00:00
|
|
|
bytesize = 1;
|
|
|
|
maxbytes_per_pixel = 4;
|
|
|
|
str_len = 3;
|
|
|
|
g_strlcpy (format_str, "%3i", 4);
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_LE:
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_BE:
|
|
|
|
pixels = pnmenc->info.width * pnmenc->info.height * 1;
|
|
|
|
bytesize = 2;
|
|
|
|
size = pixels * bytesize;
|
|
|
|
maxbytes_per_pixel = 6;
|
|
|
|
str_len = 5;
|
|
|
|
g_strlcpy (format_str, "%5i", 4);
|
2012-09-12 22:34:03 +00:00
|
|
|
break;
|
2014-07-22 07:12:36 +00:00
|
|
|
default:
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
2012-09-12 22:34:03 +00:00
|
|
|
}
|
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
header = g_strdup_printf ("P%i\n%i %i\n%i\n",
|
|
|
|
pnmenc->info.type + 3 * (1 - pnmenc->info.encoding), pnmenc->info.width,
|
|
|
|
pnmenc->info.height, pnmenc->info.max);
|
|
|
|
|
|
|
|
if (pnmenc->info.encoding == GST_PNM_ENCODING_ASCII) {
|
|
|
|
/* Per component 4 bytes are used in case of ASCII encoding */
|
2015-12-16 23:51:48 +00:00
|
|
|
size = size * 4 + size / 20;
|
2014-07-22 07:12:36 +00:00
|
|
|
size += strlen (header);
|
|
|
|
frame->output_buffer =
|
2015-12-16 23:51:48 +00:00
|
|
|
gst_video_encoder_allocate_output_buffer (encoder, (size));
|
2014-07-22 07:12:36 +00:00
|
|
|
} else {
|
|
|
|
size += strlen (header);
|
|
|
|
frame->output_buffer =
|
|
|
|
gst_video_encoder_allocate_output_buffer (encoder, size);
|
|
|
|
}
|
2009-09-10 06:23:22 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
if (gst_buffer_map (frame->output_buffer, &omap, GST_MAP_WRITE) == FALSE) {
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2018-02-13 10:16:29 +00:00
|
|
|
if (!gst_video_frame_map (&in_frame, &(pnmenc->input_state->info),
|
|
|
|
frame->input_buffer, GST_MAP_READ)) {
|
2014-07-22 07:12:36 +00:00
|
|
|
/* Unmap already mapped buffer */
|
|
|
|
gst_buffer_unmap (frame->output_buffer, &omap);
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2016-05-18 07:19:40 +00:00
|
|
|
/* Copy out the header first */
|
2014-07-22 07:12:36 +00:00
|
|
|
head_size = strlen (header);
|
2016-05-18 07:19:40 +00:00
|
|
|
memcpy (omap.data, header, head_size);
|
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
if (pnmenc->info.encoding == GST_PNM_ENCODING_ASCII) {
|
|
|
|
/* We need to convert to ASCII */
|
2016-05-18 07:19:40 +00:00
|
|
|
/* Convert from gstreamer rowstride to PNM rowstride as we go */
|
|
|
|
if (pnmenc->info.type == GST_PNM_TYPE_PIXMAP) {
|
|
|
|
o_rowstride = 3 * pnmenc->info.width;
|
|
|
|
} else {
|
|
|
|
o_rowstride = pnmenc->info.width;
|
|
|
|
}
|
2018-02-13 10:16:29 +00:00
|
|
|
i_rowstride = GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, 0);
|
2016-05-18 07:19:40 +00:00
|
|
|
|
|
|
|
switch (GST_VIDEO_INFO_FORMAT (info)) {
|
|
|
|
case GST_VIDEO_FORMAT_RGB:
|
|
|
|
case GST_VIDEO_FORMAT_GRAY8:
|
|
|
|
for (i = 0; i < pnmenc->info.height; i++) {
|
|
|
|
index = i * i_rowstride;
|
|
|
|
for (j = 0; j < o_rowstride; j++, bytes++, index++) {
|
|
|
|
g_snprintf ((char *) omap.data + head_size, maxbytes_per_pixel,
|
2018-02-13 10:16:29 +00:00
|
|
|
format_str, in_frame.map[0].data[index]);
|
2016-05-18 07:19:40 +00:00
|
|
|
head_size += str_len;
|
|
|
|
omap.data[head_size++] = ' ';
|
|
|
|
/* Add new line so that file will not end up with single big line */
|
|
|
|
if (!((bytes + 1) % 20))
|
|
|
|
omap.data[head_size++] = '\n';
|
2015-10-19 15:15:30 +00:00
|
|
|
}
|
2014-07-22 07:12:36 +00:00
|
|
|
}
|
2016-05-18 07:19:40 +00:00
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_BE:
|
|
|
|
for (i = 0; i < pnmenc->info.height; i++) {
|
|
|
|
index = i * i_rowstride;
|
|
|
|
for (j = 0; j < o_rowstride; j++, bytes++, index += 2) {
|
2015-10-19 15:15:30 +00:00
|
|
|
g_snprintf ((char *) omap.data + head_size, maxbytes_per_pixel,
|
2018-02-13 10:16:29 +00:00
|
|
|
format_str, GST_READ_UINT16_BE (in_frame.map[0].data + index));
|
2015-10-19 15:15:30 +00:00
|
|
|
head_size += str_len;
|
|
|
|
omap.data[head_size++] = ' ';
|
2016-05-18 07:19:40 +00:00
|
|
|
/* Add new line so that file will not end up with single big line */
|
|
|
|
if (!((bytes + 1) % 20))
|
2015-10-19 15:15:30 +00:00
|
|
|
omap.data[head_size++] = '\n';
|
|
|
|
}
|
2016-05-18 07:19:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_LE:
|
|
|
|
for (i = 0; i < pnmenc->info.height; i++) {
|
|
|
|
index = i * i_rowstride;
|
|
|
|
for (j = 0; j < o_rowstride; j++, bytes++, index += 2) {
|
2015-10-19 15:15:30 +00:00
|
|
|
g_snprintf ((char *) omap.data + head_size, maxbytes_per_pixel,
|
2018-02-13 10:16:29 +00:00
|
|
|
format_str, GST_READ_UINT16_LE (in_frame.map[0].data + index));
|
2015-10-19 15:15:30 +00:00
|
|
|
head_size += str_len;
|
|
|
|
omap.data[head_size++] = ' ';
|
2016-05-18 07:19:40 +00:00
|
|
|
/* Add new line so that file will not end up with single big line */
|
|
|
|
if (!((bytes + 1) % 20))
|
2015-10-19 15:15:30 +00:00
|
|
|
omap.data[head_size++] = '\n';
|
|
|
|
}
|
|
|
|
}
|
2016-05-18 07:19:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_ERROR_OBJECT (encoder, "Unhandled format %s",
|
|
|
|
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (info)));
|
|
|
|
gst_buffer_unmap (frame->output_buffer, &omap);
|
2018-02-13 10:16:29 +00:00
|
|
|
gst_video_frame_unmap (&in_frame);
|
2016-05-18 07:19:40 +00:00
|
|
|
g_free (header);
|
|
|
|
return GST_FLOW_ERROR;
|
2014-07-22 07:12:36 +00:00
|
|
|
}
|
2016-05-18 07:19:40 +00:00
|
|
|
|
|
|
|
gst_buffer_set_size (frame->output_buffer, head_size);
|
2014-07-22 07:12:36 +00:00
|
|
|
} else {
|
2016-05-18 07:19:40 +00:00
|
|
|
guint out_index = head_size;
|
2014-07-22 07:12:36 +00:00
|
|
|
|
2016-05-18 07:19:40 +00:00
|
|
|
/* Binary output. 8-bit, or 16-bit BE */
|
|
|
|
if (pnmenc->info.type == GST_PNM_TYPE_PIXMAP) {
|
|
|
|
o_rowstride = 3 * pnmenc->info.width * bytesize;
|
2014-07-22 07:12:36 +00:00
|
|
|
} else {
|
2016-05-18 07:19:40 +00:00
|
|
|
o_rowstride = pnmenc->info.width * bytesize;
|
|
|
|
}
|
2018-02-13 10:16:29 +00:00
|
|
|
i_rowstride = GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, 0);
|
2016-05-18 07:19:40 +00:00
|
|
|
|
|
|
|
switch (GST_VIDEO_INFO_FORMAT (info)) {
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_BE:
|
|
|
|
for (i = 0; i < pnmenc->info.height; i++) {
|
|
|
|
index = i * i_rowstride;
|
|
|
|
for (j = 0; j < o_rowstride; j += 2, index += 2) {
|
2018-02-13 10:16:29 +00:00
|
|
|
guint16 val = GST_READ_UINT16_LE (in_frame.map[0].data + index);
|
2016-05-18 07:19:40 +00:00
|
|
|
GST_WRITE_UINT16_BE (omap.data + out_index, val);
|
|
|
|
out_index += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEO_FORMAT_GRAY16_LE:
|
|
|
|
for (i = 0; i < pnmenc->info.height; i++) {
|
|
|
|
index = i * i_rowstride;
|
|
|
|
for (j = 0; j < o_rowstride; j += 2, index += 2) {
|
2018-02-13 10:16:29 +00:00
|
|
|
guint16 val = GST_READ_UINT16_LE (in_frame.map[0].data + index);
|
2016-05-18 07:19:40 +00:00
|
|
|
GST_WRITE_UINT16_BE (omap.data + out_index, val);
|
|
|
|
out_index += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
for (i = 0; i < pnmenc->info.height; i++) {
|
|
|
|
memcpy (omap.data + head_size + o_rowstride * i,
|
2018-02-13 10:16:29 +00:00
|
|
|
in_frame.map[0].data + i_rowstride * i, o_rowstride);
|
2016-05-18 07:19:40 +00:00
|
|
|
}
|
2014-07-22 07:12:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_unmap (frame->output_buffer, &omap);
|
2018-02-13 10:16:29 +00:00
|
|
|
gst_video_frame_unmap (&in_frame);
|
2009-09-10 06:23:22 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
if ((ret = gst_video_encoder_finish_frame (encoder, frame)) != GST_FLOW_OK)
|
|
|
|
goto done;
|
2009-09-10 06:23:22 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
done:
|
2015-12-16 00:05:42 +00:00
|
|
|
g_free (header);
|
2014-07-22 07:12:36 +00:00
|
|
|
return ret;
|
2009-09-10 06:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-09-12 22:34:03 +00:00
|
|
|
gst_pnmenc_class_init (GstPnmencClass * klass)
|
2009-09-10 06:23:22 +00:00
|
|
|
{
|
2012-09-12 22:34:03 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2014-07-22 07:12:36 +00:00
|
|
|
GstVideoEncoderClass *venc_class = (GstVideoEncoderClass *) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
gobject_class->set_property = gst_pnmenc_set_property;
|
|
|
|
gobject_class->get_property = gst_pnmenc_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, GST_PNMENC_PROP_ASCII,
|
|
|
|
g_param_spec_boolean ("ascii", "ASCII Encoding", "The output will be "
|
|
|
|
"ASCII encoded", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2009-09-10 06:23:22 +00:00
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class, &sink_pad_template);
|
|
|
|
gst_element_class_add_static_pad_template (element_class, &src_pad_template);
|
2014-07-22 07:12:36 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class, "PNM image encoder",
|
2010-01-22 02:22:56 +00:00
|
|
|
"Codec/Encoder/Image",
|
|
|
|
"Encodes images into portable pixmap or graymap (PNM) format",
|
|
|
|
"Lutz Mueller <lutz@users.sourceforge.net>");
|
2009-09-16 06:22:19 +00:00
|
|
|
|
2014-07-22 07:12:36 +00:00
|
|
|
venc_class->set_format = gst_pnmenc_set_format;
|
|
|
|
venc_class->handle_frame = gst_pnmenc_handle_frame;
|
|
|
|
gobject_class->finalize = gst_pnmenc_finalize;
|
2009-09-10 06:23:22 +00:00
|
|
|
}
|