PERFORCE change 219345 for review
Brooks Davis
brooks at FreeBSD.org
Tue Oct 30 16:11:10 UTC 2012
http://p4web.freebsd.org/@@219345?ac=10
Change 219345 by brooks at brooks_zenith on 2012/10/30 16:10:13
Checkpoint a split of pngsb into an image reading library and
and program.
Affected files ...
.. //depot/projects/ctsrd/beribsd/src/ctsrd-lib/Makefile#5 edit
.. //depot/projects/ctsrd/beribsd/src/ctsrd-lib/libimagebox/Makefile#1 add
.. //depot/projects/ctsrd/beribsd/src/ctsrd-lib/libimagebox/imagebox.h#1 add
.. //depot/projects/ctsrd/beribsd/src/ctsrd-lib/libimagebox/pngbox.c#1 add
.. //depot/projects/ctsrd/beribsd/src/ctsrd/pngsb/Makefile#3 edit
.. //depot/projects/ctsrd/beribsd/src/ctsrd/pngsb/pngsb.c#3 edit
Differences ...
==== //depot/projects/ctsrd/beribsd/src/ctsrd-lib/Makefile#5 (text+ko) ====
@@ -4,6 +4,7 @@
.include <bsd.own.mk>
SUBDIR= libde4tc \
+ libimagebox \
libvuln_magic \
libvuln_png
==== //depot/projects/ctsrd/beribsd/src/ctsrd/pngsb/Makefile#3 (text+ko) ====
@@ -4,8 +4,9 @@
WARNS= 6
-CFLAGS+= -I${.CURDIR}/../../ctsrd-lib/libvuln_png/
-LDFLAGS+= -L/usr/local/lib
-LDADD+= -lpthread -lvuln_png -lz -lm
+CFLAGS+= -I${.CURDIR}/../../ctsrd-lib/libimagebox/ \
+ -I${.CURDIR}/../../ctsrd-lib/libvuln_png/
+#LDFLAGS+= -L/usr/local/lib
+LDADD+= -lpthread -lde4tc -limagebox -lvuln_png -lz -lm
.include <bsd.prog.mk>
==== //depot/projects/ctsrd/beribsd/src/ctsrd/pngsb/pngsb.c#3 (text+ko) ====
@@ -32,9 +32,11 @@
#include <sys/endian.h>
+#include <de4tc.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <imagebox.h>
#include <png.h>
#include <pthread.h>
#include <stdint.h>
@@ -42,6 +44,7 @@
#include <stdlib.h>
#include <unistd.h>
+#if 0
static void read_row_callback(png_structp, png_uint_32, int);
static void read_png_from_fd(png_structp, png_bytep, png_size_t);
@@ -131,6 +134,8 @@
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, &interlace_type, NULL, NULL);
+ printf("bit_depth = %d, color_type = %d\n", bit_depth, color_type);
+
if (width != pds->ps->width || height != pds->ps->height) {
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
pds->ps->error = 1;
@@ -139,9 +144,11 @@
pthread_exit(NULL);
}
- png_set_filler(png_ptr, 0, 0);
png_set_gray_to_rgb(png_ptr);
+ png_set_bgr(png_ptr);
+ png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
pds->ps->passes_remaining = png_set_interlace_handling(png_ptr);
+ png_read_update_info(png_ptr, info_ptr);
if ((rows = malloc(height*sizeof(png_bytep))) == NULL)
png_error(png_ptr, "failed to malloc row array");
@@ -266,6 +273,7 @@
free(__DEVOLATILE(void*, ps->buffer));
free(ps);
}
+#endif
static void
usage(void)
@@ -273,6 +281,7 @@
errx(1, "usage: pngsb <file>");
}
+#if 0
static void
read_row_callback(png_structp png_ptr, png_uint_32 row, int pass __unused)
{
@@ -296,36 +305,59 @@
if (rlen < 0 || (png_size_t)rlen != length)
png_error(png_ptr, "read error");
}
+#endif
int
main(int argc, char **argv)
{
int pfd;
- uint32_t last_row = -1;
- struct pngstate *ps;
+ uint32_t i, last_row = 0;
+ struct iboxstate *ps;
if (argc != 2)
usage();
+ fb_init();
+
if ((pfd = open(argv[1], O_RDONLY)) < -1)
err(1, "open(%s)", argv[1]);
- if ((ps = png_read_start(pfd, 800, 480)) == NULL)
+ if ((ps = png_read_start(pfd, 800, 480, SB_NONE)) == NULL)
err(1, "failed to initialize read of %s", argv[1]);
/* XXX: do something with the valid parts of the image as it decodes. */
- while(ps->valid_rows < ps->height) {
+ while(ps->valid_rows < ps->height ) {
if (last_row != ps->valid_rows) {
+ for (i = last_row; i < ps->valid_rows; i++)
+ memcpy(__DEVOLATILE(void*,
+ pfbp + (i * fb_width)),
+ __DEVOLATILE(void *,
+ ps->buffer + (i * ps->width)),
+ sizeof(uint32_t) * ps->width);
last_row = ps->valid_rows;
printf("valid_rows = %d\n", ps->valid_rows);
}
+#if 0
+ pthread_yield();
+#endif
+ }
+ if (last_row != ps->valid_rows) {
+ for (i = last_row; i < ps->valid_rows; i++)
+ memcpy(__DEVOLATILE(void*,
+ pfbp + (i * fb_width)),
+ __DEVOLATILE(void *,
+ ps->buffer + (i * ps->width)),
+ sizeof(uint32_t) * ps->width);
+ last_row = ps->valid_rows;
}
printf("valid_rows = %d\n", ps->valid_rows);
if (png_read_finish(ps) != 0)
errx(1, "png_read_finish failed");
- pngstate_free(ps);
+ iboxstate_free(ps);
+
+ fb_fini();
return(0);
}
More information about the p4-projects
mailing list