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

Side by Side Diff: examples/analyzer.cc

Issue 815: Render analyzer frame using cairo
Patch Set: Created 4 years, 8 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 "daala/codec.h" 35 #include "daala/codec.h"
35 #include "daala/daaladec.h" 36 #include "daala/daaladec.h"
36 37
37 /*Smallest blocks are 4x4*/ 38 /*Smallest blocks are 4x4*/
38 # define OD_LOG_BSIZE0 (2) 39 # define OD_LOG_BSIZE0 (2)
39 /*There are 4 block sizes total (4x4, 8x8, 16x16, 32x32).*/ 40 /*There are 4 block sizes total (4x4, 8x8, 16x16, 32x32).*/
40 # define OD_NBSIZES (4) 41 # define OD_NBSIZES (4)
41 /*The maximum length of the side of a block.*/ 42 /*The maximum length of the side of a block.*/
42 # define OD_BSIZE_MAX (1 << OD_LOG_BSIZE0 + OD_NBSIZES - 1) 43 # define OD_BSIZE_MAX (1 << OD_LOG_BSIZE0 + OD_NBSIZES - 1)
43 44
44 # define OD_MAXI(a, b) ((a) ^ (((a) ^ (b)) & -((b) > (a)))) 45 # define OD_MAXI(a, b) ((a) ^ (((a) ^ (b)) & -((b) > (a))))
45 # define OD_MINI(a, b) ((a) ^ (((b) ^ (a)) & -((b) < (a)))) 46 # define OD_MINI(a, b) ((a) ^ (((b) ^ (a)) & -((b) < (a))))
46 # define OD_CLAMPI(a, b, c) (OD_MAXI(a, OD_MINI(b, c))) 47 # define OD_CLAMPI(a, b, c) (OD_MAXI(a, OD_MINI(b, c)))
47 48
48 # define OD_SIGNMASK(a) (-((a) < 0)) 49 # define OD_SIGNMASK(a) (-((a) < 0))
49 # define OD_FLIPSIGNI(a, b) (((a) + OD_SIGNMASK(b)) ^ OD_SIGNMASK(b)) 50 # define OD_FLIPSIGNI(a, b) (((a) + OD_SIGNMASK(b)) ^ OD_SIGNMASK(b))
50 # define OD_DIV_ROUND(x, y) (((x) + OD_FLIPSIGNI((y) >> 1, x))/(y)) 51 # define OD_DIV_ROUND(x, y) (((x) + OD_FLIPSIGNI((y) >> 1, x))/(y))
51 52
52 # define OD_BLOCK_SIZE4x4(bsize, bstride, bx, by) \ 53 # define OD_BLOCK_SIZE4x4(bsize, bstride, bx, by) \
53 ((bsize)[((by) >> 1)*(bstride) + ((bx) >> 1)]) 54 ((bsize)[((by) >> 1)*(bstride) + ((bx) >> 1)])
55
56 od_img* img_clone(od_img* input) {
57 od_img *img;
58 od_img_plane *iplane;
59 od_img_plane *inputplane;
60 int pli;
61 img = (od_img *)malloc(sizeof(*img));
62 img->nplanes = input->nplanes;
63 img->width = input->width;
64 img->height = input->height;
65 for (pli = 0; pli < img->nplanes; pli++) {
66 iplane = img->planes + pli;
67 inputplane = input->planes + pli;
68 iplane->data = (unsigned char *)malloc(inputplane->ystride*img->height);
69 iplane->xdec = inputplane->xdec;
70 iplane->ydec = inputplane->ydec;
71 iplane->xstride = inputplane->xstride;
72 iplane->ystride = inputplane->ystride;
73 memcpy(iplane->data, inputplane->data, inputplane->ystride*img->height);
74 }
75 return img;
76 }
54 77
55 class DaalaDecoder { 78 class DaalaDecoder {
56 private: 79 private:
57 FILE *input; 80 FILE *input;
58 const char *path; 81 const char *path;
59 82
60 ogg_page page; 83 ogg_page page;
61 ogg_sync_state oy; 84 ogg_sync_state oy;
62 ogg_stream_state os; 85 ogg_stream_state os;
63 86
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (x < 16 && y < 16) return 6; 471 if (x < 16 && y < 16) return 6;
449 if (x < 32 && y < 8) return 7; 472 if (x < 32 && y < 8) return 7;
450 if (x < 8 && y < 32) return 8; 473 if (x < 8 && y < 32) return 8;
451 return 9; 474 return 9;
452 } 475 }
453 476
454 ogg_int64_t block_edge_luma(ogg_int64_t yval) { 477 ogg_int64_t block_edge_luma(ogg_int64_t yval) {
455 return yval > 50 ? yval >> 1 : yval + 15; 478 return yval > 50 ? yval >> 1 : yval + 15;
456 } 479 }
457 480
481 cairo_surface_t* create_from_img(od_img *img) {
482 unsigned char *y_row;
483 unsigned char *u_row;
484 unsigned char *v_row;
485 unsigned char *xrgb;
486 unsigned char *rgb;
487 int w;
488 int h;
489 int x;
490 int y;
491 int i;
492 int u_hdec;
493 int u_vdec;
494 int v_hdec;
495 int v_vdec;
496 cairo_surface_t *cs;
497 unsigned char * pixels;
498
499 w=img->width;
500 h=img->height;
501 u_hdec=img->planes[1].xdec;
502 u_vdec=img->planes[1].ydec;
503 v_hdec=img->planes[2].xdec;
504 v_vdec=img->planes[2].ydec;
505 y_row=img->planes[0].data;
506 u_row=img->planes[1].data;
507 v_row=img->planes[2].data;
tmatth 2015/06/25 10:28:47 spaces needed around = operator
508
509 pixels = (unsigned char *)malloc(sizeof(*pixels)*4*w*h);
510
511 /* convert the YUV image into our xRGB pixels buffer (Cairo requires
512 unpacked 32 bit RGB with one unused byte). This code works for
513 420, 422 and 444 */
514 xrgb = pixels;
515 for(y=0;y<h;y++){
516 for(x=0;x<w;x++){
tmatth 2015/06/25 10:28:47 Should be for (y = 0; y < h; y++) for (x = 0; x <
517 unsigned int r;
518 unsigned int g;
519 unsigned int b;
520 int64_t yval;
521 int64_t cbval;
522 int64_t crval;
523 yval = y_row[x] - 16;
524 cbval = u_row[x>>u_hdec] - 128;
525 crval = v_row[x>>v_hdec] - 128;
tmatth 2015/06/25 10:28:47 spaces needed around shift operators
526 r = OD_CLAMPI(0, (int32_t)OD_DIV_ROUND(
527 2916394880000LL*yval + 4490222169144LL*crval, 9745792000LL), 65535);
528 g = OD_CLAMPI(0, (int32_t)OD_DIV_ROUND(
529 2916394880000LL*yval - 534117096223LL*cbval - 1334761232047LL*crval,
530 9745792000LL), 65535);
531 b = OD_CLAMPI(0, (int32_t)OD_DIV_ROUND(
532 2916394880000LL*yval + 5290866304968LL*cbval, 9745792000LL), 65535);
533 xrgb[4*x+0] = (unsigned char)(b >> 8);
534 xrgb[4*x+1] = (unsigned char)(g >> 8);
535 xrgb[4*x+2] = (unsigned char)(r >> 8);
536 xrgb[4*x+3] = 0;
tmatth 2015/06/25 10:28:47 spaces needed around + operators
537 }
538 y_row+=img->planes[0].ystride;
539 u_row+=img->planes[1].ystride&-((y&1)|!u_vdec);
540 v_row+=img->planes[2].ystride&-((y&1)|!v_vdec);
541 xrgb+=4*w;
542 }
543
544 /* hand pixels to Cairo */
545 cs=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32,w,h,w*4);
546 if(cairo_surface_status(cs)!=CAIRO_STATUS_SUCCESS){
547 cairo_surface_destroy(cs);
548 return NULL;
549 }
550 return cs;
551 }
552
458 void TestPanel::render() { 553 void TestPanel::render() {
459 od_img *img = &dd.img; 554 od_img *img = img_clone(&dd.img);
555 cairo_surface_t *cs;
tmatth 2015/06/25 10:28:47 normally we do var declarations at the top of the
460 /* Assume both chroma planes are decimated the same */ 556 /* Assume both chroma planes are decimated the same */
461 int xdec = img->planes[1].xdec; 557 int xdec = img->planes[1].xdec;
462 int ydec = img->planes[1].ydec; 558 int ydec = img->planes[1].ydec;
463 int y_stride = img->planes[0].ystride; 559 int y_stride = img->planes[0].ystride;
464 int cb_stride = img->planes[1].ystride; 560 int cb_stride = img->planes[1].ystride;
465 int cr_stride = img->planes[2].ystride; 561 int cr_stride = img->planes[2].ystride;
466 int p_stride = 3*getDisplayWidth(); 562 int p_stride = 3*getDisplayWidth();
467 unsigned char *y_row = img->planes[0].data; 563 unsigned char *y_row = img->planes[0].data;
468 unsigned char *cb_row = img->planes[1].data; 564 unsigned char *cb_row = img->planes[1].data;
469 unsigned char *cr_row = img->planes[2].data; 565 unsigned char *cr_row = img->planes[2].data;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 yval = 255 * ((i + j) & 1); 623 yval = 255 * ((i + j) & 1);
528 pmask = OD_ALL_MASK; 624 pmask = OD_ALL_MASK;
529 } 625 }
530 if (pmask & OD_LUMA_MASK) { 626 if (pmask & OD_LUMA_MASK) {
531 yval -= 16; 627 yval -= 16;
532 } else { 628 } else {
533 yval = 128; 629 yval = 128;
534 } 630 }
535 cbval = ((pmask & OD_CB_MASK) >> 1) * (cbval - 128); 631 cbval = ((pmask & OD_CB_MASK) >> 1) * (cbval - 128);
536 crval = ((pmask & OD_CR_MASK) >> 2) * (crval - 128); 632 crval = ((pmask & OD_CR_MASK) >> 2) * (crval - 128);
537 /*This is intentionally slow and very accurate.*/ 633 *y = yval;
538 rval = OD_CLAMPI(0, (ogg_int32_t)OD_DIV_ROUND( 634 *cb = cbval;
539 2916394880000LL*yval + 4490222169144LL*crval, 9745792000LL), 65535); 635 *cr = crval;
540 gval = OD_CLAMPI(0, (ogg_int32_t)OD_DIV_ROUND(
541 2916394880000LL*yval - 534117096223LL*cbval - 1334761232047LL*crval,
542 9745792000LL), 65535);
543 bval = OD_CLAMPI(0, (ogg_int32_t)OD_DIV_ROUND(
544 2916394880000LL*yval + 5290866304968LL*cbval, 9745792000LL), 65535);
545 unsigned char *px_row = p;
546 for (int v = 0; v < zoom; v++) {
547 unsigned char *px = px_row;
548 for (int u = 0; u < zoom; u++) {
549 *(px + 0) = (unsigned char)(rval >> 8);
550 *(px + 1) = (unsigned char)(gval >> 8);
551 *(px + 2) = (unsigned char)(bval >> 8);
552 px += 3;
553 }
554 px_row += p_stride;
555 }
556 int dc = ((y - y_row) & 1) | (1 - xdec); 636 int dc = ((y - y_row) & 1) | (1 - xdec);
557 y++; 637 y++;
558 cb += dc; 638 cb += dc;
559 cr += dc; 639 cr += dc;
560 p += zoom*3;
561 } 640 }
562 int dc = -((j & 1) | (1 - ydec)); 641 int dc = -((j & 1) | (1 - ydec));
563 y_row += y_stride; 642 y_row += y_stride;
564 cb_row += dc & cb_stride; 643 cb_row += dc & cb_stride;
565 cr_row += dc & cr_stride; 644 cr_row += dc & cr_stride;
566 p_row += zoom*p_stride;
567 } 645 }
646 cs = create_from_img(img);
647 cairo_surface_flush(cs);
648 unsigned char *cairo_pixels = cairo_image_surface_get_data(cs);
649 unsigned char *wx_pixels = pixels;
650 for(int i = 0; i < dd.getWidth()*dd.getHeight(); i++){
tmatth 2015/06/25 10:28:47 for (int
651 *wx_pixels++ = cairo_pixels[2];
652 *wx_pixels++ = cairo_pixels[1];
653 *wx_pixels++ = cairo_pixels[0];
654 cairo_pixels += 4;
655 }
656 cairo_surface_destroy(cs);
568 } 657 }
569 658
570 int TestPanel::getZoom() const { 659 int TestPanel::getZoom() const {
571 return zoom; 660 return zoom;
572 } 661 }
573 662
574 bool TestPanel::updateDisplaySize() { 663 bool TestPanel::updateDisplaySize() {
575 unsigned char *p = 664 unsigned char *p =
576 (unsigned char *)malloc(sizeof(*p)*3*getDisplayWidth()*getDisplayHeight()); 665 (unsigned char *)malloc(sizeof(*p)*3*getDisplayWidth()*getDisplayHeight());
577 if (p == NULL) { 666 if (p == NULL) {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 bool TestApp::OnInit() { 944 bool TestApp::OnInit() {
856 frame = new TestFrame(); 945 frame = new TestFrame();
857 frame->Show(); 946 frame->Show();
858 if (argc >= 2) { 947 if (argc >= 2) {
859 return frame->open(wxString(argv[1])); 948 return frame->open(wxString(argv[1]));
860 } 949 }
861 return true; 950 return true;
862 } 951 }
863 952
864 IMPLEMENT_APP(TestApp) 953 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