#include <string.h>
-#ifndef _MSC_VER
-#include <alloca.h>
-#else
+#if defined(WIN32) || defined(__WIN32__)
#include <malloc.h>
+#else
+#include <alloca.h>
#endif
#include "imago2.h"
+#include "assman.h"
#include "image.h"
static int pixel_elements(Image::Format fmt);
flip_horizontal();
}
+void Image::resize_half()
+{
+ int pixsz = pixel_size(fmt);
+ int newxsz = width / 2;
+ int newysz = height / 2;
+
+ if(!newxsz || !newysz) return;
+
+ unsigned char *newpix = new unsigned char[newxsz * newysz * pixsz];
+
+ unsigned char *sptr = (unsigned char*)pixels;
+ unsigned char *dptr = newpix;
+
+ for(int i=0; i<newysz; i++) {
+ if(i & 1) sptr += width * pixsz;
+ for(int j=0; j<newxsz; j++) {
+ memcpy(dptr, sptr, pixsz);
+ dptr += pixsz;
+ sptr += pixsz * 2;
+ }
+ }
+
+ delete [] (char*)pixels;
+ pixels = newpix;
+ width = newxsz;
+ height = newysz;
+}
+
+static size_t io_read(void *buf, size_t bytes, void *fp)
+{
+ return ass_fread(buf, 1, bytes, fp);
+}
+
+static long io_seek(long offs, int whence, void *fp)
+{
+ ass_fseek(fp, offs, whence);
+ return ass_ftell(fp);
+}
+
bool Image::load(const char *fname)
{
struct img_pixmap pixmap;
+ struct img_io io = {0, io_read, 0, io_seek};
+ ass_file *fp;
+
+ if(!(fp = ass_fopen(fname, "rb"))) {
+ return false;
+ }
+ io.uptr = fp;
img_init(&pixmap);
- if(img_load(&pixmap, fname) == -1) {
+ if(img_read(&pixmap, &io) == -1) {
return false;
}