Exemplo n.º 1
0
EXPORT BOOL WINAPI mhsp_SWFBitmap_buf(HSPEXINFO *hei, int p2, int p3, int p4)
{
	unsigned char *buf, *buf2;
	int size, size2;
	SWFInput input;
	SWFBitmap *p1;
	lstrcpy(funcname, "SWFBitmap_buf");
	p1 = (SWFBitmap *)hei->HspFunc_prm_getv();
	buf = (unsigned char *)hei->HspFunc_prm_getv();
	size = hei->HspFunc_prm_geti();
	buf2 = (unsigned char *)hei->HspFunc_prm_getv();
	size2 = hei->HspFunc_prm_getdi(0);
	input = newSWFInput_allocedBuffer(buf, size);
	if (size2 && isJPEG(input)) {
		SWFInput_seek(input, 0, SEEK_SET);
		*p1 = (SWFBitmap)newSWFJpegWithAlpha_fromInput(input,
			 newSWFInput_allocedBuffer(buf2, size2));
	}
#ifdef JAMING
	else if (isDBL(input) || isJPEG(input))
#else
	else if (isDBL(input) || isJPEG(input) || isGIF(input) || isPNG(input) || isBMP(input))
#endif
	{
		SWFInput_seek(input, 0, SEEK_SET);
		*p1 = newSWFBitmap_fromInput(newSWFInput_allocedBuffer(buf, size));
	}
	else {
		return -1;
	}
	if (!mhsp_bitmap) {
		mhsp_bitmap = *p1;
	}
	return 0;
}
Exemplo n.º 2
0
int main(void)
{
    FILE* file = fopen("./card.raw", "r");
    FILE* temp;
    
    if (file == NULL)
    {
        printf("Could not open card.raw\n");
        return 1;
    }
    
    BYTE* buffer = malloc(BLOCKSIZE);
    
    if (buffer == NULL)
    {
        printf("Error allocating memory\n");
        return 2;
    }
    
    char* filename = malloc(sizeof(char) * 8);
    int counter = 0;
    
    bool fileOpened = false;
    
    while(fread(buffer, sizeof(buffer), 1, file) == 1)
    {   
        if(isJPEG(buffer))
        {
            sprintf(filename, "%03d.jpg", counter);
            counter++;
            
            if(fileOpened)
            {
                fclose(temp);
                temp = fopen(filename, "w");
                fwrite(buffer, sizeof(buffer), 1, temp);
            }
            else
            {
                temp = fopen(filename, "w");
                fwrite(buffer, sizeof(buffer), 1, temp);
                fileOpened = true;
            }             
        }     
        else if (fileOpened)
        {
            fwrite(buffer, sizeof(buffer), 1, temp);
        }
    }
    
    if(temp)
    {
        fclose(temp);
    }
    fclose(file);
    free(filename);
    free(buffer);
    
    return 0;
}
Exemplo n.º 3
0
bool Image::loadFromBuffer(uint8_t* buf, size_t len)
{
	clearData();
	size_t pixelsByteLen = 0;

	if (isPNG(buf))
	{
		pixels = pixels_from_png(buf, len, pixelsByteLen, width, height);
		__BGRA = true;
	}

	else if (isJPEG(buf))
	{
		pixels = pixels_from_jpeg(buf, len, pixelsByteLen, width, height);
		__BGRA = false;
	}

	if (pixels && pixelsByteLen)
	{
		_surface = cairo_image_surface_create_for_data(pixels, CAIRO_FORMAT_ARGB32, width, height, 4 * width);
		cairo_surface_flush(_surface);
	}

	cairo_status_t status = cairo_surface_status(_surface);
	if (status == CAIRO_STATUS_SUCCESS)
	{
		naturalWidth = width = cairo_image_surface_get_width(_surface);
		naturalHeight = height = cairo_image_surface_get_height(_surface);
	}

	return (status == CAIRO_STATUS_SUCCESS);
}
Exemplo n.º 4
0
EXPORT BOOL WINAPI mhsp_SWFBitmap(HSPEXINFO *hei, int p2, int p3, int p4)
{
	FILE *fp1, *fp2;
	char filename[MHSP_STRMAX], alpha[MHSP_STRMAX];
	SWFInput input;
	SWFBitmap *p1;
	lstrcpy(funcname, "SWFBitmap");
	p1 = (SWFBitmap *)hei->HspFunc_prm_getv();
	lstrcpyn(filename, hei->HspFunc_prm_gets(), MHSP_STRMAX);
	lstrcpyn(alpha, hei->HspFunc_prm_getds(""), MHSP_STRMAX);
	fp1 = fopen(filename, "rb");
	if (!fp1) {
		return 1;
	}
	input = newSWFInput_file(fp1);
	fp2 = fopen(alpha, "rb");
	if (fp2 && isJPEG(input)) {
		SWFInput_seek(input, 0, SEEK_SET);
		*p1 = (SWFBitmap)newSWFJpegWithAlpha_fromInput(input, newSWFInput_file(fp2));
	}
#ifdef JAMING
	else if (isDBL(input) || isJPEG(input))
#else
	else if (isDBL(input) || isJPEG(input) || isGIF(input) || isPNG(input) || isBMP(input))
#endif
	{
		SWFInput_seek(input, 0, SEEK_SET);
		*p1 = newSWFBitmap_fromInput(input);
	}
	else {
		return -1;	/* 非対応フォーマット */
	}
	if (!mhsp_bitmap) {
		mhsp_bitmap = *p1;
	}
	return 0;
}
Exemplo n.º 5
0
ImageType getImageType(const std::string& FileName)
{
  FILE *file_image = fopen(FileName.c_str(), "rb");
  if (!file_image)
  {
    //file could not be opened for reading
    return itUnknown;
  }

  unsigned char header[8];
  memset(header, 0, 8);
  //read first eight bytes
  if (fread(header, 1, 8, file_image)!=8)
  {
    //file is not long enough to be a proper image file
    fclose(file_image);
    return itUnknown;
  }
  fclose(file_image);

  if (isJPEG(header, 8))
  {
    return itJPEG;
  }
  if (isPNG(header, 8))
  {
    return itPNG;
  }
  if (isGIF(header, 8))
  {
    return itGIF;
  }
  if (isPPM(header, 8))
  {
    return itPPM;
  }
  if (isBMP(header, 8))
  {
    return itBitmap;
  }
  return itUnknown;
}
Exemplo n.º 6
0
bool Image::loadSupportedFormat(const char* path_)
{
  const char *verifiedPath = MediaPathManager::lookUpMediaPath(path_);
  
  if (!verifiedPath)
    return false;
    
  path = verifiedPath;
  
  if (isPNG(verifiedPath))
    return loadPNG(verifiedPath, this);
    
  if (isJPEG(verifiedPath))
    return loadJPG(verifiedPath);
    
  if (isTGA(verifiedPath))
    return loadTGA(verifiedPath);
    
  if (isDDS(verifiedPath))
    return loadDDS(verifiedPath);
    
  return false;
}