home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / Linux / Apps / xanim.tgz / xanim / xanim27064 / xa1.0_kpcd.c < prev    next >
C/C++ Source or Header  |  1997-01-26  |  6KB  |  205 lines

  1.  
  2. /*
  3.  * xa_kpcd.c
  4.  *
  5.  * Copyright (C) 1996,1997 by Mark Podlipec. 
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied and redistributed without
  9.  * fee for non-commerical purposes provided that this copyright notice is
  10.  * preserved intact on all copies and modified copies.
  11.  * 
  12.  * There is no warranty or other guarantee of fitness of this software.
  13.  * It is provided solely "as is". The author(s) disclaim(s) all
  14.  * responsibility and liability with respect to this software's usage
  15.  * or its effect upon hardware or computer systems.
  16.  *
  17.  */
  18.  
  19. /* xa_kpcd.c */
  20. /*****************************************************************************
  21.  * Kodak Photo CD (KPCD) Format     Very limited - only 1 size supported.
  22.  *
  23.  *****************************************************************************/
  24.  
  25. /* REVISIONS *************************************************************
  26.  * 0.0  16May96  Initial file by Mark Podlipec (podlipec@shell.portal.com)
  27.  */
  28.  
  29. #include "xa_types.h"    /* XAnim data types and structures */
  30.  
  31. /*********** Global Functions */
  32. xaLONG KPCD_Codec_Query();
  33.  
  34. /*********** Local but used Externally Functions */
  35. xaULONG KPCD_Decode_KPCD();
  36.  
  37. /*********** Local Functions */
  38.  
  39. /*********** External XAnim functions that are called/needed */
  40. extern void XA_Gen_YUV_Tabs();
  41. extern void JPG_Setup_Samp_Limit_Table();
  42. extern void JPG_Alloc_MCU_Bufs();
  43. extern void *XA_YUV221111_Func();
  44.  
  45. /******* external XAnim variables used in various places **************/
  46. extern xaLONG xa_debug;
  47.  
  48. extern YUVBufs jpg_YUVBufs;
  49. extern YUVTabs def_yuv_tabs;
  50.  
  51.  
  52. /******* Defines for XAnim Video Codec Interface **********************/
  53.  
  54. #define XAPI_REV 0x0002
  55.  
  56. typedef struct
  57. {
  58.   void *anim_hdr;        /* used to add stuff to Free Chain */
  59.   xaULONG compression;        /* input/output compression */
  60.   xaULONG x,y;            /* input/output x,y */
  61.   xaULONG depth;        /* input depth */
  62.   void *extra;            /* extra for delta */
  63.   xaULONG xapi_rev;        /* XAnim API rev */
  64.   xaULONG (*decoder)();        /* decoder routine */
  65.   char *description;        /* text string */
  66.   xaULONG avi_ctab_flag;    /* AVI ctable to be read */
  67.   xaULONG (*avi_read_ext)();    /* routine to read extended data */
  68.  
  69. } XA_CODEC_HDR;
  70.  
  71. #define CODEC_SUPPORTED    1
  72. #define CODEC_UNKNOWN      0
  73. #define CODEC_UNSUPPORTED -1
  74.  
  75. typedef struct
  76. {
  77.   xaULONG cmd;                  /* decode or query */
  78.   xaULONG skip_flag;            /* skip_flag */
  79.   xaULONG imagex,imagey;        /* Image Buffer Size */
  80.   xaULONG imaged;               /* Image depth */
  81.   XA_CHDR *chdr;                /* Color Map Header */
  82.   xaULONG map_flag;             /* remap image? */
  83.   xaULONG *map;                 /* map to use */
  84.   xaULONG xs,ys;                /* pos of changed area */
  85.   xaULONG xe,ye;                /* size of change area */
  86.   xaULONG special;              /* Special Info */
  87.   xaULONG bytes_pixel;        /* bytes per pixel */
  88.   xaULONG image_type;        /* type of image */
  89.   xaULONG tmp1;            /* future expansion */
  90.   xaULONG tmp2;            /* future expansion */
  91.   xaULONG tmp3;            /* future expansion */
  92.   xaULONG tmp4;            /* future expansion */
  93.   void *extra;                  /* Decompression specific info */
  94. } XA_DEC2_INFO;
  95.  
  96.  
  97. #define ID_kpcd  0x6b706364
  98. #define ID_KPCD  0x4b504344
  99.  
  100.  
  101. /********* Start of Functions *****************************************/
  102.  
  103. /***************************
  104.  *
  105.  ***********/
  106. xaULONG KPCD_What_Rev_API() { return(XAPI_REV); }
  107.  
  108. /***************************
  109.  *
  110.  ***********/
  111. xaLONG KPCD_Codec_Query(codec)
  112. XA_CODEC_HDR *codec;
  113. { xaLONG ret = CODEC_UNKNOWN;
  114.  
  115.   codec->extra = 0;
  116.   codec->decoder = 0;
  117.   codec->description = 0;
  118.   codec->avi_read_ext = 0;
  119.   codec->xapi_rev = XAPI_REV;
  120.  
  121.   switch(codec->compression)
  122.   {
  123.     case ID_kpcd:
  124.     case ID_KPCD:
  125.     codec->compression = ID_KPCD;
  126.     codec->x = 4 * ((codec->x + 3)/4);
  127.     codec->decoder = KPCD_Decode_KPCD;
  128.     codec->description = "Kodak Photo CD";
  129.     codec->avi_ctab_flag = xaFALSE;
  130.     /* KPCD_Init_Stuff();  */
  131.     JPG_Alloc_MCU_Bufs(codec->anim_hdr,codec->x,codec->y,xaTRUE);
  132.     XA_Gen_YUV_Tabs(codec->anim_hdr);
  133.     JPG_Setup_Samp_Limit_Table(codec->anim_hdr);
  134.     ret = CODEC_SUPPORTED;
  135.     break;
  136.  
  137.     default:
  138.     ret = CODEC_UNKNOWN;
  139.     break;
  140.   }
  141.  return(ret);
  142. }
  143.  
  144.  
  145. /************************************
  146.  * This XAnim Delta Function decodes 
  147.  *
  148.  **********/
  149. xaULONG
  150. KPCD_Decode_KPCD(image,delta,dsize,dec_info)
  151. xaUBYTE *image;         /* Image Buffer. */
  152. xaUBYTE *delta;         /* delta data. */
  153. xaULONG dsize;          /* delta size */
  154. XA_DEC2_INFO *dec_info;  /* Decoder Info Header */
  155. { xaULONG imagex = dec_info->imagex;    xaULONG imagey = dec_info->imagey;
  156.   xaULONG map_flag = dec_info->map_flag;        xaULONG *map = dec_info->map;
  157.   XA_CHDR *chdr = dec_info->chdr;
  158.   xaUBYTE *dptr = delta;
  159.   xaULONG ycnt, row_inc = imagex << 1;
  160.   void (*color_func)() = (void (*)())XA_YUV221111_Func(dec_info->image_type);
  161.   xaUBYTE *ydp, *udp, *vdp;
  162.  
  163.   dec_info->xs = dec_info->ys = 0;
  164.   dec_info->xe = imagex; dec_info->ye = imagey;
  165.   if (dec_info->skip_flag > 0) return(ACT_DLTA_DROP);
  166.   if (chdr) { if (chdr->new_chdr) chdr = chdr->new_chdr; }
  167.  
  168.   row_inc *= dec_info->bytes_pixel;
  169.  
  170.   /* setup input plane pointers */
  171.   ydp = vdp = udp = dptr;
  172.   vdp += imagex * imagey;
  173.   udp += (imagex * imagey) + ((imagex * imagey) >> 2);
  174.  
  175.   ycnt = 0;
  176.   while(imagey > 0)  /* && (dsize > 0) ) */
  177.   { xaUBYTE *yp,*up,*vp;
  178.     xaULONG x; 
  179.  
  180.     if (ycnt == 0)
  181.       { yp = jpg_YUVBufs.Ybuf; up = jpg_YUVBufs.Ubuf; vp = jpg_YUVBufs.Vbuf; }
  182.  
  183.     /* read y line each time */
  184.     x = imagex;        while(x--)    *yp++ = *dptr++;
  185.    
  186.     ycnt++;
  187.     imagey--;
  188.     if ((ycnt >= 2) || (imagey == 0))
  189.     { 
  190.     /* read chroma every other or last with an odd image size if possible*/
  191.       x = imagex>>1;    while(x--)    *up++ = *dptr++;
  192.       x = imagex>>1;    while(x--)    *vp++ = *dptr++;
  193.  
  194.       color_func(image,imagex,ycnt,imagex,ycnt,
  195.                 &jpg_YUVBufs, &def_yuv_tabs, map_flag, map, chdr);
  196.       ycnt = 0;
  197.       image += row_inc;
  198.     }
  199.   } /*end of y */
  200.   if (map_flag) return(ACT_DLTA_MAPD);
  201.   else return(ACT_DLTA_NORM);
  202. }
  203.  
  204.  
  205.