1 #include <png.h> // must be included before Python.h because of setjmp
4 #include <lib/gdi/picload.h>
5 #include <lib/gdi/picexif.h>
12 extern const uint32_t crc32_table[256];
16 static std::string getSize(const char* file)
19 if (stat64(file, &s) < 0)
22 snprintf(tmp, 20, "%ld kB",(long)s.st_size / 1024);
26 static unsigned char *conv24to32(unsigned char *orgin, int size, unsigned char alpha = 0xFF)
29 unsigned char *cr = new unsigned char[size * 4];
32 eDebug("[Picload] Error malloc");
36 for (s = 0, d = 0 ; s < (size * 3); s += 3, d += 4 )
39 cr[d+1] = orgin[s + 1];
40 cr[d+2] = orgin[s + 2];
47 static unsigned char *simple_resize(unsigned char *orgin, int ox, int oy, int dx, int dy)
49 unsigned char *cr, *p, *l;
51 cr = new unsigned char[dx * dy * 3];
54 eDebug("[Picload] Error malloc");
59 for (j = 0; j < dy; j++,l += dx * 3)
61 p = orgin + (j * oy / dy * ox * 3);
62 for (i = 0, k = 0; i < dx; i++, k += 3)
74 static unsigned char *color_resize(unsigned char * orgin, int ox, int oy, int dx, int dy)
76 unsigned char *cr, *p, *q;
77 int i, j, k, l, xa, xb, ya, yb;
79 cr = new unsigned char[dx * dy * 3];
82 eDebug("[Picload] Error malloc");
87 for (j = 0; j < dy; j++)
89 for (i = 0; i < dx; i++, p += 3)
93 xb = (i + 1) * ox / dx;
96 yb = (j + 1) * oy / dy;
99 for (l = ya, r = 0, g = 0, b = 0, sq = 0; l <= yb; l++)
101 q = orgin + ((l * ox + xa) * 3);
102 for (k = xa; k <= xb; k++, q += 3, sq++)
104 r += q[0]; g += q[1]; b += q[2];
107 p[0] = r / sq; p[1] = g / sq; p[2] = b / sq;
114 //---------------------------------------------------------------------------------------------
116 #define BMP_TORASTER_OFFSET 10
117 #define BMP_SIZE_OFFSET 18
118 #define BMP_BPP_OFFSET 28
119 #define BMP_RLE_OFFSET 30
120 #define BMP_COLOR_OFFSET 54
122 #define fill4B(a) ((4 - ((a) % 4 )) & 0x03)
130 static void fetch_pallete(int fd, struct color pallete[], int count)
132 unsigned char buff[4];
133 lseek(fd, BMP_COLOR_OFFSET, SEEK_SET);
134 for (int i = 0; i < count; i++)
137 pallete[i].red = buff[2];
138 pallete[i].green = buff[1];
139 pallete[i].blue = buff[0];
143 static unsigned char *bmp_load(const char *file, int *x, int *y)
145 unsigned char buff[4];
146 struct color pallete[256];
148 int fd = open(file, O_RDONLY);
149 if (fd == -1) return NULL;
150 if (lseek(fd, BMP_SIZE_OFFSET, SEEK_SET) == -1) return NULL;
152 *x = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
154 *y = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
155 if (lseek(fd, BMP_TORASTER_OFFSET, SEEK_SET) == -1) return NULL;
157 int raster = buff[0] + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
158 if (lseek(fd, BMP_BPP_OFFSET, SEEK_SET) == -1) return NULL;
160 int bpp = buff[0] + (buff[1] << 8);
162 unsigned char *pic_buffer = new unsigned char[(*x) * (*y) * 3];
163 unsigned char *wr_buffer = pic_buffer + (*x) * ((*y) - 1) * 3;
169 int skip = fill4B((*x) / 2 + (*x) % 2);
170 fetch_pallete(fd, pallete, 16);
171 lseek(fd, raster, SEEK_SET);
172 unsigned char * tbuffer = new unsigned char[*x / 2 + 1];
175 for (int i = 0; i < *y; i++)
177 read(fd, tbuffer, (*x) / 2 + *x % 2);
179 for (j = 0; j < (*x) / 2; j++)
181 unsigned char c1 = tbuffer[j] >> 4;
182 unsigned char c2 = tbuffer[j] & 0x0f;
183 *wr_buffer++ = pallete[c1].red;
184 *wr_buffer++ = pallete[c1].green;
185 *wr_buffer++ = pallete[c1].blue;
186 *wr_buffer++ = pallete[c2].red;
187 *wr_buffer++ = pallete[c2].green;
188 *wr_buffer++ = pallete[c2].blue;
192 unsigned char c1 = tbuffer[j] >> 4;
193 *wr_buffer++ = pallete[c1].red;
194 *wr_buffer++ = pallete[c1].green;
195 *wr_buffer++ = pallete[c1].blue;
198 read(fd, buff, skip);
199 wr_buffer -= (*x) * 6;
205 int skip = fill4B(*x);
206 fetch_pallete(fd, pallete, 256);
207 lseek(fd, raster, SEEK_SET);
208 unsigned char * tbuffer = new unsigned char[*x];
211 for (int i = 0; i < *y; i++)
213 read(fd, tbuffer, *x);
214 for (int j = 0; j < *x; j++)
216 wr_buffer[j * 3] = pallete[tbuffer[j]].red;
217 wr_buffer[j * 3 + 1] = pallete[tbuffer[j]].green;
218 wr_buffer[j * 3 + 2] = pallete[tbuffer[j]].blue;
221 read(fd, buff, skip);
222 wr_buffer -= (*x) * 3;
228 int skip = fill4B((*x) * 3);
229 lseek(fd, raster, SEEK_SET);
230 for (int i = 0; i < (*y); i++)
232 read(fd, wr_buffer, (*x) * 3);
233 for (int j = 0; j < (*x) * 3 ; j = j + 3)
235 unsigned char c = wr_buffer[j];
236 wr_buffer[j] = wr_buffer[j + 2];
237 wr_buffer[j + 2] = c;
240 read(fd, buff, skip);
241 wr_buffer -= (*x) * 3;
253 //---------------------------------------------------------------------
255 static unsigned char *png_load(const char *file, int *ox, int *oy)
257 //static const png_color_16 my_background = {0, 0, 0, 0, 0};
260 png_uint_32 width, height;
262 int bit_depth, color_type, interlace_type;
263 int number_passes, pass;
267 if (!(fh = fopen(file, "rb"))) return NULL;
269 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
272 info_ptr = png_create_info_struct(png_ptr);
273 if (info_ptr == NULL)
275 png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
280 if (setjmp(png_ptr->jmpbuf))
282 png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
287 png_init_io(png_ptr, fh);
289 png_read_info(png_ptr, info_ptr);
290 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL);
292 if ((color_type == PNG_COLOR_TYPE_PALETTE)||(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)||(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
293 png_set_expand(png_ptr);
295 png_set_strip_16(png_ptr);
296 if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
297 png_set_gray_to_rgb(png_ptr);
299 number_passes = png_set_interlace_handling(png_ptr);
300 png_read_update_info(png_ptr, info_ptr);
302 int bpp = png_get_rowbytes(png_ptr, info_ptr)/width;
303 if ((bpp !=4) && (bpp !=3))
305 eDebug("[PNG] Error processing");
309 if (width * height > 1000000) // 1000x1000 or equiv.
311 eDebug("[png_load] image size is %d x %d, which is \"too large\".", (int)width, (int)height);
312 png_read_end(png_ptr, info_ptr);
313 png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
318 unsigned char *pic_buffer = new unsigned char[width * height * bpp];
322 for(pass = 0; pass < number_passes; pass++)
324 fbptr = (png_byte *)pic_buffer;
325 for (i = 0; i < height; i++, fbptr += width * bpp)
326 png_read_row(png_ptr, fbptr, NULL);
328 png_read_end(png_ptr, info_ptr);
329 png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
334 //-------------------------------------------------------------------
336 struct r_jpeg_error_mgr
338 struct jpeg_error_mgr pub;
342 void jpeg_cb_error_exit(j_common_ptr cinfo)
344 struct r_jpeg_error_mgr *mptr;
345 mptr = (struct r_jpeg_error_mgr *) cinfo->err;
346 (*cinfo->err->output_message) (cinfo);
347 longjmp(mptr->envbuffer, 1);
350 static unsigned char *jpeg_load(const char *file, int *ox, int *oy)
352 struct jpeg_decompress_struct cinfo;
353 struct jpeg_decompress_struct *ciptr = &cinfo;
354 struct r_jpeg_error_mgr emgr;
356 unsigned char *pic_buffer=NULL;
358 if (!(fh = fopen(file, "rb")))
361 ciptr->err = jpeg_std_error(&emgr.pub);
362 emgr.pub.error_exit = jpeg_cb_error_exit;
363 if (setjmp(emgr.envbuffer) == 1)
365 jpeg_destroy_decompress(ciptr);
370 jpeg_create_decompress(ciptr);
371 jpeg_stdio_src(ciptr, fh);
372 jpeg_read_header(ciptr, TRUE);
373 ciptr->out_color_space = JCS_RGB;
374 ciptr->scale_denom = 1;
376 jpeg_start_decompress(ciptr);
378 *ox=ciptr->output_width;
379 *oy=ciptr->output_height;
381 if(ciptr->output_components == 3)
383 JSAMPLE *lb = (JSAMPLE *)(*ciptr->mem->alloc_small)((j_common_ptr) ciptr, JPOOL_PERMANENT, ciptr->output_width * ciptr->output_components);
384 pic_buffer = new unsigned char[ciptr->output_height * ciptr->output_width * ciptr->output_components];
385 unsigned char *bp = pic_buffer;
387 while (ciptr->output_scanline < ciptr->output_height)
389 jpeg_read_scanlines(ciptr, &lb, 1);
390 memcpy(bp, lb, ciptr->output_width * ciptr->output_components);
391 bp += ciptr->output_width * ciptr->output_components;
394 jpeg_finish_decompress(ciptr);
395 jpeg_destroy_decompress(ciptr);
401 static int jpeg_save(const char * filename, int ox, int oy, unsigned char *pic_buffer)
403 struct jpeg_compress_struct cinfo;
404 struct jpeg_error_mgr jerr;
406 JSAMPROW row_pointer[1];
409 cinfo.err = jpeg_std_error(&jerr);
410 jpeg_create_compress(&cinfo);
412 if ((outfile = fopen(filename, "wb")) == NULL)
414 eDebug("[Picload] jpeg can't open %s", filename);
417 eDebug("[Picload] save Thumbnail... %s",filename);
419 jpeg_stdio_dest(&cinfo, outfile);
421 cinfo.image_width = ox;
422 cinfo.image_height = oy;
423 cinfo.input_components = 3;
424 cinfo.in_color_space = JCS_RGB;
425 jpeg_set_defaults(&cinfo);
426 jpeg_set_quality(&cinfo, 70, TRUE );
427 jpeg_start_compress(&cinfo, TRUE);
429 while (cinfo.next_scanline < cinfo.image_height)
431 row_pointer[0] = & pic_buffer[cinfo.next_scanline * row_stride];
432 (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
434 jpeg_finish_compress(&cinfo);
436 jpeg_destroy_compress(&cinfo);
440 //-------------------------------------------------------------------
442 inline void m_rend_gif_decodecolormap(unsigned char *cmb, unsigned char *rgbb, ColorMapObject *cm, int s, int l)
444 GifColorType *cmentry;
446 for (i = 0; i < l; i++)
448 cmentry = &cm->Colors[cmb[i]];
449 *(rgbb++) = cmentry->Red;
450 *(rgbb++) = cmentry->Green;
451 *(rgbb++) = cmentry->Blue;
455 static unsigned char *gif_load(const char *file, int *ox, int *oy)
457 unsigned char *pic_buffer = NULL;
458 int px, py, i, j, ibxs;
459 unsigned char *fbptr;
460 unsigned char *lb=NULL;
461 unsigned char *slb=NULL;
464 GifByteType *extension;
465 ColorMapObject *cmap;
469 gft = DGifOpenFileName(file);
474 if (DGifGetRecordType(gft, &rt) == GIF_ERROR)
478 case IMAGE_DESC_RECORD_TYPE:
479 if (DGifGetImageDesc(gft) == GIF_ERROR)
481 *ox = px = gft->Image.Width;
482 *oy = py = gft->Image.Height;
483 pic_buffer = new unsigned char[px * py * 3];
484 lb = (unsigned char *)malloc(px * 3);
485 slb = (unsigned char *) malloc(px);
487 if (lb != NULL && slb != NULL)
489 cmap = (gft->Image.ColorMap ? gft->Image.ColorMap : gft->SColorMap);
490 cmaps = cmap->ColorCount;
494 if (!(gft->Image.Interlace))
496 for (i = 0; i < py; i++, fbptr += px * 3)
498 if (DGifGetLine(gft, slb, px) == GIF_ERROR)
500 m_rend_gif_decodecolormap(slb, lb, cmap, cmaps, px);
501 memcpy(fbptr, lb, px * 3);
506 for (j = 0; j < 4; j++)
509 for (i = 0; i < py; i++, fbptr += px * 3)
511 if (DGifGetLine(gft, slb, px) == GIF_ERROR)
513 m_rend_gif_decodecolormap(slb, lb, cmap, cmaps, px);
514 memcpy(fbptr, lb, px * 3);
530 case EXTENSION_RECORD_TYPE:
531 if (DGifGetExtension(gft, &extcode, &extension) == GIF_ERROR)
533 while (extension != NULL)
534 if (DGifGetExtensionNext(gft, &extension) == GIF_ERROR)
541 while (rt != TERMINATE_RECORD_TYPE);
546 eDebug("[Picload] <Error gif>");
553 //---------------------------------------------------------------------------------------------
556 :msg_thread(this,1), msg_main(eApp,1)
558 CONNECT(msg_thread.recv_msg, ePicLoad::gotMessage);
559 CONNECT(msg_main.recv_msg, ePicLoad::gotMessage);
561 threadrunning = false;
565 m_conf.aspect_ratio = 1.066400; //4:3
566 m_conf.usecache = false;
567 m_conf.resizetype = 1;
568 memset(m_conf.background,0x00,sizeof(m_conf.background));
569 m_conf.thumbnailsize = 180;
572 ePicLoad::~ePicLoad()
574 msg_thread.send(Message(Message::quit));
577 if(m_filepara != NULL)
582 void ePicLoad::thread()
589 void ePicLoad::decodePic()
591 eDebug("[Picload] decode picture... %s",m_filepara->file);
593 switch(m_filepara->id)
595 case F_PNG: m_filepara->pic_buffer = png_load(m_filepara->file, &m_filepara->ox, &m_filepara->oy); break;
596 case F_JPEG: m_filepara->pic_buffer = jpeg_load(m_filepara->file, &m_filepara->ox, &m_filepara->oy); break;
597 case F_BMP: m_filepara->pic_buffer = bmp_load(m_filepara->file, &m_filepara->ox, &m_filepara->oy); break;
598 case F_GIF: m_filepara->pic_buffer = gif_load(m_filepara->file, &m_filepara->ox, &m_filepara->oy); break;
601 if(m_filepara->pic_buffer != NULL)
607 void ePicLoad::decodeThumb()
609 eDebug("[Picload] get Thumbnail... %s",m_filepara->file);
611 bool exif_thumbnail = false;
612 bool cachefile_found = false;
613 std::string cachefile = "";
614 std::string cachedir = "/.Thumbnails";
616 if(m_filepara->id == F_JPEG)
618 Cexif *exif = new Cexif;
619 if(exif->DecodeExif(m_filepara->file, 1))
621 if(exif->m_exifinfo->IsExif)
623 if(exif->m_exifinfo->Thumnailstate==2)
625 m_filepara->file = strdup(THUMBNAILTMPFILE);
626 exif_thumbnail = true;
627 eDebug("[Picload] Exif Thumbnail found");
629 m_filepara->addExifInfo(exif->m_exifinfo->CameraMake);
630 m_filepara->addExifInfo(exif->m_exifinfo->CameraModel);
631 m_filepara->addExifInfo(exif->m_exifinfo->DateTime);
633 snprintf(buf, 20, "%d x %d", exif->m_exifinfo->Width, exif->m_exifinfo->Height);
634 m_filepara->addExifInfo(buf);
641 if((! exif_thumbnail) && m_conf.usecache)
643 if(FILE *f=fopen(m_filepara->file, "rb"))
646 int count = 1024*100;
647 unsigned long crc32 = 0;
648 char crcstr[9];*crcstr=0;
650 while ((c=getc(f))!=EOF)
652 crc32 = crc32_table[((crc32) ^ (c)) & 0xFF] ^ ((crc32) >> 8);
653 if(--count < 0) break;
658 sprintf(crcstr, "%08lX", crc32);
660 cachedir = m_filepara->file;
661 unsigned int pos = cachedir.find_last_of("/");
662 if (pos != std::string::npos)
663 cachedir = cachedir.substr(0, pos) + "/.Thumbnails";
665 cachefile = cachedir + std::string("/pc_") + crcstr;
666 if(!access(cachefile.c_str(), R_OK))
668 cachefile_found = true;
669 m_filepara->file = strdup(cachefile.c_str());
670 m_filepara->id = F_JPEG;
671 eDebug("[Picload] Cache File found");
676 switch(m_filepara->id)
678 case F_PNG: m_filepara->pic_buffer = png_load(m_filepara->file, &m_filepara->ox, &m_filepara->oy); break;
679 case F_JPEG: m_filepara->pic_buffer = jpeg_load(m_filepara->file, &m_filepara->ox, &m_filepara->oy); break;
680 case F_BMP: m_filepara->pic_buffer = bmp_load(m_filepara->file, &m_filepara->ox, &m_filepara->oy); break;
681 case F_GIF: m_filepara->pic_buffer = gif_load(m_filepara->file, &m_filepara->ox, &m_filepara->oy); break;
685 ::unlink(THUMBNAILTMPFILE);
687 if(m_filepara->pic_buffer != NULL)
690 if(m_conf.usecache && (! exif_thumbnail) && (! cachefile_found))
692 if(access(cachedir.c_str(), R_OK))
693 ::mkdir(cachedir.c_str(), 0755);
695 //resize for Thumbnail
697 if (m_filepara->ox <= m_filepara->oy)
699 imy = m_conf.thumbnailsize;
700 imx = (int)( (m_conf.thumbnailsize * ((double)m_filepara->ox)) / ((double)m_filepara->oy) );
704 imx = m_conf.thumbnailsize;
705 imy = (int)( (m_conf.thumbnailsize * ((double)m_filepara->oy)) / ((double)m_filepara->ox) );
708 m_filepara->pic_buffer = color_resize(m_filepara->pic_buffer, m_filepara->ox, m_filepara->oy, imx, imy);
709 m_filepara->ox = imx;
710 m_filepara->oy = imy;
712 if(jpeg_save(cachefile.c_str(), m_filepara->ox, m_filepara->oy, m_filepara->pic_buffer))
713 eDebug("[Picload] error saving cachefile");
720 void ePicLoad::resizePic()
724 if((m_conf.aspect_ratio * m_filepara->oy * m_filepara->max_x / m_filepara->ox) <= m_filepara->max_y)
726 imx = m_filepara->max_x;
727 imy = (int)(m_conf.aspect_ratio * m_filepara->oy * m_filepara->max_x / m_filepara->ox);
731 imx = (int)((1.0/m_conf.aspect_ratio) * m_filepara->ox * m_filepara->max_y / m_filepara->oy);
732 imy = m_filepara->max_y;
735 if(m_conf.resizetype)
736 m_filepara->pic_buffer = color_resize(m_filepara->pic_buffer, m_filepara->ox, m_filepara->oy, imx, imy);
738 m_filepara->pic_buffer = simple_resize(m_filepara->pic_buffer, m_filepara->ox, m_filepara->oy, imx, imy);
740 m_filepara->ox = imx;
741 m_filepara->oy = imy;
744 void ePicLoad::gotMessage(const Message &msg)
748 case Message::decode_Pic:
750 msg_main.send(Message(Message::decode_finished));
752 case Message::decode_Thumb:
754 msg_main.send(Message(Message::decode_finished));
756 case Message::quit: // called from decode thread
757 eDebug("[Picload] decode thread ... got quit msg");
760 case Message::decode_finished: // called from main thread
761 //eDebug("[Picload] decode finished... %s", m_filepara->file);
763 if(m_filepara->callback)
765 PictureData(m_filepara->picinfo.c_str());
769 if(m_filepara != NULL)
777 eDebug("unhandled thread message");
781 int ePicLoad::startThread(int what, const char *file, int x, int y)
783 if(threadrunning && m_filepara != NULL)
785 eDebug("[Picload] thread running");
786 m_filepara->callback = false;
790 if(m_filepara != NULL)
797 unsigned char id[10];
798 int fd = ::open(file, O_RDONLY);
799 if (fd == -1) return 1;
803 if(id[1] == 'P' && id[2] == 'N' && id[3] == 'G') file_id = F_PNG;
804 else if(id[6] == 'J' && id[7] == 'F' && id[8] == 'I' && id[9] == 'F') file_id = F_JPEG;
805 else if(id[0] == 0xff && id[1] == 0xd8 && id[2] == 0xff) file_id = F_JPEG;
806 else if(id[0] == 'B' && id[1] == 'M' ) file_id = F_BMP;
807 else if(id[0] == 'G' && id[1] == 'I' && id[2] == 'F') file_id = F_GIF;
811 eDebug("[Picload] <format not supportet>");
815 m_filepara = new Cfilepara(file, file_id, getSize(file));
816 x > 0 ? m_filepara->max_x = x : m_filepara->max_x = m_conf.max_x;
817 y > 0 ? m_filepara->max_y = y : m_filepara->max_y = m_conf.max_y;
819 if(m_filepara->max_x <= 0 || m_filepara->max_y <= 0)
823 eDebug("[Picload] <error in Para>");
829 msg_thread.send(Message(Message::decode_Pic));
831 msg_thread.send(Message(Message::decode_Thumb));
836 RESULT ePicLoad::startDecode(const char *file, int x, int y)
838 return startThread(1, file, x, y);
841 RESULT ePicLoad::getThumbnail(const char *file, int x, int y)
843 return startThread(0, file, x, y);
846 RESULT ePicLoad::setPara(PyObject *val)
848 if (!PyList_Check(val))
850 if (PyList_Size(val) < 6)
853 m_conf.max_x = PyInt_AsLong( PyList_GET_ITEM(val, 0));
854 m_conf.max_y = PyInt_AsLong( PyList_GET_ITEM(val, 1));
855 m_conf.aspect_ratio = PyFloat_AsDouble( PyList_GET_ITEM(val, 2));
856 m_conf.usecache = PyInt_AsLong( PyList_GET_ITEM(val, 3));
857 m_conf.resizetype = PyInt_AsLong( PyList_GET_ITEM(val, 4));
858 const char *bg_str = PyString_AsString( PyList_GET_ITEM(val, 5));
860 if(bg_str[0] == '#' && strlen(bg_str)==9)
862 int bg = strtoul(bg_str+1, NULL, 16);
863 m_conf.background[0] = bg&0xFF; //BB
864 m_conf.background[1] = (bg>>8)&0xFF; //GG
865 m_conf.background[2] = (bg>>16)&0xFF; //RR
866 m_conf.background[3] = bg>>24; //AA
869 eDebug("[Picload] setPara max-X=%d max-Y=%d aspect_ratio=%lf cache=%d resize=%d bg=#%02X%02X%02X%02X", m_conf.max_x, m_conf.max_y, m_conf.aspect_ratio, (int)m_conf.usecache, (int)m_conf.resizetype, m_conf.background[3], m_conf.background[2], m_conf.background[1], m_conf.background[0]);
873 PyObject *ePicLoad::getInfo(const char *filename)
877 Cexif *exif = new Cexif;
878 if(exif->DecodeExif(filename))
880 if(exif->m_exifinfo->IsExif)
884 list = PyList_New(23);
885 PyList_SET_ITEM(list, pos++, PyString_FromString(filename));
886 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->Version));
887 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->CameraMake));
888 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->CameraModel));
889 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->DateTime));
890 PyList_SET_ITEM(list, pos++, PyString_FromFormat("%d x %d", exif->m_exifinfo->Width, exif->m_exifinfo->Height));
891 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->FlashUsed));
892 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->Orientation));
893 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->Comments));
894 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->MeteringMode));
895 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->ExposureProgram));
896 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->LightSource));
897 PyList_SET_ITEM(list, pos++, PyString_FromFormat("%d", exif->m_exifinfo->CompressionLevel));
898 PyList_SET_ITEM(list, pos++, PyString_FromFormat("%d", exif->m_exifinfo->ISOequivalent));
899 sprintf(tmp, "%.2f", exif->m_exifinfo->Xresolution);
900 PyList_SET_ITEM(list, pos++, PyString_FromString(tmp));
901 sprintf(tmp, "%.2f", exif->m_exifinfo->Yresolution);
902 PyList_SET_ITEM(list, pos++, PyString_FromString(tmp));
903 PyList_SET_ITEM(list, pos++, PyString_FromString(exif->m_exifinfo->ResolutionUnit));
904 sprintf(tmp, "%.2f", exif->m_exifinfo->Brightness);
905 PyList_SET_ITEM(list, pos++, PyString_FromString(tmp));
906 sprintf(tmp, "%.5f sec.", exif->m_exifinfo->ExposureTime);
907 PyList_SET_ITEM(list, pos++, PyString_FromString(tmp));
908 sprintf(tmp, "%.5f", exif->m_exifinfo->ExposureBias);
909 PyList_SET_ITEM(list, pos++, PyString_FromString(tmp));
910 sprintf(tmp, "%.5f", exif->m_exifinfo->Distance);
911 PyList_SET_ITEM(list, pos++, PyString_FromString(tmp));
912 sprintf(tmp, "%.5f", exif->m_exifinfo->CCDWidth);
913 PyList_SET_ITEM(list, pos++, PyString_FromString(tmp));
914 sprintf(tmp, "%.2f", exif->m_exifinfo->ApertureFNumber);
915 PyList_SET_ITEM(list, pos++, PyString_FromString(tmp));
919 list = PyList_New(2);
920 PyList_SET_ITEM(list, 0, PyString_FromString(filename));
921 PyList_SET_ITEM(list, 1, PyString_FromString(exif->m_szLastError));
927 list = PyList_New(2);
928 PyList_SET_ITEM(list, 0, PyString_FromString(filename));
929 PyList_SET_ITEM(list, 1, PyString_FromString(exif->m_szLastError));
933 return list ? (PyObject*)list : (PyObject*)PyList_New(0);
936 int ePicLoad::getData(ePtr<gPixmap> &result)
938 if(m_filepara->pic_buffer == NULL) return 0;
940 m_filepara->pic_buffer = conv24to32(m_filepara->pic_buffer, m_filepara->ox * m_filepara->oy);
942 result=new gPixmap(eSize(m_filepara->max_x, m_filepara->max_y), 32);
943 gSurface *surface = result->surface;
946 int o_y=0, u_y=0, v_x=0, h_x=0;
948 unsigned char *tmp_buffer=((unsigned char *)(surface->data));
950 if(m_filepara->oy < m_filepara->max_y)
952 o_y = (m_filepara->max_y - m_filepara->oy) / 2;
953 u_y = m_filepara->max_y - m_filepara->oy - o_y;
955 if(m_filepara->ox < m_filepara->max_x)
957 v_x = (m_filepara->max_x - m_filepara->ox) / 2;
958 h_x = m_filepara->max_x - m_filepara->ox - v_x;
961 if(m_filepara->oy < m_filepara->max_y)
963 for(a=0; a<(o_y*m_filepara->ox); a++, nc+=4)
965 tmp_buffer=((unsigned char *)(surface->data)) + nc;
966 memcpy(tmp_buffer, m_conf.background, sizeof(m_conf.background));
970 for(a=0; a<m_filepara->oy; a++)
972 if(m_filepara->ox < m_filepara->max_x)
974 for(b=0; b<v_x; b++, nc+=4)
976 tmp_buffer=((unsigned char *)(surface->data)) + nc;
977 memcpy(tmp_buffer, m_conf.background, sizeof(m_conf.background));
981 for(b=0; b<(m_filepara->ox*4); b+=4, nc+=4)
983 tmp_buffer=((unsigned char *)(surface->data)) + nc;
984 tmp_buffer[2] = m_filepara->pic_buffer[oc++];
985 tmp_buffer[1] = m_filepara->pic_buffer[oc++];
986 tmp_buffer[0] = m_filepara->pic_buffer[oc++];
987 tmp_buffer[3] = m_filepara->pic_buffer[oc++];
990 if(m_filepara->ox < m_filepara->max_x)
992 for(b=0; b<h_x; b++, nc+=4)
994 tmp_buffer=((unsigned char *)(surface->data)) + nc;
995 memcpy(tmp_buffer, m_conf.background, sizeof(m_conf.background));
1000 if(m_filepara->oy < m_filepara->max_y)
1002 for(a=0; a<(u_y*m_filepara->ox); a++, nc+=4)
1004 tmp_buffer=((unsigned char *)(surface->data)) + nc;
1005 memcpy(tmp_buffer, m_conf.background, sizeof(m_conf.background));
1009 surface->clut.data=0;
1010 surface->clut.colors=0;
1011 surface->clut.start=0;