#include "ninox.h" #include #include static unsigned int _SubSample8(unsigned char *ptr, int img_wid, int bpp, int x_size, int y_size); static unsigned int _SubSample16(unsigned char *ptr, int img_wid, int bpp, int x_size, int y_size); /* * Generate and return an array of subsampled images, count is how many images to make, * and is also the number of elements of xsizes[] and ysizes[] which give the sizes * of the subsampled images. * * rdepth is the requested depth, the list must contain sub-images of this depth * * Region(r) defines the area in the original image to use. If NULL then the cutout region in * the source image is used */ struct Image ** GenerateSubSampledImages(struct Image *img, struct Region *r, int *xsizes, int *ysizes, int rdepth, int count) { struct Image **list; unsigned char *buffer = img->data; int width = img->width; int height = img->height; int depth = img->depth; int w,h,x,y,x1,y1,x2,y2; int subsample_x,subsample_y; int i,bpp,n,x_inc; int x_last,y_last; int pixels_per_row; unsigned char *buf; unsigned short *ubuf; char fname[1024]; if (depth != 16 && depth != 8 && depth != 24) { Print("GenerateSubSampledImages: Depth must be 8,16 or 24, not %d\n",depth); return NULL; } if (count>32) { Print("GenerateSubSampledImages: maximum of 32 images allowed\n"); return NULL; } list = (struct Image **)malloc(sizeof(struct Image **) * count); if (r != NULL) { x1=r->x1; y1=r->y1; x2=r->x2; y2=r->y2; } else { x1 = img->cutout.x1; x2 = img->cutout.x2; y1 = img->cutout.y1; y2 = img->cutout.y2; } Clip(width,height,&x1,&y1,&x2,&y2); pixels_per_row = x2-x1+1; bpp = depth/8; //WriteImage(img); for(i=0; isrc_fname,i); list[i] = CreateFitsImage(fname, w, h, rdepth, buf, -1, -1.0); //ShowImage(list[i]); //Usleep(5000*1000); if (! list[i]) { Print("GenerateSubSampledImages: error generating file %s\n",fname); exit(1); } } return list; } /* * Subsample a region starting at *ptr of size X size pixels. * Always return a 16bpp result */ static unsigned int _SubSample16(unsigned char *ptr, int img_wid, int bpp, int x_size, int y_size) { int x,y,val=0; unsigned short v,*uptr; double d; switch(bpp) { case 1: for(y=0; y>8; uptr += img_wid; } break; case 3: // 24bpp data, 8 bit BGR, convert to monochrome for(y=0; ydst_fname = strdup("reference.fit"); WriteImage(img); z = fopen("offsets.txt","w"); num = (int *)ZeroMalloc(Subsample_nframes * sizeof(int)); for(i=0; iwidth-1; r.y2 = img->height-1; // Calculate the size of the subsampled image output_width = img->width / Subsample_pixel_width; output_height = img->height / Subsample_pixel_height; Print("Generating image %d: %s (%d,%d) with offsets (%d,%d)\n", i,fname, output_width, output_height, offset_x,offset_y); // Generate 1 subsampled image sub = GenerateSubSampledImages(img, &r, &output_width, &output_height, 16, 1); sub[0]->dst_fname = strdup(fname); if (Subsample_noise > 0) { // Add small amount of noise to image uptr = (unsigned short *)(sub[0]->data); for(j=0; j65535) v=65535; *(uptr++) = v; } } if (Subsample_upscale>1) { upscale_image(sub[0],Subsample_upscale); } if (Subsample_smooth > 1) { smooth_image(sub[0],Subsample_smooth); } sub[0] = ConvertToType(sub[0],IMG_BMP,8); WriteImage(sub[0]); stack_frame(sub[0]); DestroyImage(sub[0]); fprintf(z,"%s: (%d,%d)\n",fname,offset_x, offset_y); fflush(z); } fclose(z); write_stack_file("stack.fit"); return 1; }