[svn] / branches / dev-api-3 / xvidcore / src / image / image.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/image/image.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 586, Wed Oct 9 15:56:16 2002 UTC revision 631, Thu Nov 7 10:31:03 2002 UTC
# Line 54  Line 54 
54  #include <math.h>  #include <math.h>
55    
56  #include "../portab.h"  #include "../portab.h"
57    #include "../global.h"                  // XVID_CSP_XXX's
58  #include "../xvid.h"                    // XVID_CSP_XXX's  #include "../xvid.h"                    // XVID_CSP_XXX's
59  #include "image.h"  #include "image.h"
60  #include "colorspace.h"  #include "colorspace.h"
# Line 61  Line 62 
62  #include "../divx4.h"  #include "../divx4.h"
63  #include "../utils/mem_align.h"  #include "../utils/mem_align.h"
64    
65    #include "font.h"               // XXX: remove later
66    
67  #define SAFETY  64  #define SAFETY  64
68  #define EDGE_SIZE2  (EDGE_SIZE/2)  #define EDGE_SIZE2  (EDGE_SIZE/2)
69    
# Line 472  Line 475 
475  }  }
476    
477    
478    
479    /*
480      perform safe packed colorspace conversion, by splitting
481      the image up into an optimized area (pixel width divisible by 16),
482      and two unoptimized/plain-c areas (pixel width divisible by 2)
483    */
484    
485    static void
486    safe_packed_conv(uint8_t * x_ptr, int x_stride,
487                                     uint8_t * y_ptr, uint8_t * u_ptr, uint8_t * v_ptr,
488                                     int y_stride, int uv_stride,
489                                     int width, int height, int vflip,
490                                     packedFunc * func_opt, packedFunc func_c, int size)
491    {
492            int width_opt, width_c;
493    
494            if (func_opt != func_c && x_stride < size*((width+15)/16)*16)
495            {
496                    width_opt = width & (~15);
497                    width_c = width - width_opt;
498            }
499            else
500            {
501                    width_opt = width;
502                    width_c = 0;
503            }
504    
505            func_opt(x_ptr, x_stride,
506                            y_ptr, u_ptr, v_ptr, y_stride, uv_stride,
507                            width_opt, height, vflip);
508    
509            if (width_c)
510            {
511                    func_c(x_ptr + size*width_opt, x_stride,
512                            y_ptr + width_opt, u_ptr + width_opt/2, v_ptr + width_opt/2,
513                            y_stride, uv_stride, width_c, height, vflip);
514            }
515    }
516    
517    
518    
519  int  int
520  image_input(IMAGE * image,  image_input(IMAGE * image,
521                          uint32_t width,                          uint32_t width,
522                          int height,                          int height,
523                          uint32_t edged_width,                          uint32_t edged_width,
524                          uint8_t * src,                          uint8_t * src,
525                          int csp)                          int src_stride,
526                            int csp,
527                            int interlacing)
528  {  {
529            const int edged_width2 = edged_width/2;
530            const int width2 = width/2;
531            const int height2 = height/2;
532            //const int height_signed = (csp & XVID_CSP_VFLIP) ? -height : height;
533    
534    
535            //      int src_stride = width;
536    
537  /*      if (csp & XVID_CSP_VFLIP)          // --- xvid 2.1 compatiblity patch ---
538            // --- remove when xvid_dec_frame->stride equals real stride
539            /*
540            if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 ||
541                    (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 ||
542                    (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 ||
543                    (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YVYU ||
544                    (csp & ~XVID_CSP_VFLIP) == XVID_CSP_UYVY)
545            {
546                    src_stride *= 2;
547            }
548            else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB24)
549            {
550                    src_stride *= 3;
551            }
552            else if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB32 ||
553                    (csp & ~XVID_CSP_VFLIP) == XVID_CSP_ABGR ||
554                    (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGBA)
555          {          {
556                  height = -height;                  src_stride *= 4;
557          }          }
558  */  */
559            // ^--- xvid 2.1 compatiblity fix ---^
560    
561          switch (csp & ~XVID_CSP_VFLIP) {          switch (csp & ~XVID_CSP_VFLIP) {
562          case XVID_CSP_RGB555:          case XVID_CSP_RGB555:
563                  rgb555_to_yv12(image->y, image->u, image->v, src, width, height,                  safe_packed_conv(
564                                             edged_width);                          src, src_stride, image->y, image->u, image->v,
565                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
566                            interlacing?rgb555i_to_yv12  :rgb555_to_yv12,
567                            interlacing?rgb555i_to_yv12_c:rgb555_to_yv12_c, 2);
568                    break;
569    
570          case XVID_CSP_RGB565:          case XVID_CSP_RGB565:
571                  rgb565_to_yv12(image->y, image->u, image->v, src, width, height,                  safe_packed_conv(
572                                             edged_width);                          src, src_stride, image->y, image->u, image->v,
573                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
574                            interlacing?rgb565i_to_yv12  :rgb565_to_yv12,
575                            interlacing?rgb565i_to_yv12_c:rgb565_to_yv12_c, 2);
576                    break;
577    
578    
579          case XVID_CSP_RGB24:          case XVID_CSP_RGB24:
580                  rgb24_to_yv12(image->y, image->u, image->v, src, width, height,                  safe_packed_conv(
581                                            edged_width);                          src, src_stride, image->y, image->u, image->v,
582                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
583                            interlacing?bgri_to_yv12  :bgr_to_yv12,
584                            interlacing?bgri_to_yv12_c:bgr_to_yv12_c, 3);
585                    break;
586    
587          case XVID_CSP_RGB32:          case XVID_CSP_RGB32:
588                  rgb32_to_yv12(image->y, image->u, image->v, src, width, height,                  safe_packed_conv(
589                                            edged_width);                          src, src_stride, image->y, image->u, image->v,
590                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
591                            interlacing?bgrai_to_yv12  :bgra_to_yv12,
592                            interlacing?bgrai_to_yv12_c:bgra_to_yv12_c, 4);
593                    break;
594    
595          case XVID_CSP_I420:          case XVID_CSP_ABGR :
596                  yuv_to_yv12(image->y, image->u, image->v, src, width, height,                  safe_packed_conv(
597                                          edged_width);                          src, src_stride, image->y, image->u, image->v,
598                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
599                            interlacing?abgri_to_yv12  :abgr_to_yv12,
600                            interlacing?abgri_to_yv12_c:abgr_to_yv12_c, 4);
601                    break;
602    
603          case XVID_CSP_YV12:             /* u/v swapped */          case XVID_CSP_RGBA :
604                  yuv_to_yv12(image->y, image->v, image->u, src, width, height,                  safe_packed_conv(
605                                          edged_width);                          src, src_stride, image->y, image->u, image->v,
606                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
607                            interlacing?rgbai_to_yv12  :rgba_to_yv12,
608                            interlacing?rgbai_to_yv12_c:rgba_to_yv12_c, 4);
609                    break;
610    
611          case XVID_CSP_YUY2:          case XVID_CSP_YUY2:
612                  yuyv_to_yv12(image->y, image->u, image->v, src, width, height,                  safe_packed_conv(
613                                           edged_width);                          src, src_stride, image->y, image->u, image->v,
614                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
615                            interlacing?yuyvi_to_yv12  :yuyv_to_yv12,
616                            interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
617                    break;
618    
619          case XVID_CSP_YVYU:             /* u/v swapped */          case XVID_CSP_YVYU:             /* u/v swapped */
620                  yuyv_to_yv12(image->y, image->v, image->u, src, width, height,                  safe_packed_conv(
621                                           edged_width);                          src, src_stride, image->y, image->v, image->y,
622                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
623                            interlacing?yuyvi_to_yv12  :yuyv_to_yv12,
624                            interlacing?yuyvi_to_yv12_c:yuyv_to_yv12_c, 2);
625                    break;
626    
627          case XVID_CSP_UYVY:          case XVID_CSP_UYVY:
628                  uyvy_to_yv12(image->y, image->u, image->v, src, width, height,                  safe_packed_conv(
629                                           edged_width);                          src, src_stride, image->y, image->u, image->v,
630                  return 0;                          edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
631                            interlacing?uyvyi_to_yv12  :uyvy_to_yv12,
632                            interlacing?uyvyi_to_yv12_c:uyvy_to_yv12_c, 2);
633                    break;
634    
635            case XVID_CSP_I420:
636                    yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,
637                            src, src + width*height, src + width*height + width2*height2,
638                            width, width2, width, height, (csp & XVID_CSP_VFLIP));
639                    break
640                            ;
641            case XVID_CSP_YV12:             /* u/v swapped */
642                    yv12_to_yv12(image->y, image->v, image->u, edged_width, edged_width2,
643                            src, src + width*height, src + width*height + width2*height2,
644                            width, width2, width, height, (csp & XVID_CSP_VFLIP));
645                    break;
646    
647          case XVID_CSP_USER:          case XVID_CSP_USER:
648                  user_to_yuv_c(image->y, image->u, image->v, edged_width,                  {
649                                            (DEC_PICTURE *) src, width, height);                          DEC_PICTURE * pic = (DEC_PICTURE*)src;
650                  return 0;                          yv12_to_yv12(image->y, image->u, image->v, edged_width, edged_width2,
651                                    pic->y, pic->u, pic->v, pic->stride_y, pic->stride_y,
652                                    width, height, (csp & XVID_CSP_VFLIP));
653                    }
654                    break;
655    
656          case XVID_CSP_NULL:          case XVID_CSP_NULL:
657                  break;                  break;
658    
659            default :
660                    return -1;
661          }          }
662    
663          return -1;  
664            /* pad out image when the width and/or height is not a multiple of 16 */
665    
666            if (width & 15)
667            {
668                    int i;
669                    int pad_width = 16 - (width&15);
670                    for (i = 0; i < height; i++)
671                    {
672                            memset(image->y + i*edged_width + width,
673                                     *(image->y + i*edged_width + width - 1), pad_width);
674                    }
675                    for (i = 0; i < height/2; i++)
676                    {
677                            memset(image->u + i*edged_width2 + width2,
678                                     *(image->u + i*edged_width2 + width2 - 1),pad_width/2);
679                            memset(image->v + i*edged_width2 + width2,
680                                     *(image->v + i*edged_width2 + width2 - 1),pad_width/2);
681                    }
682            }
683    
684            if (height & 15)
685            {
686                    int pad_height = 16 - (height&15);
687                    int length = ((width+15)/16)*16;
688                    int i;
689                    for (i = 0; i < pad_height; i++)
690                    {
691                            memcpy(image->y + (height+i)*edged_width,
692                                       image->y + (height-1)*edged_width,length);
693                    }
694    
695                    for (i = 0; i < pad_height/2; i++)
696                    {
697                            memcpy(image->u + (height2+i)*edged_width2,
698                                       image->u + (height2-1)*edged_width2,length/2);
699                            memcpy(image->v + (height2+i)*edged_width2,
700                                       image->v + (height2-1)*edged_width2,length/2);
701                    }
702            }
703    
704    /*
705            if (interlacing)
706                    image_printf(image, edged_width, height, 5,5, "[i]");
707            image_dump_yuvpgm(image, edged_width, ((width+15)/16)*16, ((height+15)/16)*16, "\\encode.pgm");
708    */
709            return 0;
710  }  }
711    
712    
# Line 556  Line 718 
718                           uint32_t edged_width,                           uint32_t edged_width,
719                           uint8_t * dst,                           uint8_t * dst,
720                           uint32_t dst_stride,                           uint32_t dst_stride,
721                           int csp)                           int csp,
722                             int interlacing)
723  {  {
724          if (csp & XVID_CSP_VFLIP) {          const int edged_width2 = edged_width/2;
725                  height = -height;          int width2 = width/2;
726          }          int height2 = height/2;
727    
728    /*
729            if (interlacing)
730                    image_printf(image, edged_width, height, 5,100, "[i]=%i,%i",width,height);
731            image_dump_yuvpgm(image, edged_width, width, height, "\\decode.pgm");
732    */
733    
734    
735          // --- xvid 2.1 compatiblity patch ---          // --- xvid 2.1 compatiblity patch ---
736          // --- remove when xvid_dec_frame->stride equals real stride          // --- remove when xvid_dec_frame->stride equals real stride
737            /*
738          if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 ||          if ((csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB555 ||
739                  (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 ||                  (csp & ~XVID_CSP_VFLIP) == XVID_CSP_RGB565 ||
740                  (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 ||                  (csp & ~XVID_CSP_VFLIP) == XVID_CSP_YUY2 ||
# Line 582  Line 753 
753          {          {
754                  dst_stride *= 4;                  dst_stride *= 4;
755          }          }
756            */
757          // ^--- xvid 2.1 compatiblity fix ---^          // ^--- xvid 2.1 compatiblity fix ---^
758    
759    
760          switch (csp & ~XVID_CSP_VFLIP) {          switch (csp & ~XVID_CSP_VFLIP) {
761          case XVID_CSP_RGB555:          case XVID_CSP_RGB555:
762                  yv12_to_rgb555(dst, dst_stride, image->y, image->u, image->v,                  safe_packed_conv(
763                                             edged_width, edged_width / 2, width, height);                          dst, dst_stride, image->y, image->u, image->v,
764                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
765                            interlacing?yv12_to_rgb555i  :yv12_to_rgb555,
766                            interlacing?yv12_to_rgb555i_c:yv12_to_rgb555_c, 2);
767                  return 0;                  return 0;
768    
769          case XVID_CSP_RGB565:          case XVID_CSP_RGB565:
770                  yv12_to_rgb565(dst, dst_stride, image->y, image->u, image->v,                  safe_packed_conv(
771                                             edged_width, edged_width / 2, width, height);                          dst, dst_stride, image->y, image->u, image->v,
772                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
773                            interlacing?yv12_to_rgb565i  :yv12_to_rgb565,
774                            interlacing?yv12_to_rgb565i_c:yv12_to_rgb565_c, 2);
775                  return 0;                  return 0;
776    
777          case XVID_CSP_RGB24:          case XVID_CSP_RGB24:
778                  yv12_to_rgb24(dst, dst_stride, image->y, image->u, image->v,                  safe_packed_conv(
779                                            edged_width, edged_width / 2, width, height);                          dst, dst_stride, image->y, image->u, image->v,
780                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
781                            interlacing?yv12_to_bgri  :yv12_to_bgr,
782                            interlacing?yv12_to_bgri_c:yv12_to_bgr_c, 3);
783                  return 0;                  return 0;
784    
785          case XVID_CSP_RGB32:          case XVID_CSP_RGB32:
786                  yv12_to_rgb32(dst, dst_stride, image->y, image->u, image->v,                  safe_packed_conv(
787                                            edged_width, edged_width / 2, width, height);                          dst, dst_stride, image->y, image->u, image->v,
788                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
789                            interlacing?yv12_to_bgrai  :yv12_to_bgra,
790                            interlacing?yv12_to_bgrai_c:yv12_to_bgra_c, 4);
791                  return 0;                  return 0;
792    
793          case XVID_CSP_ABGR:          case XVID_CSP_ABGR:
794                  yv12_to_abgr(dst, dst_stride, image->y, image->u, image->v,                  safe_packed_conv(
795                                            edged_width, edged_width / 2, width, height);                          dst, dst_stride, image->y, image->u, image->v,
796                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
797                            interlacing?yv12_to_abgri  :yv12_to_abgr,
798                            interlacing?yv12_to_abgri_c:yv12_to_abgr_c, 4);
799                  return 0;                  return 0;
800    
801          case XVID_CSP_RGBA:          case XVID_CSP_RGBA:
802                  yv12_to_rgba(dst, dst_stride, image->y, image->u, image->v,                  safe_packed_conv(
803                                            edged_width, edged_width / 2, width, height);                          dst, dst_stride, image->y, image->u, image->v,
804                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
805                            interlacing?yv12_to_rgbai  :yv12_to_rgba,
806                            interlacing?yv12_to_rgbai_c:yv12_to_rgba_c, 4);
807                  return 0;                  return 0;
808    
809          case XVID_CSP_I420:          case XVID_CSP_YUY2:
810                  yv12_to_yuv(dst, dst_stride, image->y, image->u, image->v, edged_width,                  safe_packed_conv(
811                                          edged_width / 2, width, height);                          dst, dst_stride, image->y, image->u, image->v,
812                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
813                            interlacing?yv12_to_yuyvi  :yv12_to_yuyv,
814                            interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2);
815                  return 0;                  return 0;
816    
817          case XVID_CSP_YV12:             // u,v swapped          case XVID_CSP_YVYU:             // u,v swapped
818                  yv12_to_yuv(dst, dst_stride, image->y, image->v, image->u, edged_width,                  safe_packed_conv(
819                                          edged_width / 2, width, height);                          dst, dst_stride, image->y, image->v, image->u,
820                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
821                            interlacing?yv12_to_yuyvi  :yv12_to_yuyv,
822                            interlacing?yv12_to_yuyvi_c:yv12_to_yuyv_c, 2);
823                  return 0;                  return 0;
824    
825          case XVID_CSP_YUY2:          case XVID_CSP_UYVY:
826                  yv12_to_yuyv(dst, dst_stride, image->y, image->u, image->v,                  safe_packed_conv(
827                                           edged_width, edged_width / 2, width, height);                          dst, dst_stride, image->y, image->u, image->v,
828                            edged_width, edged_width2, width, height, (csp & XVID_CSP_VFLIP),
829                            interlacing?yv12_to_uyvyi  :yv12_to_uyvy,
830                            interlacing?yv12_to_uyvyi_c:yv12_to_uyvy_c, 2);
831                  return 0;                  return 0;
832    
833          case XVID_CSP_YVYU:             // u,v swapped          case XVID_CSP_I420:
834                  yv12_to_yuyv(dst, dst_stride, image->y, image->v, image->u,                  yv12_to_yv12(dst, dst + width*height, dst + width*height + width2*height2,
835                                           edged_width, edged_width / 2, width, height);                          width, width2,
836                            image->y, image->u, image->v, edged_width, edged_width2,
837                            width, height, (csp & XVID_CSP_VFLIP));
838                  return 0;                  return 0;
839    
840          case XVID_CSP_UYVY:          case XVID_CSP_YV12:             // u,v swapped
841                  yv12_to_uyvy(dst, dst_stride, image->y, image->u, image->v,                  yv12_to_yv12(dst, dst + width*height, dst + width*height + width2*height2,
842                                           edged_width, edged_width / 2, width, height);                          width, width2,
843                            image->y, image->v, image->u, edged_width, edged_width2,
844                            width, height, (csp & XVID_CSP_VFLIP));
845                  return 0;                  return 0;
846    
847          case XVID_CSP_USER:          case XVID_CSP_USER:
848                  ((DEC_PICTURE *) dst)->y = image->y;                  {
849                  ((DEC_PICTURE *) dst)->u = image->u;                          DEC_PICTURE * pic = (DEC_PICTURE*)dst;
850                  ((DEC_PICTURE *) dst)->v = image->v;                          pic->y = image->y;
851                  ((DEC_PICTURE *) dst)->stride_y = edged_width;                          pic->u = image->u;
852                  ((DEC_PICTURE *) dst)->stride_uv = edged_width / 2;                          pic->v = image->v;
853                            pic->stride_y = edged_width;
854                            pic->stride_uv = edged_width / 2;
855                    }
856                  return 0;                  return 0;
857    
858          case XVID_CSP_NULL:          case XVID_CSP_NULL:

Legend:
Removed from v.586  
changed lines
  Added in v.631

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4