Add an NX/TIFF screenshot from Petteri Aimonen (Patch 0014)
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5690 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
5d1fdfbf04
commit
f275b573f9
4
Kconfig
4
Kconfig
@ -11,6 +11,10 @@ menu "Examples"
|
|||||||
source "$APPSDIR/examples/Kconfig"
|
source "$APPSDIR/examples/Kconfig"
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
menu "Graphics Support"
|
||||||
|
source "$APPSDIR/graphics/Kconfig"
|
||||||
|
endmenu
|
||||||
|
|
||||||
menu "Interpreters"
|
menu "Interpreters"
|
||||||
source "$APPSDIR/interpreters/Kconfig"
|
source "$APPSDIR/interpreters/Kconfig"
|
||||||
endmenu
|
endmenu
|
||||||
|
@ -4,10 +4,15 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
config TIFF
|
config TIFF
|
||||||
bool "TIFF file generation utility"
|
bool "TIFF file generation library"
|
||||||
default n
|
default n
|
||||||
---help---
|
---help---
|
||||||
Enable support for the TIFF file generation program.
|
Enable support for the TIFF file generation program.
|
||||||
|
|
||||||
if TIFF
|
if TIFF
|
||||||
|
|
||||||
|
menu "TIFF Screenshot Utility"
|
||||||
|
source "$APPSDIR/graphics/screenshot/Kconfig"
|
||||||
|
endmenu
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
@ -38,3 +38,6 @@ ifeq ($(CONFIG_TIFF),y)
|
|||||||
CONFIGURED_APPS += graphics/tiff
|
CONFIGURED_APPS += graphics/tiff
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_GRAPHICS_SCREENSHOT),y)
|
||||||
|
CONFIGURED_APPS += graphics/screenshot
|
||||||
|
endif
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
# Sub-directories
|
# Sub-directories
|
||||||
|
|
||||||
SUBDIRS = tiff
|
SUBDIRS = tiff screenshot
|
||||||
|
|
||||||
# Sub-directories that might need context setup
|
# Sub-directories that might need context setup
|
||||||
|
|
||||||
|
34
graphics/screenshot/Kconfig
Normal file
34
graphics/screenshot/Kconfig
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#
|
||||||
|
# For a description of the syntax of this configuration file,
|
||||||
|
# see misc/tools/kconfig-language.txt.
|
||||||
|
#
|
||||||
|
|
||||||
|
config GRAPHICS_SCREENSHOT
|
||||||
|
bool "TIFF screenshot utility"
|
||||||
|
default n
|
||||||
|
depends on TIFF && NX
|
||||||
|
---help---
|
||||||
|
Generate a NX screenshot utility based on the TIFF library.
|
||||||
|
|
||||||
|
if GRAPHICS_SCREENSHOT
|
||||||
|
|
||||||
|
config SCREENSHOT_WIDTH
|
||||||
|
int "Screenshot width (in pixels)"
|
||||||
|
default 320
|
||||||
|
---help---
|
||||||
|
The width of the screenshot in pixels/columns.
|
||||||
|
|
||||||
|
config SCREENSHOT_HEIGHT
|
||||||
|
int "Screenshot height (in lines)"
|
||||||
|
default 240
|
||||||
|
---help---
|
||||||
|
The height of the screenshot in pixels/rows.
|
||||||
|
|
||||||
|
config SCREENSHOT_FORMAT
|
||||||
|
int "Screenshot color format"
|
||||||
|
default 9
|
||||||
|
---help---
|
||||||
|
See inlcude/nuttx/fb.h for a list of color formats. The default
|
||||||
|
value of 9 corresponds to FB_FMT_RGB16_565
|
||||||
|
|
||||||
|
endif
|
113
graphics/screenshot/Makefile
Normal file
113
graphics/screenshot/Makefile
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/examples/screenshot/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in
|
||||||
|
# the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software
|
||||||
|
# without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/.config
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
include $(APPDIR)/Make.defs
|
||||||
|
|
||||||
|
ifeq ($(WINTOOL),y)
|
||||||
|
INCDIROPT = -w
|
||||||
|
endif
|
||||||
|
|
||||||
|
# TIFF Screenshot utility
|
||||||
|
|
||||||
|
ASRCS =
|
||||||
|
CSRCS = screenshot_main.c
|
||||||
|
|
||||||
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
OBJS = $(AOBJS) $(COBJS)
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||||
|
BIN = ..\..\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
ifeq ($(WINTOOL),y)
|
||||||
|
BIN = ..\\..\\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
BIN = ../../libapps$(LIBEXT)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ROOTDEPPATH = --dep-path .
|
||||||
|
|
||||||
|
# TIFF screen built-in application info
|
||||||
|
|
||||||
|
APPNAME = screenshot
|
||||||
|
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||||
|
STACKSIZE = 4096
|
||||||
|
|
||||||
|
# Common build
|
||||||
|
|
||||||
|
VPATH =
|
||||||
|
|
||||||
|
all: .built
|
||||||
|
.PHONY: clean depend distclean
|
||||||
|
|
||||||
|
$(AOBJS): %$(OBJEXT): %.S
|
||||||
|
$(call ASSEMBLE, $<, $@)
|
||||||
|
|
||||||
|
$(COBJS): %$(OBJEXT): %.c
|
||||||
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
|
.built: $(OBJS)
|
||||||
|
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||||
|
$(Q) touch .built
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||||
|
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||||
|
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||||
|
|
||||||
|
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||||
|
else
|
||||||
|
context:
|
||||||
|
endif
|
||||||
|
|
||||||
|
.depend: Makefile $(SRCS)
|
||||||
|
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
$(Q) touch $@
|
||||||
|
|
||||||
|
depend: .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(call DELFILE, .built)
|
||||||
|
$(call CLEAN)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(call DELFILE, Make.dep)
|
||||||
|
$(call DELFILE, .depend)
|
||||||
|
|
||||||
|
-include Make.dep
|
238
graphics/screenshot/screenshot_main.c
Normal file
238
graphics/screenshot/screenshot_main.c
Normal file
@ -0,0 +1,238 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/examples/screenshot/screenshot_main.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
* Petteri Aimonen <jpa@kapsi.fi>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <apps/tiff.h>
|
||||||
|
|
||||||
|
#include <semaphore.h>
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/nx/nx.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-Processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_SCREENSHOT_WIDTH
|
||||||
|
# define CONFIG_SCREENSHOT_WIDTH 320
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_SCREENSHOT_HEIGHT
|
||||||
|
# define CONFIG_SCREENSHOT_HEIGHT 240
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_SCREENSHOT_FORMAT
|
||||||
|
# define CONFIG_SCREENSHOT_FORMAT FB_FMT_RGB16_565
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void replace_extension(FAR const char *filename, FAR const char *newext,
|
||||||
|
FAR char *dest, size_t size)
|
||||||
|
{
|
||||||
|
FAR char *p = strrchr(filename, '.');
|
||||||
|
int len = strlen(filename);
|
||||||
|
|
||||||
|
if (p != NULL)
|
||||||
|
{
|
||||||
|
len = p - filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > size)
|
||||||
|
{
|
||||||
|
len = size - strlen(newext);
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(dest, filename, size);
|
||||||
|
strncpy(dest + len, newext, size - len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: save_screenshot
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Takes a screenshot and saves it to a tif file.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int save_screenshot(FAR const char *filename)
|
||||||
|
{
|
||||||
|
struct tiff_info_s info;
|
||||||
|
FAR uint8_t *strip;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int ret;
|
||||||
|
char tempf1[64];
|
||||||
|
char tempf2[64];
|
||||||
|
NXHANDLE server;
|
||||||
|
NXWINDOW window;
|
||||||
|
struct nx_callback_s cb = {};
|
||||||
|
struct nxgl_size_s size = {CONFIG_SCREENSHOT_WIDTH, CONFIG_SCREENSHOT_HEIGHT};
|
||||||
|
|
||||||
|
replace_extension(filename, ".tm1", tempf1, sizeof(tempf1));
|
||||||
|
replace_extension(filename, ".tm2", tempf2, sizeof(tempf2));
|
||||||
|
|
||||||
|
/* Connect to NX server */
|
||||||
|
|
||||||
|
server = nx_connect();
|
||||||
|
if (!server)
|
||||||
|
{
|
||||||
|
perror("nx_connect");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for "connected" event */
|
||||||
|
|
||||||
|
if (nx_eventhandler(server) < 0)
|
||||||
|
{
|
||||||
|
perror("nx_eventhandler");
|
||||||
|
nx_disconnect(server);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Open invisible dummy window for communication */
|
||||||
|
|
||||||
|
window = nx_openwindow(server, &cb, NULL);
|
||||||
|
if (!window)
|
||||||
|
{
|
||||||
|
perror("nx_openwindow");
|
||||||
|
nx_disconnect(server);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
nx_setsize(window, &size);
|
||||||
|
|
||||||
|
/* Configure the TIFF structure */
|
||||||
|
|
||||||
|
memset(&info, 0, sizeof(struct tiff_info_s));
|
||||||
|
info.outfile = filename;
|
||||||
|
info.tmpfile1 = tempf1;
|
||||||
|
info.tmpfile2 = tempf2;
|
||||||
|
info.colorfmt = CONFIG_SCREENSHOT_FORMAT;
|
||||||
|
info.rps = 1;
|
||||||
|
info.imgwidth = size.w;
|
||||||
|
info.imgheight = size.h;
|
||||||
|
info.iobuffer = (uint8_t *)malloc(300);
|
||||||
|
info.iosize = 300;
|
||||||
|
|
||||||
|
/* Initialize the TIFF library */
|
||||||
|
|
||||||
|
ret = tiff_initialize(&info);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("tiff_initialize() failed: %d\n", ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add each strip to the TIFF file */
|
||||||
|
|
||||||
|
strip = malloc(size.w * 3);
|
||||||
|
|
||||||
|
for (int y = 0; y < size.h; y++)
|
||||||
|
{
|
||||||
|
struct nxgl_rect_s rect = {{0, y}, {size.w - 1, y}};
|
||||||
|
nx_getrectangle(window, &rect, 0, strip, 0);
|
||||||
|
|
||||||
|
ret = tiff_addstrip(&info, strip);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("tiff_addstrip() #%d failed: %d\n", y, ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(strip);
|
||||||
|
|
||||||
|
/* Then finalize the TIFF file */
|
||||||
|
|
||||||
|
ret = tiff_finalize(&info);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
printf("tiff_finalize() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(info.iobuffer);
|
||||||
|
nx_closewindow(window);
|
||||||
|
nx_disconnect(server);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: screenshot_main
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Main entry point for the screenshot NSH application.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int screenshot_main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: screenshot file.tif\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return save_screenshot(argv[1]);
|
||||||
|
}
|
@ -34,9 +34,6 @@
|
|||||||
#
|
#
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
# TODO, this makefile should run make under the app dirs, instead of
|
|
||||||
# sourcing the Make.defs!
|
|
||||||
|
|
||||||
-include $(TOPDIR)/.config
|
-include $(TOPDIR)/.config
|
||||||
-include $(TOPDIR)/Make.defs
|
-include $(TOPDIR)/Make.defs
|
||||||
include $(APPDIR)/Make.defs
|
include $(APPDIR)/Make.defs
|
||||||
|
Loading…
Reference in New Issue
Block a user