|
From: <jl...@us...> - 2008-06-17 22:08:00
|
Revision: 836
http://personalrobots.svn.sourceforge.net/personalrobots/?rev=836&view=rev
Author: jleibs
Date: 2008-06-17 15:08:05 -0700 (Tue, 17 Jun 2008)
Log Message:
-----------
Allow for population of width/height/colorspace of jpeg images without needing to decompress the full image.
Modified Paths:
--------------
pkg/trunk/drivers/cam/axis_cam/manifest.xml
pkg/trunk/drivers/cam/axis_cam/src/Makefile
pkg/trunk/drivers/cam/axis_cam/src/axis_cam/axis_cam.cpp
pkg/trunk/util/image_utils/include/image_utils/image_codec.h
pkg/trunk/util/image_utils/include/image_utils/jpeg_wrapper.h
Modified: pkg/trunk/drivers/cam/axis_cam/manifest.xml
===================================================================
--- pkg/trunk/drivers/cam/axis_cam/manifest.xml 2008-06-17 22:00:23 UTC (rev 835)
+++ pkg/trunk/drivers/cam/axis_cam/manifest.xml 2008-06-17 22:08:05 UTC (rev 836)
@@ -15,6 +15,7 @@
<depend package="std_msgs"/>
<depend package="rosthread"/>
<depend package="string_utils"/>
+<depend package="image_utils"/>
<export>
<cpp cflags="-I${prefix}/include" lflags="-L${prefix}/lib -laxis_cam -lcurl"/>
</export>
Modified: pkg/trunk/drivers/cam/axis_cam/src/Makefile
===================================================================
--- pkg/trunk/drivers/cam/axis_cam/src/Makefile 2008-06-17 22:00:23 UTC (rev 835)
+++ pkg/trunk/drivers/cam/axis_cam/src/Makefile 2008-06-17 22:08:05 UTC (rev 836)
@@ -1,3 +1,3 @@
-SUBDIRS = axis_cam libaxis_cam
+SUBDIRS = libaxis_cam axis_cam
include $(shell rospack find mk)/recurse_subdirs.mk
Modified: pkg/trunk/drivers/cam/axis_cam/src/axis_cam/axis_cam.cpp
===================================================================
--- pkg/trunk/drivers/cam/axis_cam/src/axis_cam/axis_cam.cpp 2008-06-17 22:00:23 UTC (rev 835)
+++ pkg/trunk/drivers/cam/axis_cam/src/axis_cam/axis_cam.cpp 2008-06-17 22:08:05 UTC (rev 836)
@@ -29,6 +29,7 @@
#include "ros/node.h"
#include "std_msgs/Image.h"
+#include "image_utils/image_codec.h"
#include "axis_cam/axis_cam.h"
@@ -36,12 +37,13 @@
{
public:
std_msgs::Image image;
+ ImageCodec<std_msgs::Image> codec;
string axis_host;
AxisCam *cam;
int frame_id;
- Axis_cam_node() : ros::node("axis_ptz"), cam(NULL), frame_id(0)
+ Axis_cam_node() : ros::node("axis_ptz"), codec(&image), cam(NULL), frame_id(0)
{
advertise<std_msgs::Image>("image");
@@ -71,12 +73,9 @@
image.set_data_size(jpeg_size);
memcpy(image.data, jpeg, jpeg_size);
- //TODO: Read width and height from somewhere else
- image.width = 704;
- image.height = 480;
image.compression = "jpeg";
- image.colorspace = "rgb24";
+ codec.inflate_header();
publish("image", image);
return true;
Modified: pkg/trunk/util/image_utils/include/image_utils/image_codec.h
===================================================================
--- pkg/trunk/util/image_utils/include/image_utils/image_codec.h 2008-06-17 22:00:23 UTC (rev 835)
+++ pkg/trunk/util/image_utils/include/image_utils/image_codec.h 2008-06-17 22:08:05 UTC (rev 836)
@@ -83,6 +83,24 @@
return raster;
}
+ bool inflate_header()
+ {
+ msg->lock();
+
+ // perform decompression and/or colorspace conversion if necessary
+ if (msg->compression == string("jpeg"))
+ decompress_jpeg_header();
+ else
+ {
+ printf("unimplemented image header compression: [%s]\n",
+ msg->compression.c_str());
+ msg->unlock();
+ return false;
+ }
+ msg->unlock();
+ return true;
+ }
+
uint32_t get_raster_size()
{
int bpp = 0;
@@ -92,6 +110,10 @@
bpp = 1;
else if (msg->colorspace == "mono16")
bpp = 2;
+ else {
+ printf("Undefined colorspace [%s]. Defaulting to 3 byte per pixel.\n", msg->colorspace.c_str());
+ bpp = 3;
+ }
return msg->width * msg->height * bpp;
}
@@ -162,6 +184,21 @@
memcpy(raster, jpeg->get_raster(), jpeg->raster_size());
return true;
}
+
+ bool decompress_jpeg_header()
+ {
+ if (!jpeg)
+ jpeg = new JpegWrapper();
+ if (!jpeg->decompress_jpeg_header((char *)msg->data, msg->get_data_size()))
+ return false;
+
+ msg->width = jpeg->width();
+ msg->height = jpeg->height();
+ msg->compression = "jpeg";
+ msg->colorspace = jpeg->color_space();
+
+ return true;
+ }
bool decompress_raw()
{
Modified: pkg/trunk/util/image_utils/include/image_utils/jpeg_wrapper.h
===================================================================
--- pkg/trunk/util/image_utils/include/image_utils/jpeg_wrapper.h 2008-06-17 22:00:23 UTC (rev 835)
+++ pkg/trunk/util/image_utils/include/image_utils/jpeg_wrapper.h 2008-06-17 22:08:05 UTC (rev 836)
@@ -9,6 +9,7 @@
}
#include <cstdlib>
#include <cstring>
+#include <string>
class JpegWrapper
{
@@ -44,6 +45,18 @@
inline int width() { return raster_width; }
inline int height() { return raster_height; }
+
+ std::string color_space()
+ {
+ if (raster_type == RT_MONO8)
+ return std::string("mono8");
+ else if (raster_type == RT_RGB24)
+ return std::string("rgb24");
+ else
+ return std::string("unknown");
+ }
+
+
inline int raster_size()
{
if (raster_type == RT_RGB24)
@@ -53,6 +66,7 @@
else
return 0;
}
+
inline uint8_t *get_raster() { return raster; }
bool decompress_jpeg_buf(char *data, uint32_t data_len)
@@ -86,6 +100,31 @@
ros_jpeg_mutex_unlock();
return true;
}
+
+ bool decompress_jpeg_header(char *data, uint32_t data_len)
+ {
+ ros_jpeg_mutex_lock();
+ jpeg_buffer_src(&dinfo, data, data_len);
+ jpeg_read_header(&dinfo, TRUE);
+ jpeg_start_decompress(&dinfo);
+ if (dinfo.out_color_space == JCS_GRAYSCALE) {
+ raster_type = RT_MONO8;
+ }
+ else if (dinfo.out_color_space == JCS_RGB)
+ {
+ raster_type = RT_RGB24;
+ }
+ else {
+ printf("woah! this jpeg buffer uses an unexpected color space.\n");
+ return false;
+ }
+ raster_width = dinfo.output_width;
+ raster_height = dinfo.output_height;
+ jpeg_abort_decompress(&dinfo);
+ ros_jpeg_mutex_unlock();
+ return true;
+ }
+
uint32_t compress_to_jpeg(uint8_t *raster, uint32_t w, uint32_t h,
raster_type_t raster_type = RT_RGB24,
int32_t quality = 95)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|