Lossless Images added.
authorkramm <kramm>
Sun, 28 Oct 2001 23:17:12 +0000 (23:17 +0000)
committerkramm <kramm>
Sun, 28 Oct 2001 23:17:12 +0000 (23:17 +0000)
pdf2swf/SWFOutputDev.cc
pdf2swf/swfoutput.cc
pdf2swf/swfoutput.h

index c1d9548..94fa6b9 100644 (file)
@@ -422,6 +422,8 @@ void dumpFontInfo(char*loglevel, GfxFont*font)
 
 SWFOutputDev::SWFOutputDev() 
 {
+    jpeginfo = 0;
+    pbminfo = 0;
     clippos = 0;
     clipping[clippos] = 0;
     outputstarted = 0;
@@ -608,8 +610,6 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state)
   double x1,y1,x2,y2;
   logf("<debug> startPage %d\n", pageNum);
   logf("<notice> processing page %d", pageNum);
-  jpeginfo = 0;
-  pbminfo = 0;
 
   state->transform(state->getX1(),state->getY1(),&x1,&y1);
   state->transform(state->getX2(),state->getY2(),&x2,&y2);
@@ -952,6 +952,10 @@ void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
   int c;
   char fileName[128];
   double x1,y1,x2,y2,x3,y3,x4,y4;
+  ImageStream *imgStr;
+  Guchar pixBuf[4];
+  GfxRGB rgb;
+
   state->transform(0, 1, &x1, &y1);
   state->transform(0, 0, &x2, &y2);
   state->transform(1, 0, &x3, &y3);
@@ -964,7 +968,7 @@ void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
     logf("<verbose> Found jpeg. Temporary storage is %s", fileName);
     if(!jpeginfo)
     {
-       logf("<notice> Page contains jpeg pictures");
+       logf("<notice> file contains jpeg pictures");
        jpeginfo = 1;
     }
     if (!(fi = fopen(fileName, "wb"))) {
@@ -976,14 +980,78 @@ void SWFOutputDev::drawGeneralImage(GfxState *state, Object *ref, Stream *str,
     while ((c = str->getChar()) != EOF)
       fputc(c, fi);
     fclose(fi);
-    swfoutput_drawimagefile(&output, fileName, width, height, x1,y1,x2,y2,x3,y3,x4,y4);
+    swfoutput_drawimagejpeg(&output, fileName, width, height, x1,y1,x2,y2,x3,y3,x4,y4);
     unlink(fileName);
   } else {
-      if(!pbminfo)
-      {
-         logf("<notice> Page contains pbm pictures");
-         pbminfo = 1;
-      }
+
+    if(!pbminfo) {
+       logf("<notice> file contains pbm pictures %s",mask?"(masked)":"");
+       if(mask)
+       logf("<verbose> ignoring %d by %d masked picture\n", width, height);
+       pbminfo = 1;
+    }
+
+    if(mask) {
+       str->reset();
+       int yes=0;
+       while ((c = str->getChar()) != EOF)
+       {
+           if((c<32 || c>'z') && yes && (c!=13) && (c!=10)) {
+               printf("no ascii: %02x\n", c);
+               yes = 1;
+          }
+       }
+    } else {
+       int x,y;
+       int width2 = (width+3)&(~3);
+       imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(),
+                                colorMap->getBits());
+       imgStr->reset();
+
+       if(colorMap->getNumPixelComps()!=1)
+       {
+           RGBA*pic=new RGBA[width*height];
+           for (y = 0; y < height; ++y) {
+             for (x = 0; x < width; ++x) {
+               imgStr->getPixel(pixBuf);
+               colorMap->getRGB(pixBuf, &rgb);
+               pic[width*y+x].r = (U8)(rgb.r * 255 + 0.5);
+               pic[width*y+x].g = (U8)(rgb.g * 255 + 0.5);
+               pic[width*y+x].b = (U8)(rgb.b * 255 + 0.5);
+               pic[width*y+x].a = 255;//(U8)(rgb.a * 255 + 0.5);
+             }
+           }
+           swfoutput_drawimagelossless(&output, pic, width, height, 
+                   x1,y1,x2,y2,x3,y3,x4,y4);
+           delete pic;
+       }
+       else
+       {
+           U8*pic = new U8[width2*height];
+           RGBA pal[256];
+           int t;
+           for(t=0;t<256;t++)
+           {
+               pixBuf[0] = t;
+               colorMap->getRGB(pixBuf, &rgb);
+               pal[t].r = (U8)(rgb.r * 255 + 0.5);
+               pal[t].g = (U8)(rgb.g * 255 + 0.5);
+               pal[t].b = (U8)(rgb.b * 255 + 0.5);
+               pal[t].a = 255;//(U8)(rgb.b * 255 + 0.5);
+           }
+           for (y = 0; y < height; ++y) {
+             for (x = 0; x < width; ++x) {
+               imgStr->getPixel(pixBuf);
+               pic[width2*y+x] = pixBuf[0];
+             }
+           }
+           swfoutput_drawimagelossless256(&output, pic, pal, width, height, 
+                   x1,y1,x2,y2,x3,y3,x4,y4);
+           delete pic;
+       }
+       delete imgStr;
+    }
+
   }
 }
 
index 40700cd..5a634b5 100644 (file)
@@ -1020,22 +1020,17 @@ void swfoutput_endclip(swfoutput*obj)
     PlaceObject(cliptags[clippos],clipshapes[clippos],clipdepths[clippos],NULL,NULL,NULL,depth++);
 }
 
-void swfoutput_drawimagefile(struct swfoutput*, char*filename, int sizex,int sizey, 
+
+void drawimage(struct swfoutput*obj, int bitid, int sizex,int sizey, 
        double x1,double y1,
        double x2,double y2,
        double x3,double y3,
        double x4,double y4)
 {
-    if(shapeid>=0)
-     endshape();
-    if(textid>=0)
-     endtext();
-
     RGBA rgb;
     SRECT r;
     int lsid=0;
     int fsid;
-    int bitid;
     struct plotxy p1,p2,p3,p4;
     int myshapeid;
     double xmax=x1,ymax=y1,xmin=x1,ymin=y1;
@@ -1068,14 +1063,7 @@ void swfoutput_drawimagefile(struct swfoutput*, char*filename, int sizex,int siz
 
     m.tx = (int)(x1*20);
     m.ty = (int)(y1*20);
-
-    bitid = ++currentswfid;
   
-    /* bitmap */
-    tag = InsertTag(tag,ST_DEFINEBITSJPEG2);
-    SetU16(tag, bitid);
-    SetJPEGBits(tag, filename, jpegquality);
-
     /* shape */
     myshapeid = ++currentswfid;
     tag = InsertTag(tag,ST_DEFINESHAPE);
@@ -1112,3 +1100,60 @@ void swfoutput_drawimagefile(struct swfoutput*, char*filename, int sizex,int siz
     ObjectPlace(tag,myshapeid,/*depth*/depth++,NULL,NULL,NULL);
 }
 
+void swfoutput_drawimagejpeg(struct swfoutput*obj, char*filename, int sizex,int sizey, 
+       double x1,double y1,
+       double x2,double y2,
+       double x3,double y3,
+       double x4,double y4)
+{
+    if(shapeid>=0)
+     endshape();
+    if(textid>=0)
+     endtext();
+
+    int bitid = ++currentswfid;
+    tag = InsertTag(tag,ST_DEFINEBITSJPEG2);
+    SetU16(tag, bitid);
+    SetJPEGBits(tag, filename, jpegquality);
+
+    drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
+}
+
+void swfoutput_drawimagelossless(struct swfoutput*obj, RGBA*mem, int sizex,int sizey, 
+       double x1,double y1,
+       double x2,double y2,
+       double x3,double y3,
+       double x4,double y4)
+{
+    if(shapeid>=0)
+     endshape();
+    if(textid>=0)
+     endtext();
+
+    int bitid = ++currentswfid;
+    tag = InsertTag(tag,ST_DEFINEBITSLOSSLESS);
+    SetU16(tag, bitid);
+    SetLosslessBits(tag,sizex,sizey,mem, BMF_32BIT);
+    
+    drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
+}
+
+void swfoutput_drawimagelossless256(struct swfoutput*obj, U8*mem, RGBA*pal, int sizex,int sizey, 
+       double x1,double y1,
+       double x2,double y2,
+       double x3,double y3,
+       double x4,double y4)
+{
+    if(shapeid>=0)
+     endshape();
+    if(textid>=0)
+     endtext();
+
+    int bitid = ++currentswfid;
+    tag = InsertTag(tag,ST_DEFINEBITSLOSSLESS2);
+    SetU16(tag, bitid);
+    SetLosslessBitsIndexed(tag,sizex,sizey,mem, pal, 256);
+  
+    drawimage(obj, bitid, sizex, sizey, x1,y1,x2,y2,x3,y3,x4,y4);
+}
+
index 0540d81..2002615 100644 (file)
@@ -91,7 +91,17 @@ void swfoutput_drawchar(struct swfoutput*,double x,double y,char*a);
 void swfoutput_drawpath(struct swfoutput*, T1_OUTLINE*outline, struct swfmatrix*m);
 void swfoutput_startclip(struct swfoutput*, T1_OUTLINE*outline, struct swfmatrix*m);
 void swfoutput_endclip(struct swfoutput*);
-void swfoutput_drawimagefile(struct swfoutput*, char*filename, int sizex,int sizey, 
+void swfoutput_drawimagejpeg(struct swfoutput*, char*filename, int sizex,int sizey, 
+       double x1,double y1,
+       double x2,double y2,
+       double x3,double y3,
+       double x4,double y4);
+void swfoutput_drawimagelossless(struct swfoutput*, RGBA*pic, int sizex, int sizey,
+       double x1,double y1,
+       double x2,double y2,
+       double x3,double y3,
+       double x4,double y4);
+void swfoutput_drawimagelossless256(struct swfoutput*, U8*pic,RGBA*pal, int sizex, int sizey,
        double x1,double y1,
        double x2,double y2,
        double x3,double y3,