Ignore:
Timestamp:
Nov 10, 2005, 9:41:13 PM (17 years ago)
Author:
Sam Hocevar
Message:
  • absolute shitloads of 64 bit fixes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/imlib/image.cpp

    r2 r17  
    1212#include <stdlib.h>
    1313
    14 extern unsigned char current_background;
     14extern uint8_t current_background;
    1515char *imerr_messages[]={"No error",
    1616                        "Error occured while reading",
     
    2323                       
    2424                         
    25 short imerror=0;
    26 short swpfile_num=0;
    27 
    28 short current_error()
     25int16_t imerror=0;
     26int16_t swpfile_num=0;
     27
     28int16_t current_error()
    2929{ return imerror; }
    3030
     
    4848}
    4949
    50 void set_error(short x)
     50void set_error(int16_t x)
    5151{ imerror=x; }
    5252
    53 short last_error()
    54 {
    55   short ec;
     53int16_t last_error()
     54{
     55  int16_t ec;
    5656  ec=imerror;
    5757  imerror=0;
     
    6262
    6363
    64 image_descriptor::image_descriptor(short length, short height,
     64image_descriptor::image_descriptor(int16_t length, int16_t height,
    6565                                   int keep_dirties, int static_memory)
    6666
     
    7272}
    7373
    74 void image::change_size(short new_width, short new_height, unsigned char *page)
     74void image::change_size(int16_t new_width, int16_t new_height, uint8_t *page)
    7575{
    7676  delete_page();
     
    9797}
    9898
    99 unsigned char image::pixel(short x, short y)
     99uint8_t image::pixel(int16_t x, int16_t y)
    100100{
    101101  CONDITION(x>=0 && x<width() && y>=0 && y<height(),
     
    104104}
    105105
    106 void image::putpixel(short x, short y, char color)
     106void image::putpixel(int16_t x, int16_t y, char color)
    107107{
    108108  CONDITION(x>=0 && x<width() && y>=0 && y<height(),
     
    116116
    117117
    118 image::image(short width, short height, unsigned char *page_buffer, short create_descriptor)
     118image::image(int16_t width, int16_t height, uint8_t *page_buffer, int16_t create_descriptor)
    119119{
    120120  w=width;
     
    132132image::image(spec_entry *e, bFILE *fp)
    133133{
    134   short i;
     134  int16_t i;
    135135  fp->seek(e->offset,0);
    136   w=fp->read_short();
    137   h=fp->read_short();
     136  w=fp->read_uint16();
     137  h=fp->read_uint16();
    138138  special=NULL;
    139139  make_page(w,h,NULL);
     
    145145image::image(bFILE *fp)
    146146{
    147   short i;
    148   w=fp->read_short();
    149   h=fp->read_short();
     147  int16_t i;
     148  w=fp->read_uint16();
     149  h=fp->read_uint16();
    150150  special=NULL;
    151151  make_page(w,h,NULL);
     
    172172void image_init()
    173173{
    174   unsigned char bt[2];
    175   unsigned short wrd,*up;
     174  uint8_t bt[2];
     175  uint16_t wrd,*up;
    176176  bt[0]=1;
    177177  bt[1]=0;
    178   up=(unsigned short *)bt;
    179   wrd=int_to_intel(*up);
     178  up=(uint16_t *)bt;
     179  wrd=uint16_to_intel(*up);
    180180  if (wrd!=0x01)
    181181  { printf("Compiled under wrong ENDING-nes, edit system.h and try again\n");
     
    187187
    188188
    189 long image::total_pixels(unsigned char background)
    190 {
    191   short i,j;
    192   long co;
    193   unsigned char *c;
     189int32_t image::total_pixels(uint8_t background)
     190{
     191  int16_t i,j;
     192  int32_t co;
     193  uint8_t *c;
    194194  for (co=0,i=height()-1;i>=0;i--)
    195195  { c=scan_line(i);
     
    200200}
    201201
    202 void image::clear(short color)
    203 {
    204   short i;
     202void image::clear(int16_t color)
     203{
     204  int16_t i;
    205205  if (color==-1) color=current_background;
    206206  if (special)
     
    220220{
    221221  image *im;
    222   unsigned char *c,*dat;
     222  uint8_t *c,*dat;
    223223  int i;
    224   dat=(unsigned char *)jmalloc(width(),"image copy");
     224  dat=(uint8_t *)jmalloc(width(),"image copy");
    225225  im=new image(width(),height());
    226226  for (i=height()-1;i>=0;i--)
     
    236236
    237237
    238 void image::line(short x1, short y1,short x2, short y2, unsigned char color)
    239 {
    240   short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;
     238void image::line(int16_t x1, int16_t y1,int16_t x2, int16_t y2, uint8_t color)
     239{
     240  int16_t i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;
    241241  unsigned dcy,dcx;
    242242  // check to make sure that both endpoint are on the screen
    243243
    244   short cx1,cy1,cx2,cy2;
     244  int16_t cx1,cy1,cx2,cy2;
    245245
    246246  // check to see if the line is completly clipped off
     
    378378
    379379
    380 void image::put_image(image *screen, short x, short y, char transparent)
    381 {
    382   short i,j,xl,yl;
    383   unsigned char *pg1,*pg2,*source,*dest;
     380void image::put_image(image *screen, int16_t x, int16_t y, char transparent)
     381{
     382  int16_t i,j,xl,yl;
     383  uint8_t *pg1,*pg2,*source,*dest;
    384384  if (screen->special)  // the screen is clipped then we onl want to put
    385385                    // part of the image
     
    417417}
    418418
    419 void image::fill_image(image *screen, short x1, short y1, short x2, short y2, short allign)
    420 {
    421   short i,j,w,xx,start,xl,starty;
    422   unsigned char *pg1,*pg2;
     419void image::fill_image(image *screen, int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t allign)
     420{
     421  int16_t i,j,w,xx,start,xl,starty;
     422  uint8_t *pg1,*pg2;
    423423  CHECK(x1<=x2 && y1<=y2);  // we should have gotten this
    424424
     
    467467
    468468
    469 void image::put_part(image *screen, short x, short y,
    470                 short x1, short y1, short x2, short y2, char transparent)
    471 {
    472   short xl,yl,j,i;
    473   short cx1,cy1,cx2,cy2;
    474   unsigned char *pg1,*pg2,*source,*dest;
     469void image::put_part(image *screen, int16_t x, int16_t y,
     470                int16_t x1, int16_t y1, int16_t x2, int16_t y2, char transparent)
     471{
     472  int16_t xl,yl,j,i;
     473  int16_t cx1,cy1,cx2,cy2;
     474  uint8_t *pg1,*pg2,*source,*dest;
    475475  CHECK(x1<=x2 && y1<=y2);
    476476
     
    533533}
    534534
    535 void image::put_part_xrev(image *screen, short x, short y,
    536                 short x1, short y1, short x2, short y2, char transparent)
    537 {
    538   short xl,yl,j,i;
    539   short cx1,cy1,cx2,cy2;
    540   unsigned char *pg1,*pg2,*source,*dest;
     535void image::put_part_xrev(image *screen, int16_t x, int16_t y,
     536                int16_t x1, int16_t y1, int16_t x2, int16_t y2, char transparent)
     537{
     538  int16_t xl,yl,j,i;
     539  int16_t cx1,cy1,cx2,cy2;
     540  uint8_t *pg1,*pg2,*source,*dest;
    541541  CHECK(x1<=x2 && y1<=y2);
    542542
     
    596596
    597597
    598 void image::put_part_masked(image *screen, image *mask, short x, short y,
    599                 short maskx, short masky,
    600                 short x1, short y1, short x2, short y2)
    601 {
    602   short xl,yl,j,i,ml,mh;
    603   short cx1,cy1,cx2,cy2;
    604   unsigned char *pg1,*pg2,*pg3;
     598void image::put_part_masked(image *screen, image *mask, int16_t x, int16_t y,
     599                int16_t maskx, int16_t masky,
     600                int16_t x1, int16_t y1, int16_t x2, int16_t y2)
     601{
     602  int16_t xl,yl,j,i,ml,mh;
     603  int16_t cx1,cy1,cx2,cy2;
     604  uint8_t *pg1,*pg2,*pg3;
    605605  CHECK(x1<=x2 && y1<=y2);
    606606
     
    658658
    659659
    660 unsigned char image::brightest_color(palette *pal)
    661 { unsigned char *p,r,g,b,bri;
    662   short i,j;
    663   long brv;
     660uint8_t image::brightest_color(palette *pal)
     661{ uint8_t *p,r,g,b,bri;
     662  int16_t i,j;
     663  int32_t brv;
    664664  brv=0; bri=0;
    665665  for (j=0;j<h;j++)
     
    668668    for (i=0;i<w;i++)
    669669    { pal->get(p[i],r,g,b);
    670       if ((long)r*(long)g*(long)b>brv)
    671       { brv=(long)r*(long)g*(long)b;
     670      if ((int32_t)r*(int32_t)g*(int32_t)b>brv)
     671      { brv=(int32_t)r*(int32_t)g*(int32_t)b;
    672672        bri=p[i];
    673673      }
     
    677677}
    678678
    679 unsigned char image::darkest_color(palette *pal, short noblack)
    680 { unsigned char *p,r,g,b,bri;
    681   short i,j;
    682   long brv,x;
    683   brv=(long)258*(long)258*(long)258; bri=0;
     679uint8_t image::darkest_color(palette *pal, int16_t noblack)
     680{ uint8_t *p,r,g,b,bri;
     681  int16_t i,j;
     682  int32_t brv,x;
     683  brv=(int32_t)258*(int32_t)258*(int32_t)258; bri=0;
    684684  for (j=0;j<h;j++)
    685685  {
     
    687687    for (i=0;i<w;i++)
    688688    { pal->get(p[i],r,g,b);
    689       x=(long)r*(long)g*(long)b;
     689      x=(int32_t)r*(int32_t)g*(int32_t)b;
    690690      if (x<brv && (x || !noblack))
    691691      { brv=x;
     
    697697}
    698698
    699 void image::rectangle(short x1, short y1,short x2, short y2, unsigned char color)
     699void image::rectangle(int16_t x1, int16_t y1,int16_t x2, int16_t y2, uint8_t color)
    700700{
    701701  line(x1,y1,x2,y1,color);
     
    705705}
    706706
    707 void image::set_clip(short x1, short y1, short x2, short y2)
     707void image::set_clip(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
    708708{
    709709  // If the image does not already have an Image descriptor, allocate one.
     
    718718}
    719719
    720 void image::get_clip (short &x1, short &y1, short &x2, short &y2)
     720void image::get_clip (int16_t &x1, int16_t &y1, int16_t &x2, int16_t &y2)
    721721{
    722722  if (special)
     
    726726}
    727727
    728 void image::in_clip  (short x1, short y1, short x2, short y2)
     728void image::in_clip  (int16_t x1, int16_t y1, int16_t x2, int16_t y2)
    729729{
    730730  if (special)
     
    747747{
    748748  dirty_rect *p,*q;
    749   short x1,y1,x2,y2,nn;
     749  int16_t x1,y1,x2,y2,nn;
    750750  x1=6000; y1=6000;
    751751  x2=0; y2=0;
     
    769769void image_descriptor::delete_dirty(int x1, int y1, int x2, int y2)
    770770{
    771   short i,ax1,ay1,ax2,ay2;
     771  int16_t i,ax1,ay1,ax2,ay2;
    772772  dirty_rect *p,*next;
    773773  if (keep_dirt)
     
    869869void image_descriptor::add_dirty(int x1, int y1, int x2, int y2)
    870870{
    871   short i;
     871  int16_t i;
    872872  dirty_rect *p;
    873873  if (keep_dirt)
     
    941941}
    942942
    943 void image::bar      (short x1, short y1, short x2, short y2, unsigned char color)
    944 {
    945   short y;
     943void image::bar      (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)
     944{
     945  int16_t y;
    946946  if (x1>x2 || y1>y2) return ;
    947947  if (special)
     
    964964}
    965965
    966 void image::xor_bar  (short x1, short y1, short x2, short y2, unsigned char color)
    967 {
    968   short y,x;
     966void image::xor_bar  (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t color)
     967{
     968  int16_t y,x;
    969969  if (x1>x2 || y1>y2) return ;
    970970  if (special)
     
    983983    return ;
    984984
    985   unsigned char *sl=scan_line(y1)+x1;
     985  uint8_t *sl=scan_line(y1)+x1;
    986986  for (y=y1;y<=y2;y++)
    987987  {
    988     unsigned char *s=sl;
     988    uint8_t *s=sl;
    989989    for (x=x1;x<=x2;x++,s++)
    990990      *s=(*s)^color;
     
    996996
    997997
    998 void image::unpack_scanline(short line, char bitsperpixel)
    999 {
    1000   short x;
    1001   unsigned char *sl,*ex,mask,bt,sh;
    1002   ex=(unsigned char *)jmalloc(width(),"image::unpacked scanline");
     998void image::unpack_scanline(int16_t line, char bitsperpixel)
     999{
     1000  int16_t x;
     1001  uint8_t *sl,*ex,mask,bt,sh;
     1002  ex=(uint8_t *)jmalloc(width(),"image::unpacked scanline");
    10031003  sl=scan_line(line);
    10041004  memcpy(ex,sl,width());
     
    10181018void image::dither(palette *pal)
    10191019{
    1020   short x,y,i,j;
    1021   unsigned char dt_matrix[]={0,  136,24, 170,
     1020  int16_t x,y,i,j;
     1021  uint8_t dt_matrix[]={0,  136,24, 170,
    10221022                   68, 204,102,238,
    10231023                   51, 187, 17,153,
    10241024                   119,255, 85,221};
    10251025
    1026   unsigned char *sl;
     1026  uint8_t *sl;
    10271027  for (y=height()-1;y>=0;y--)
    10281028  {
     
    10491049}
    10501050
    1051 void image::resize(short new_width, short new_height)
     1051void image::resize(int16_t new_width, int16_t new_height)
    10521052{
    10531053  int old_width=width(),old_height=height();
    1054   unsigned char *im=(unsigned char *)jmalloc(width()*height(),"image::resized");
     1054  uint8_t *im=(uint8_t *)jmalloc(width()*height(),"image::resized");
    10551055  memcpy(im,scan_line(0),width()*height());
    10561056
     
    10601060  h=new_height;
    10611061
    1062   unsigned char *sl1,*sl2;
    1063   short y,y2,x2;
     1062  uint8_t *sl1,*sl2;
     1063  int16_t y,y2,x2;
    10641064  double yc,xc,yd,xd;
    10651065
     
    10801080}
    10811081
    1082 void image::scroll(short x1, short y1, short x2, short y2, short xd, short yd)
    1083 {
    1084   short cx1,cy1,cx2,cy2;
     1082void image::scroll(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t xd, int16_t yd)
     1083{
     1084  int16_t cx1,cy1,cx2,cy2;
    10851085  CHECK(x1>=0 && y1>=0 && x1<x2 && y1<y2 && x2<width() && y2<height());
    10861086  if (special)
     
    10891089    x1=max(x1,cx1); y1=max(cy1,y1); x2=min(x2,cx2); y2=min(y2,cy2);
    10901090  }
    1091   short xsrc,ysrc,xdst,ydst,xtot=x2-x1-abs(xd)+1,ytot,xt;
    1092   unsigned char *src,*dst;
     1091  int16_t xsrc,ysrc,xdst,ydst,xtot=x2-x1-abs(xd)+1,ytot,xt;
     1092  uint8_t *src,*dst;
    10931093  if (xd<0) { xsrc=x1-xd; xdst=x1; } else { xsrc=x2-xd; xdst=x2; }
    10941094  if (yd<0) { ysrc=y1-yd; ydst=y1; } else { ysrc=y2-yd; ydst=y2; }
     
    11071107
    11081108
    1109 image *image::create_smooth(short smoothness)
    1110 {
    1111   short i,j,k,l,t,d;
     1109image *image::create_smooth(int16_t smoothness)
     1110{
     1111  int16_t i,j,k,l,t,d;
    11121112  image *im;
    11131113  CHECK(smoothness>=0);
     
    11291129}
    11301130
    1131 void image::wiget_bar(short x1, short y1, short x2, short y2,
    1132         unsigned char light, unsigned char med, unsigned char dark)
     1131void image::wiget_bar(int16_t x1, int16_t y1, int16_t x2, int16_t y2,
     1132        uint8_t light, uint8_t med, uint8_t dark)
    11331133{
    11341134  line(x1,y1,x2,y1,light);
     
    11421142{
    11431143public :
    1144   short x,y;
     1144  int16_t x,y;
    11451145  fill_rec *last;
    1146   fill_rec(short X, short Y, fill_rec *Last)
     1146  fill_rec(int16_t X, int16_t Y, fill_rec *Last)
    11471147  { x=X; y=Y; last=Last; }
    11481148} ;
    11491149
    1150 void image::flood_fill(short x, short y, unsigned char color)
    1151 {
    1152   unsigned char *sl,*above,*below;
     1150void image::flood_fill(int16_t x, int16_t y, uint8_t color)
     1151{
     1152  uint8_t *sl,*above,*below;
    11531153  fill_rec *recs=NULL,*r;
    1154   unsigned char fcolor;
     1154  uint8_t fcolor;
    11551155  sl=scan_line(y);
    11561156  fcolor=sl[x];
     
    12311231#define LED_L 5
    12321232#define LED_H 5
    1233 void image::burn_led(short x, short y, long num, short color, short scale)
     1233void image::burn_led(int16_t x, int16_t y, int32_t num, int16_t color, int16_t scale)
    12341234{
    12351235  char st[100];
    1236   short ledx[]={1,2,1,2,3,3,3,3,1,2,0,0,0,0};
    1237   short ledy[]={3,3,0,0,1,2,4,6,7,7,4,6,1,2};
    1238 
    1239   short dig[]={2+4+8+16+32+64,4+8,2+4+1+32+16,2+4+1+8+16,64+1+4+8,
     1236  int16_t ledx[]={1,2,1,2,3,3,3,3,1,2,0,0,0,0};
     1237  int16_t ledy[]={3,3,0,0,1,2,4,6,7,7,4,6,1,2};
     1238
     1239  int16_t dig[]={2+4+8+16+32+64,4+8,2+4+1+32+16,2+4+1+8+16,64+1+4+8,
    12401240             2+64+1+8+16,64+32+1+8+16,2+4+8,1+2+4+8+16+32+64,64+2+4+1+8,1};
    1241   short xx,yy,zz;
    1242   sprintf(st,"%8ld",num);
     1241  int16_t xx,yy,zz;
     1242  sprintf(st,"%8ld",(long int)num);
    12431243  for (xx=0;xx<8;xx++)
    12441244  {
     
    12581258}
    12591259
    1260 unsigned char dither_matrix[]={0,  136,24, 170,
     1260uint8_t dither_matrix[]={0,  136,24, 170,
    12611261                     68, 204,102,238,
    12621262                     51, 187, 17,153,
    12631263                     119,255, 85,221};
    12641264
    1265 image *image::copy_part_dithered (short x1, short y1, short x2, short y2)
    1266 {
    1267   short x,y,cx1,cy1,cx2,cy2,ry,rx,bo,dity,ditx;
     1265image *image::copy_part_dithered (int16_t x1, int16_t y1, int16_t x2, int16_t y2)
     1266{
     1267  int16_t x,y,cx1,cy1,cx2,cy2,ry,rx,bo,dity,ditx;
    12681268  image *ret;
    1269   unsigned char *sl1,*sl2;
     1269  uint8_t *sl1,*sl2;
    12701270  get_clip(cx1,cy1,cx2,cy2);
    12711271  if (y1<cy1) y1=cy1;
     
    13041304void image::flip_x()
    13051305{
    1306   unsigned char *rev=(unsigned char *)jmalloc(width(),"image tmp::flipped_x"),*sl;
     1306  uint8_t *rev=(uint8_t *)jmalloc(width(),"image tmp::flipped_x"),*sl;
    13071307  CONDITION(rev,"memory allocation");
    13081308  int y,x,i;
     
    13181318void image::flip_y()
    13191319{
    1320   unsigned char *rev=(unsigned char *)jmalloc(width(),"image::flipped_y"),*sl;
     1320  uint8_t *rev=(uint8_t *)jmalloc(width(),"image::flipped_y"),*sl;
    13211321  CONDITION(rev,"memory allocation");
    13221322  int y;
     
    13291329}
    13301330
    1331 void image::make_color(unsigned char color)
    1332 {
    1333   unsigned char *sl;
     1331void image::make_color(uint8_t color)
     1332{
     1333  uint8_t *sl;
    13341334  int y,x;
    13351335  for (y=0;y<height();y++)
Note: See TracChangeset for help on using the changeset viewer.