Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(570591)

Side by Side Diff: examples/analyzer.cc

Issue 815: Render analyzer frame using cairo
Patch Set: Render analyzer frame using cairo Created 4 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « configure.ac ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /*Daala video codec 1 /*Daala video codec
2 Copyright (c) 2002-2015 Daala project contributors. All rights reserved. 2 Copyright (c) 2002-2015 Daala project contributors. All rights reserved.
3 3
4 Redistribution and use in source and binary forms, with or without 4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met: 5 modification, are permitted provided that the following conditions are met:
6 6
7 - Redistributions of source code must retain the above copyright notice, this 7 - Redistributions of source code must retain the above copyright notice, this
8 list of conditions and the following disclaimer. 8 list of conditions and the following disclaimer.
9 9
10 - Redistributions in binary form must reproduce the above copyright notice, 10 - Redistributions in binary form must reproduce the above copyright notice,
(...skipping 12 matching lines...) Expand all
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ 23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
24 24
25 #ifdef HAVE_CONFIG_H 25 #ifdef HAVE_CONFIG_H
26 # include "config.h" 26 # include "config.h"
27 #endif 27 #endif
28 28
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <string.h> 30 #include <string.h>
31 #include <wx/wx.h> 31 #include <wx/wx.h>
32 #include <wx/dcbuffer.h> 32 #include <wx/dcbuffer.h>
33 #include <cairo.h>
33 34
34 #include <ogg/ogg.h> 35 #include <ogg/ogg.h>
35 36
36 #include "daala/codec.h" 37 #include "daala/codec.h"
37 #include "daala/daaladec.h" 38 #include "daala/daaladec.h"
38 39
39 /*Smallest blocks are 4x4*/ 40 /*Smallest blocks are 4x4*/
40 # define OD_LOG_BSIZE0 (2) 41 # define OD_LOG_BSIZE0 (2)
41 /*There are 4 block sizes total (4x4, 8x8, 16x16, 32x32).*/ 42 /*There are 4 block sizes total (4x4, 8x8, 16x16, 32x32).*/
42 # define OD_NBSIZES (4) 43 # define OD_NBSIZES (4)
43 /*The maximum length of the side of a block.*/ 44 /*The maximum length of the side of a block.*/
44 # define OD_BSIZE_MAX (1 << OD_LOG_BSIZE0 + OD_NBSIZES - 1) 45 # define OD_BSIZE_MAX (1 << OD_LOG_BSIZE0 + OD_NBSIZES - 1)
45 46
46 # define OD_MAXI(a, b) ((a) ^ (((a) ^ (b)) & -((b) > (a)))) 47 # define OD_MAXI(a, b) ((a) ^ (((a) ^ (b)) & -((b) > (a))))
47 # define OD_MINI(a, b) ((a) ^ (((b) ^ (a)) & -((b) < (a)))) 48 # define OD_MINI(a, b) ((a) ^ (((b) ^ (a)) & -((b) < (a))))
48 # define OD_CLAMPI(a, b, c) (OD_MAXI(a, OD_MINI(b, c))) 49 # define OD_CLAMPI(a, b, c) (OD_MAXI(a, OD_MINI(b, c)))
49 50
50 # define OD_SIGNMASK(a) (-((a) < 0)) 51 # define OD_SIGNMASK(a) (-((a) < 0))
51 # define OD_FLIPSIGNI(a, b) (((a) + OD_SIGNMASK(b)) ^ OD_SIGNMASK(b)) 52 # define OD_FLIPSIGNI(a, b) (((a) + OD_SIGNMASK(b)) ^ OD_SIGNMASK(b))
52 # define OD_DIV_ROUND(x, y) (((x) + OD_FLIPSIGNI((y) >> 1, x))/(y)) 53 # define OD_DIV_ROUND(x, y) (((x) + OD_FLIPSIGNI((y) >> 1, x))/(y))
53 54
54 # define OD_BLOCK_SIZE4x4(bsize, bstride, bx, by) \ 55 # define OD_BLOCK_SIZE4x4(bsize, bstride, bx, by) \
55 ((bsize)[((by) >> 1)*(bstride) + ((bx) >> 1)]) 56 ((bsize)[((by) >> 1)*(bstride) + ((bx) >> 1)])
57
58 od_img* img_clone(od_img* input) {
59 od_img *img;
60 od_img_plane *iplane;
61 od_img_plane *inputplane;
62 int pli;
63 img = (od_img *)malloc(sizeof(*img));
64 img->nplanes = input->nplanes;
65 img->width = input->width;
66 img->height = input->height;
67 for (pli = 0; pli < img->nplanes; pli++) {
68 iplane = img->planes + pli;
69 inputplane = input->planes + pli;
70 iplane->data = (unsigned char *)malloc(inputplane->ystride*img->height);
71 iplane->xdec = inputplane->xdec;
72 iplane->ydec = inputplane->ydec;
73 iplane->xstride = inputplane->xstride;
74 iplane->ystride = inputplane->ystride;
75 memcpy(iplane->data, inputplane->data, inputplane->ystride*img->height);
76 }
77 return img;
78 }
56 79
57 class DaalaDecoder { 80 class DaalaDecoder {
58 private: 81 private:
59 FILE *input; 82 FILE *input;
60 wxString path; 83 wxString path;
61 84
62 ogg_page page; 85 ogg_page page;
63 ogg_sync_state oy; 86 ogg_sync_state oy;
64 ogg_stream_state os; 87 ogg_stream_state os;
65 88
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 if (x < 16 && y < 16) return 6; 590 if (x < 16 && y < 16) return 6;
568 if (x < 32 && y < 8) return 7; 591 if (x < 32 && y < 8) return 7;
569 if (x < 8 && y < 32) return 8; 592 if (x < 8 && y < 32) return 8;
570 return 9; 593 return 9;
571 } 594 }
572 595
573 ogg_int64_t block_edge_luma(ogg_int64_t yval) { 596 ogg_int64_t block_edge_luma(ogg_int64_t yval) {
574 return yval > 50 ? yval >> 1 : yval + 15; 597 return yval > 50 ? yval >> 1 : yval + 15;
575 } 598 }
576 599
600 cairo_surface_t* create_from_img(od_img *img) {
601 unsigned char *y_row;
602 unsigned char *u_row;
603 unsigned char *v_row;
604 unsigned char *xrgb;
605 unsigned char *rgb;
606 int w;
607 int h;
608 int x;
609 int y;
610 int i;
611 int u_hdec;
612 int u_vdec;
613 int v_hdec;
614 int v_vdec;
615 cairo_surface_t *cs;
616 unsigned char * pixels;
617
618 w=img->width;
619 h=img->height;
620 u_hdec=img->planes[1].xdec;
621 u_vdec=img->planes[1].ydec;
622 v_hdec=img->planes[2].xdec;
623 v_vdec=img->planes[2].ydec;
624 y_row=img->planes[0].data;
625 u_row=img->planes[1].data;
626 v_row=img->planes[2].data;
627
628 pixels = (unsigned char *)malloc(sizeof(*pixels)*4*w*h);
629
630 /* convert the YUV image into our xRGB pixels buffer (Cairo requires
631 unpacked 32 bit RGB with one unused byte). This code works for
632 420, 422 and 444 */
633 xrgb = pixels;
634 for(y=0;y<h;y++){
635 for(x=0;x<w;x++){
636 unsigned int r;
637 unsigned int g;
638 unsigned int b;
639 int64_t yval;
640 int64_t cbval;
641 int64_t crval;
642 yval = y_row[x] - 16;
643 cbval = u_row[x>>u_hdec] - 128;
644 crval = v_row[x>>v_hdec] - 128;
645 r = OD_CLAMPI(0, (int32_t)OD_DIV_ROUND(
646 2916394880000LL*yval + 4490222169144LL*crval, 9745792000LL), 65535);
647 g = OD_CLAMPI(0, (int32_t)OD_DIV_ROUND(
648 2916394880000LL*yval - 534117096223LL*cbval - 1334761232047LL*crval,
649 9745792000LL), 65535);
650 b = OD_CLAMPI(0, (int32_t)OD_DIV_ROUND(
651 2916394880000LL*yval + 5290866304968LL*cbval, 9745792000LL), 65535);
652 xrgb[4*x+0] = (unsigned char)(b >> 8);
653 xrgb[4*x+1] = (unsigned char)(g >> 8);
654 xrgb[4*x+2] = (unsigned char)(r >> 8);
655 xrgb[4*x+3] = 0;
656 }
657 y_row+=img->planes[0].ystride;
658 u_row+=img->planes[1].ystride&-((y&1)|!u_vdec);
659 v_row+=img->planes[2].ystride&-((y&1)|!v_vdec);
660 xrgb+=4*w;
661 }
662
663 /* hand pixels to Cairo */
664 cs=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32,w,h,w*4);
665 if(cairo_surface_status(cs)!=CAIRO_STATUS_SUCCESS){
666 cairo_surface_destroy(cs);
667 return NULL;
668 }
669 return cs;
670 }
671
577 void TestPanel::render() { 672 void TestPanel::render() {
578 od_img *img = &dd.img; 673 od_img *img = img_clone(&dd.img);
674 cairo_surface_t *cs;
675 cairo_t *cr;
676 cairo_pattern_t *p;
677 cairo_surface_t *output_surface;
579 /* Assume both chroma planes are decimated the same */ 678 /* Assume both chroma planes are decimated the same */
580 int xdec = img->planes[1].xdec; 679 int xdec = img->planes[1].xdec;
581 int ydec = img->planes[1].ydec; 680 int ydec = img->planes[1].ydec;
582 int y_stride = img->planes[0].ystride; 681 int y_stride = img->planes[0].ystride;
583 int cb_stride = img->planes[1].ystride; 682 int cb_stride = img->planes[1].ystride;
584 int cr_stride = img->planes[2].ystride; 683 int cr_stride = img->planes[2].ystride;
585 int p_stride = 3*getDisplayWidth(); 684 int p_stride = 3*getDisplayWidth();
586 unsigned char *y_row = img->planes[0].data; 685 unsigned char *y_row = img->planes[0].data;
587 unsigned char *cb_row = img->planes[1].data; 686 unsigned char *cb_row = img->planes[1].data;
588 unsigned char *cr_row = img->planes[2].data; 687 unsigned char *cr_row = img->planes[2].data;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 cbval = (cbval + 128) >> 1; 796 cbval = (cbval + 128) >> 1;
698 crval = (crval + 128) >> 1; 797 crval = (crval + 128) >> 1;
699 pmask = OD_ALL_MASK; 798 pmask = OD_ALL_MASK;
700 } 799 }
701 } 800 }
702 if (i == dd.getWidth() || j == dd.getHeight()) { 801 if (i == dd.getWidth() || j == dd.getHeight()) {
703 /* Display a checkerboard pattern at the padding edge */ 802 /* Display a checkerboard pattern at the padding edge */
704 yval = 255 * ((i + j) & 1); 803 yval = 255 * ((i + j) & 1);
705 pmask = OD_ALL_MASK; 804 pmask = OD_ALL_MASK;
706 } 805 }
707 if (pmask & OD_LUMA_MASK) { 806 if (!(pmask & OD_LUMA_MASK)) {
708 yval -= 16; 807 yval = 144;
709 } else {
710 yval = 128;
711 } 808 }
712 cbval = ((pmask & OD_CB_MASK) >> 1) * (cbval - 128); 809 cbval = ((pmask & OD_CB_MASK) >> 1) * (cbval);
713 crval = ((pmask & OD_CR_MASK) >> 2) * (crval - 128); 810 crval = ((pmask & OD_CR_MASK) >> 2) * (crval);
714 /*This is intentionally slow and very accurate.*/ 811 *y = OD_CLAMPI(16,yval,235);
715 rval = OD_CLAMPI(0, (ogg_int32_t)OD_DIV_ROUND( 812 *cb = OD_CLAMPI(16,cbval,235);
716 2916394880000LL*yval + 4490222169144LL*crval, 9745792000LL), 65535); 813 *cr = OD_CLAMPI(16,crval,235);
717 gval = OD_CLAMPI(0, (ogg_int32_t)OD_DIV_ROUND(
718 2916394880000LL*yval - 534117096223LL*cbval - 1334761232047LL*crval,
719 9745792000LL), 65535);
720 bval = OD_CLAMPI(0, (ogg_int32_t)OD_DIV_ROUND(
721 2916394880000LL*yval + 5290866304968LL*cbval, 9745792000LL), 65535);
722 unsigned char *px_row = p;
723 for (int v = 0; v < zoom; v++) {
724 unsigned char *px = px_row;
725 for (int u = 0; u < zoom; u++) {
726 *(px + 0) = (unsigned char)(rval >> 8);
727 *(px + 1) = (unsigned char)(gval >> 8);
728 *(px + 2) = (unsigned char)(bval >> 8);
729 px += 3;
730 }
731 px_row += p_stride;
732 }
733 int dc = ((y - y_row) & 1) | (1 - xdec); 814 int dc = ((y - y_row) & 1) | (1 - xdec);
734 y++; 815 y++;
735 cb += dc; 816 cb += dc;
736 cr += dc; 817 cr += dc;
737 p += zoom*3;
738 } 818 }
739 int dc = -((j & 1) | (1 - ydec)); 819 int dc = -((j & 1) | (1 - ydec));
740 y_row += y_stride; 820 y_row += y_stride;
741 cb_row += dc & cb_stride; 821 cb_row += dc & cb_stride;
742 cr_row += dc & cr_stride; 822 cr_row += dc & cr_stride;
743 p_row += zoom*p_stride;
744 } 823 }
824 cs = create_from_img(img);
825 cairo_surface_flush(cs);
826 output_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
827 getDisplayWidth(), getDisplayHeight());
828 cr = cairo_create(output_surface);
829 cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
830 cairo_scale(cr, zoom, zoom);
831 cairo_set_source_surface (cr, cs, 0, 0);
832 p = cairo_get_source(cr);
833 cairo_pattern_set_filter(p, CAIRO_FILTER_NEAREST);
834 cairo_paint(cr);
835 cairo_surface_flush(output_surface);
836 unsigned char *cairo_pixels = cairo_image_surface_get_data(output_surface);
837 unsigned char *wx_pixels = pixels;
838 for(int i = 0; i < getDisplayWidth()*getDisplayHeight(); i++){
839 *wx_pixels++ = cairo_pixels[2];
840 *wx_pixels++ = cairo_pixels[1];
841 *wx_pixels++ = cairo_pixels[0];
842 cairo_pixels += 4;
843 }
844 cairo_destroy(cr);
845 cairo_surface_destroy(cs);
846 cairo_surface_destroy(output_surface);
745 } 847 }
746 848
747 int TestPanel::getZoom() const { 849 int TestPanel::getZoom() const {
748 return zoom; 850 return zoom;
749 } 851 }
750 852
751 bool TestPanel::updateDisplaySize() { 853 bool TestPanel::updateDisplaySize() {
752 unsigned char *p = 854 unsigned char *p =
753 (unsigned char *)malloc(sizeof(*p)*3*getDisplayWidth()*getDisplayHeight()); 855 (unsigned char *)malloc(sizeof(*p)*3*getDisplayWidth()*getDisplayHeight());
754 if (p == NULL) { 856 if (p == NULL) {
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 bool TestApp::OnInit() { 1315 bool TestApp::OnInit() {
1214 frame = new TestFrame(); 1316 frame = new TestFrame();
1215 frame->Show(); 1317 frame->Show();
1216 if (argc >= 2) { 1318 if (argc >= 2) {
1217 return frame->open(wxString(argv[1])); 1319 return frame->open(wxString(argv[1]));
1218 } 1320 }
1219 return true; 1321 return true;
1220 } 1322 }
1221 1323
1222 IMPLEMENT_APP(TestApp) 1324 IMPLEMENT_APP(TestApp)
OLDNEW
« no previous file with comments | « configure.ac ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld